Module: Fiveruns::Tuneup::AssetTags
- Included in:
- Fiveruns::Tuneup
- Defined in:
- lib/fiveruns/tuneup/asset_tags.rb
Instance Method Summary collapse
- #add_asset_tags_to(response) ⇒ Object
-
#add_content_length(response, delta) ⇒ Object
Modify the Content-Length header, regardless if String/Fixnum, and keep it the same type.
- #insert_prototype ⇒ Object
- #show_for?(response) ⇒ Boolean
Instance Method Details
#add_asset_tags_to(response) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 6 def (response) return unless show_for?(response) before, after = response.body.split(/<\/head>/i, 2) if after insertion = %( <!-- START FIVERUNS TUNEUP ASSETS --> <link rel="stylesheet" type="text/css" href="/stylesheets/tuneup/tuneup.css" /> <script type="text/javascript"> var TuneUp = {}; </script> <script type="text/javascript" src="/javascripts/tuneup/init.js"></script> <!-- END FIVERUNS TUNEUP ASSETS --> ) add_content_length(response, insertion.size) body = [before, insertion, '</head>', after].join('').html_safe! response.body.replace(body) log :error, "Inserted asset tags" else log :error, "Could not find closing </head> tag for insertion" end end |
#add_content_length(response, delta) ⇒ Object
Modify the Content-Length header, regardless if String/Fixnum, and keep it the same type
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 39 def add_content_length(response, delta) length = response.headers["Content-Length"] response.headers["Content-Length"] = case length when Fixnum length + delta when String (length.to_i + delta).to_s else length # Shouldn't happen end end |
#insert_prototype ⇒ Object
33 34 35 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 33 def insert_prototype "<script type='text/javascript' src='/javascripts/tuneup/prototype.js'></script>" end |
#show_for?(response) ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 26 def show_for?(response) return false unless response.body return true if response.headers['ETag'] && response.headers['Content-Type'].to_s.include?('html') return false unless response.headers['Status'] && response.headers['Status'].include?('200') true end |