Skip to content

Instantly share code, notes, and snippets.

@mitio
Forked from seven1m/sass_with_jammit.rb
Created July 21, 2011 17:27
Show Gist options
  • Save mitio/1097699 to your computer and use it in GitHub Desktop.
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)
# 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