Created
February 5, 2010 06:04
-
-
Save archfear/295556 to your computer and use it in GitHub Desktop.
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
# Dan Croak, February 2008 | |
# updated by Dan Dofter, February 2010 | |
VIEWS_DIR = "#{RAILS_ROOT}/app/views" | |
CSS_DIR = "#{RAILS_ROOT}/public/stylesheets" | |
SASS_DIR = "#{VIEWS_DIR}/stylesheets" | |
def convert_css_to_sass(css_file) | |
if css_file =~ /^(.*)(\.css)$/ | |
basename = $1 | |
system "css2sass #{CSS_DIR}/#{css_file} > #{SASS_DIR}/#{basename}.sass" | |
end | |
end | |
def convert_sass_to_css(sass_file) | |
if sass_file =~ /^(.*)(\.sass)$/ | |
basename = $1 | |
options = "" | |
options += "-t #{Sass::Plugin.options[:style]}" if Sass::Plugin.options[:style] | |
options += " -l" if Sass::Plugin.options[:line_comments] | |
system "sass #{options} #{SASS_DIR}/#{sass_file} > #{CSS_DIR}/#{basename}.css" | |
end | |
end | |
def convert_html_to_haml(erb_file, options = {}) | |
if erb_file =~ /^(.*)(\.html\.erb|\.rhtml)$/ | |
basename = $1 | |
system "html2haml #{VIEWS_DIR}/#{erb_file} > #{VIEWS_DIR}/#{basename}.html.haml" | |
system "rm #{VIEWS_DIR}/#{erb_file}" unless options[:keep_original] | |
end | |
end | |
namespace :sass do | |
# Usage: | |
# rake sass:css2sass | |
# rake sass:css2sass[mystyles.css] | |
desc "Convert CSS files to Sass." | |
task :css2sass, :css_file, :needs => [:environment] do |t, args| | |
FileUtils.mkdir_p SASS_DIR | |
files = if args.css_file | |
[ args.css_file.strip ] | |
else | |
Dir.chdir(CSS_DIR) | |
Dir.glob("**/*.css") | |
end | |
files.each do |filename| | |
convert_css_to_sass filename | |
end | |
FileUtils.rm_rf('.sass-cache') | |
end | |
# Usage: | |
# rake sass:sass2css | |
# rake sass:sass2css[mystyles.sass] | |
desc "Convert Sass files to CSS." | |
task :sass2css, :sass_file, :needs => [:environment] do |t, args| | |
FileUtils.mkdir_p CSS_DIR | |
files = if args.sass_file | |
[ args.sass_file.strip ] | |
else | |
Dir.chdir(SASS_DIR) | |
Dir.glob("**/*.sass") | |
end | |
files.each do |filename| | |
convert_sass_to_css filename | |
end | |
FileUtils.rm_rf('.sass-cache') | |
end | |
end | |
namespace :haml do | |
# Usage: | |
# rake haml:html2haml | |
# rake haml:html2haml[layouts/application.html.erb] | |
# rake "haml:html2haml[layouts/application.html.erb, true]" | |
desc "Convert HTML files to Haml." | |
task :html2haml, :html_file, :keep_original, :needs => [:environment] do |t, args| | |
keep_original = (args.keep_original == "true") | |
files = if args.html_file | |
[ args.html_file.strip ] | |
else | |
Dir.chdir(VIEWS_DIR) | |
Dir.glob("**/*.html.erb") + Dir.glob("**/*.rhtml") | |
end | |
files.each do |filename| | |
convert_html_to_haml filename, :keep_original => keep_original | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment