Commits

Shrikant Sharat Kandula committed 0f43432

Now saving modifed html file.

Comments (0)

Files changed (2)

 def:
 	ruby main.rb
-	cat all-scripts.js
 
 scripts = doc.css 'script'
 
-File.open 'all-scripts.js', 'w' do |outfile|
-  scripts.each do |script|
+combined_filename = 'all-scripts.js'
+
+File.open combined_filename, 'w' do |outfile|
+  scripts.each_with_index do |script, i|
     filename = script[:src]
     File.open filename do |f|
       outfile.write f.reduce { |acc, line| acc + line }
     end
+    if i.zero?
+      script[:src] = combined_filename
+    else
+      script.remove unless i == 0
+    end
   end
 end
 
+File.open 'index-out.html', 'w' do |outfile|
+  outfile.write doc
+end
+
 puts 'Done'