How to use SASS, HAML, and CoffeeScript in Rails 3.2.x Engine?

此生再无相见时 提交于 2019-12-24 09:57:33

问题


Currently, I have a Rails 3.2.9 Engine which is using sass-rails. When I generate a controller with a couple actions, the assets are also generated (i.e., javascript and CSS). However, both the Javascript and SASS are *.js and *.css files. They're not CoffeeScript (*.js.coffee) or SASS (*.css.sass). Any ideas how to get this work?


回答1:


Here's a different solution which will use the coffee-rails and sass-rails gems by default - also fixes haml-rails.

I added this to the top of my engine.rb file:

require 'rails'
require 'coffee-rails'
require 'sass/rails'
require 'haml-rails'

What I did was inspect the source code of these files to see how they work in a normal Rails application. For example, in haml-rails I looked at lib/haml-rails.rb and saw the following:

require 'haml'
require 'rails'

module Haml
  module Rails
    class Railtie < ::Rails::Railtie
      if ::Rails.version.to_f >= 3.1
        config.app_generators.template_engine :haml
      else
        config.generators.template_engine :haml
      end
    ...

Similar files exist for sass-rails (lib/sass/rails/railtie.rb) and coffee-rails (lib/coffee/rails/engine.rb).




回答2:


Just append --stylesheet_engine=sass --javascript_engine=coffee to your generator command (I'm assuming rails g controller).



来源:https://stackoverflow.com/questions/13905389/how-to-use-sass-haml-and-coffeescript-in-rails-3-2-x-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!