Class Sass::Plugin::Rack
In: lib/sass/plugin/rack.rb
Parent: Object

Rack middleware for compiling Sass code.

## Activate

    require 'sass/plugin/rack'
    use Sass::Plugin::Rack

## Customize

    Sass::Plugin.options.merge(
      :cache_location => './tmp/sass-cache',
      :never_update => environment != :production,
      :full_exception => environment != :production)

{file:SASS_REFERENCE.md#options See the Reference for more options}.

## Use

Put your Sass files in `public/stylesheets/sass`. Your CSS will be generated in `public/stylesheets`, and regenerated every request if necessary. The locations and frequency {file:SASS_REFERENCE.md#options can be customized}. That‘s all there is to it!

Methods

Public Class methods

Disable the native Rails or Merb plugins, if they‘re enabled. This is automatically done once the Rack plugin is activated. This is done so that the stylesheets aren‘t checked twice for each request.

[Source]

    # File lib/sass/plugin/rack.rb, line 50
50:       def self.disable_native_plugin!
51:         if defined?(Merb::Rack) && defined?(Merb::Rack::Application) &&
52:             Haml::Util.has?(:instance_method, Merb::Rack::Application, :call_without_sass)
53:           Merb::Rack::Application.instance_eval {alias_method :call, :call_without_sass}
54:         end
55: 
56:         if defined?(ActionDispatch::Callbacks) && defined?(ActionDispatch::Callbacks.to_prepare)
57:           ActionDispatch::Callbacks.skip_callback(:prepare, :__sass_process)
58:         elsif defined?(ActionController::Base) &&
59:             Haml::Util.has?(:instance_method, ActionController::Base, :sass_old_process)
60:           ActionController::Base.instance_eval {alias_method :process, :sass_old_process}
61:         end
62:       end

Initialize the middleware.

@param app [call] The Rack application

[Source]

    # File lib/sass/plugin/rack.rb, line 32
32:       def initialize(app)
33:         @app = app
34:         self.class.disable_native_plugin!
35:       end

Public Instance methods

Process a request, checking the Sass stylesheets for changes and updating them if necessary.

@param env The Rack request environment @return [(to_i, {String => String}, Object)] The Rack response

[Source]

    # File lib/sass/plugin/rack.rb, line 42
42:       def call(env)
43:         Sass::Plugin.check_for_updates
44:         @app.call(env)
45:       end

[Validate]