Created
April 6, 2013 14:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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