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 |
# 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 = { frontend_url : '#{Fiveruns::Tuneup.frontend_url}'}; </script> <script type="text/javascript" src="/javascripts/tuneup/init.js"></script> <!-- END FIVERUNS TUNEUP ASSETS --> ) add_content_length(response, insertion.size) response.body.replace(before << insertion << '</head>' << after) 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
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 38 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
32 33 34 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 32 def insert_prototype "<script type='text/javascript' src='/javascripts/tuneup/prototype.js'></script>" end |
#show_for?(response) ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/fiveruns/tuneup/asset_tags.rb', line 25 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 |