Skip to content

Instantly share code, notes, and snippets.

@manfe
Created October 28, 2012 18:22
Show Gist options
  • Save manfe/3969360 to your computer and use it in GitHub Desktop.
Save manfe/3969360 to your computer and use it in GitHub Desktop.
Script to convert haml to textile
require 'haml'
require 'html2textile'
files = Dir["*"]
files.each do |f|
unless f == 'script.rb' || f == 'index.html.haml'
system("awk '{ if( NR > 2 ) { print } }' #{f} > #{f[0..-11] + '.temp'}") # remove first 2 lines
end
end
files = Dir["*.temp"]
p files.count
files.each do |f|
puts "#{f} convertendo para haml...."
system("haml #{f} #{f[0..-6]}.html") # convert to html and put extension to .html
system("rm #{f}")
end
files = Dir["*.html"]
p files.count
files.each do |f|
parser = HTMLToTextileParser.new
parser.feed(File.read(f))
file = File.new("#{f[0..-6]}.textile", "w")
file.puts parser.to_textile
file.close
system("rm #{f}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment