Sha256: 3cc980979ea1f60e4ecde54cb7598732bc05abaff5254f38f50ece82fac56318

Contents?: true

Size: 1.75 KB

Versions: 705

Compression:

Stored size: 1.75 KB

Contents

module Sass
  module Plugin
    # 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!
    class Rack
      # The delay, in seconds, between update checks.
      # Useful when many resources are requested for a single page.
      # `nil` means no delay at all.
      #
      # @return [Float]
      attr_accessor :dwell

      # Initialize the middleware.
      #
      # @param app [#call] The Rack application
      # @param dwell [Float] See \{#dwell}
      def initialize(app, dwell = 1.0)
        @app = app
        @dwell = dwell
        @check_after = Time.now.to_f
      end

      # 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
      def call(env)
        if @dwell.nil? || Time.now.to_f > @check_after
          Sass::Plugin.check_for_updates
          @check_after = Time.now.to_f + @dwell if @dwell
        end
        @app.call(env)
      end
    end
  end
end

require 'sass/plugin'

Version data entries

705 entries across 415 versions & 20 rubygems

Version Path
oreorenasass-3.4.0 lib/sass/plugin/rack.rb
sass-3.4.0 lib/sass/plugin/rack.rb
sass-3.4.0.rc.3 lib/sass/plugin/rack.rb
sass-3.3.14 lib/sass/plugin/rack.rb
sass-3.3.13 lib/sass/plugin/rack.rb
sass-3.3.12 lib/sass/plugin/rack.rb
sass-3.4.0.rc.2 lib/sass/plugin/rack.rb
sass-3.3.11 lib/sass/plugin/rack.rb
sass-3.4.0.rc.1 lib/sass/plugin/rack.rb
sass-3.3.10 lib/sass/plugin/rack.rb
sass-3.3.9 lib/sass/plugin/rack.rb
sass-3.3.8 lib/sass/plugin/rack.rb
sass-3.3.7 lib/sass/plugin/rack.rb
sass-3.3.6 lib/sass/plugin/rack.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/sass-3.2.14/lib/sass/plugin/rack.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/sass-3.2.14/lib/sass/plugin/rack.rb
sass-3.3.5 lib/sass/plugin/rack.rb
sass-3.2.19 lib/sass/plugin/rack.rb
sass-3.2.18 lib/sass/plugin/rack.rb
sass-3.3.4 lib/sass/plugin/rack.rb