Class: Rack::PixelFire
- Inherits:
-
Object
- Object
- Rack::PixelFire
- Defined in:
- lib/rack/pixel_fire.rb
Defined Under Namespace
Classes: Railtie
Instance Method Summary collapse
- #call(env) ⇒ Object
- #html? ⇒ Boolean
-
#initialize(app) ⇒ PixelFire
constructor
A new instance of PixelFire.
- #inject(env, response) ⇒ Object
- #tags(env) ⇒ Object
Constructor Details
#initialize(app) ⇒ PixelFire
5 6 7 |
# File 'lib/rack/pixel_fire.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rack/pixel_fire.rb', line 9 def call(env) @status, @headers, @body = @app.call(env) return [@status, @headers, @body] unless html? response = ::Rack::Response.new([], @status, @headers) @body.each { |fragment| response.write inject(env, fragment) } @body.close if @body.respond_to?(:close) response.finish end |
#html? ⇒ Boolean
20 21 22 |
# File 'lib/rack/pixel_fire.rb', line 20 def html? @headers['Content-Type'] =~ /html/ end |
#inject(env, response) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/pixel_fire.rb', line 24 def inject(env, response) puts "TAGS: #{(env).inspect}" (env).each do |tag| response.sub! %r{</#{tag.target}>} do |m| tag.custom_html << m.to_s end end response end |