Class: Rack::ExvoWarez::Seo
- Inherits:
-
Object
- Object
- Rack::ExvoWarez::Seo
- Defined in:
- lib/rack/exvo/seo.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each ⇒ Object
-
#initialize(app) ⇒ Seo
constructor
A new instance of Seo.
Constructor Details
#initialize(app) ⇒ Seo
Returns a new instance of Seo.
4 5 6 7 8 |
# File 'lib/rack/exvo/seo.rb', line 4 def initialize(app) @app = app @apps = apps_index @payload = ERB.new(::File.read(::File.("../templates/links.erb", __FILE__))).result(binding) end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/exvo/seo.rb', line 10 def call(env) request = Rack::Request.new(env) status, headers, @body = @app.call(env) if request.xhr? return [status, headers, @body] end if html?(headers) if cl = headers["Content-Length"] headers["Content-Length"] = (cl.to_i + @payload.length).to_s end [status, headers, self] else [status, headers, @body] end [status, headers, (html?(headers) ? self : @body)] end |
#each ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/exvo/seo.rb', line 31 def each if @body.is_a?(String) resp = ActionDispatch::Response.new resp.write(@body) @body = resp end @body.each do |chunk| yield(end_of_body?(chunk) ? with_payload(chunk) : chunk) end end |