Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Created April 6, 2013 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcheiligers/5326376 to your computer and use it in GitHub Desktop.
Save marcheiligers/5326376 to your computer and use it in GitHub Desktop.
Using http://www.youtube.com/watch?v=B1l5F3KEEBw as inspiration after being sick of modifying all the Devise templates by hand.
namespace :views do
desc "Converts all .html.erb files in app/views to .html.haml files"
task :hamlize do
Dir.glob('app/views/**/*.erb').each do |file|
begin
puts "Hamlizing #{file}"
`bundle exec html2haml #{file} | cat > #{file.sub(/(\.html)?\.erb$/, '.html.haml')} && rm #{file}`
rescue => e
puts "Error in #{file}: #{e.message}"
end
end
end
desc "Adds .row .large-12.columns at the top of all .html.haml files in the specified folder under app/views. Specify the folder to start in as FOLDER."
task :zurbify do
if ENV['FOLDER'].blank?
puts "Specify a FOLDER in app/views to start searching for files"
else
Dir.glob("app/views/#{ENV['FOLDER']}/**/*.html.haml").each do |file|
begin
contents = File.read(file)
unless contents.include?('.row') && contents.include?('.columns')
puts "Zurbifying #{file}"
File.open(file, 'w') do |f|
f.puts '.row'
f.puts ' .large-12.columns'
contents.each_line do |line|
f.puts " #{line.sub(/\r?\n$/, '')}"
end
end
end
rescue => e
puts "Error in #{file}: #{e.message}"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment