-
-
Save mitio/1097699 to your computer and use it in GitHub Desktop.
SASS support for Jammit in development mode (also with proper plugins support, for e.g. Compass)
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
# hack to auto compile sass when Jammit runs in development mode | |
# you can place this in an initializer | |
unless Rails.env.production? | |
require 'sass/engine' | |
module Jammit | |
module Helper | |
SASS_TIMESTAMPS = {} | |
def include_stylesheets_with_sass(*packages) | |
unless Rails.env.production? | |
paths = Dir[Rails.root.join('app/stylesheets/*.scss')].select do |path| | |
next if path =~ %r{/_[^/]+$} # skip partials | |
t = File.mtime(path) | |
if SASS_TIMESTAMPS[path] == t | |
false | |
else | |
SASS_TIMESTAMPS[path] = t | |
end | |
end | |
paths.each do |path| | |
Rails.logger.info("Compiling #{path} with SASS.") | |
engine = Sass::Engine.new( | |
File.read(path), | |
:load_paths => Sass::Plugin.engine_options[:load_paths], | |
:cache => false, | |
:syntax => :scss | |
) | |
css_file_path = Rails.root.join('public', 'stylesheets', File.basename(path).sub(/scss$/, 'css')) | |
File.open(css_file_path, 'w') { |f| f.write(engine.render) } | |
end | |
end | |
include_stylesheets_without_sass(*packages) | |
end | |
alias_method_chain :include_stylesheets, :sass | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment