
Untitled
By: a guest on
Jul 1st, 2012 | syntax:
None | size: 0.75 KB | hits: 14 | expires: Never
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
file = Nokogiri::HTML::Document.parse(open('./docs/templates/pages/upgrading.mustache'));
#file = Nokogiri::HTML::Document.parse(open('./docs/templates/pages/scaffolding.mustache'));
def wrap_text(text)
"{{_i}}"+text+"{{/i}}"
end
file.css("h1,h2,h3,p,a").each do |e|
e.children = wrap_text(e.children.to_s)
end
file.css("li").each do |li|
li.children.each do |c|
if c.name.eql?("ul")
c.children.each do |c2|
if c2.name.eql?("li")
c2.children = wrap_text(c2.children.to_s)
end
end
else
if c.type == 3 && !c.text.include?('{{/i}}') && !c.text.include?('{{_i}}')
c.content = wrap_text(c.content)
end
end
end
end
f = File.open("./newfile.html", "w")
f.write(file)