Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Created February 15, 2011 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephencelis/827572 to your computer and use it in GitHub Desktop.
Save stephencelis/827572 to your computer and use it in GitHub Desktop.
Rails 3.1 Assets
# lib/action_view/template/handlers/coffee_script.rb
class ActionView::Template::Handlers::CoffeeScript
def call template
"CoffeeScript.compile #{template.source.inspect}"
end
end
gem 'coffee-script'
gem 'compass',
:git => 'git://github.com/chriseppstein/compass.git',
:branch => 'master'
gem 'rails_assets',
:git => 'git://github.com/wycats/rails_assets.git'
# lib/action_view/template/handlers/sass.rb
class ActionView::Template::Handlers::Sass
def initialize options = {}
@options = options
end
def call template
<<CODE
compiler = Compass::Compiler.new *Compass.configuration.to_compiler_arguments
options = compiler.options.merge(#{@options.inspect})
Rails.logger.info "#{template.inspect}"
Sass::Engine.new(#{template.source.inspect}, options).render
CODE
end
end
# config/initializers/template_handlers.rb
# Coffee.
require 'action_view/template/handlers/coffee_script'
ActionView::Template.register_template_handler :coffee,
ActionView::Template::Handlers::CoffeeScript.new
# Sass.
require 'action_view/template/handlers/sass'
ActionView::Template.register_template_handler :sass,
ActionView::Template::Handlers::Sass.new
ActionView::Template.register_template_handler :scss,
ActionView::Template::Handlers::Sass.new(:syntax => :scss)
stylesheets_directory = Rails.root.join('app', 'assets', 'stylesheets').to_s
Compass::Frameworks.register 'rails_assets',
:stylesheets_directory => stylesheets_directory,
:templates_directory => stylesheets_directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment