Class: Rack::GoogleCustomSearch
- Inherits:
-
Struct
- Object
- Struct
- Rack::GoogleCustomSearch
- Defined in:
- lib/rack/google-custom-search.rb
Constant Summary collapse
- DEFAULTS_OPTIONS =
{:css_id => 'cse', :auto_complete => false}
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
3 4 5 |
# File 'lib/rack/google-custom-search.rb', line 3 def app @app end |
#options ⇒ Object
Returns the value of attribute options
3 4 5 |
# File 'lib/rack/google-custom-search.rb', line 3 def @options end |
Instance Method Details
#call(env) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rack/google-custom-search.rb', line 5 def call(env) status, headers, response = app.call(env) if headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/ body = "" response.each { |part| body << part } index = body.rindex("</body>") if index body.insert(index, js_files(DEFAULTS_OPTIONS.merge())) headers["Content-Length"] = body.length.to_s response = [body] end end [status, headers, response] end |