Commits

Shrikant Sharat Kandula committed d7048ca

Moved html processing to a function.

Comments (0)

Files changed (1)

 
 require 'nokogiri'
 
-File.open 'index.html' do |f|
-  @doc = Nokogiri::HTML f
-end
-
-def combine_and_save(combined_filename, selector, attribute)
+def combine_and_save(doc, combined_filename, selector, attribute)
   File.open combined_filename, 'w' do |outfile|
-    @doc.css(selector).each_with_index do |asset, i|
+    doc.css(selector).each_with_index do |asset, i|
 
       filename = asset[attribute]
 
   end
 end
 
-combined_js = 'all-scripts.js'
-combined_css = 'all-styles.css'
+# Takes the source and target html filenames.
+def process_html(html_source, html_target)
+  f = File.open html_source
+  doc = Nokogiri::HTML f
+  f.close
 
-combine_and_save combined_js, 'script', :src
-combine_and_save combined_css, 'link[rel=stylesheet]', :href
+  combined_js = 'all-scripts.js'
+  combined_css = 'all-styles.css'
 
-File.open 'index-out.html', 'w' do |outfile|
-  outfile.write @doc
+  combine_and_save doc, combined_js, 'script', :src
+  combine_and_save doc, combined_css, 'link[rel=stylesheet]', :href
+
+  File.open html_target, 'w' do |outfile|
+    outfile.write doc
+  end
 end
 
+process_html 'index.html', 'index-out.html'
 puts 'Fin'