Sha256: e98f9c0efb089bf1b0730ec449eeea2ae6a2d6a1cafd2f362508ec2f298b2ccb

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

module Sprockets
  class Bootstrap
    def initialize(app)
      @app = app
    end

    # TODO: Get rid of config.assets.enabled
    def run
      app, config = @app, @app.config
      return unless app.assets

      config.assets.paths.each { |path| app.assets.append_path(path) }

      if config.assets.compress
        # temporarily hardcode default JS compressor to uglify. Soon, it will work
        # the same as SCSS, where a default plugin sets the default.
        unless config.assets.js_compressor == false
          app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) }
        end

        unless config.assets.css_compressor == false
          app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) }
        end
      end

      if config.assets.compile
        app.routes.prepend do
          mount app.assets => config.assets.prefix
        end
      end

      if config.assets.digest
        app.assets = app.assets.index
      end
    end

    protected

    def expand_js_compressor(sym)
      case sym
      when :closure
        require 'closure-compiler'
        Closure::Compiler.new
      when :uglifier
        require 'uglifier'
        Uglifier.new
      when :yui
        require 'yui/compressor'
        YUI::JavaScriptCompressor.new
      else
        sym
      end
    end

    def expand_css_compressor(sym)
      case sym
      when :yui
        require 'yui/compressor'
        YUI::CssCompressor.new
      else
        sym
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
actionpack-3.1.12 lib/sprockets/bootstrap.rb
actionpack-3.1.11 lib/sprockets/bootstrap.rb
actionpack-3.1.10 lib/sprockets/bootstrap.rb
actionpack-3.1.9 lib/sprockets/bootstrap.rb
actionpack-3.1.8 lib/sprockets/bootstrap.rb
actionpack-3.1.7 lib/sprockets/bootstrap.rb
actionpack-3.1.6 lib/sprockets/bootstrap.rb
actionpack-3.1.5 lib/sprockets/bootstrap.rb
actionpack-3.1.5.rc1 lib/sprockets/bootstrap.rb
actionpack-3.1.4 lib/sprockets/bootstrap.rb
actionpack-3.1.4.rc1 lib/sprockets/bootstrap.rb
actionpack-3.1.3 lib/sprockets/bootstrap.rb
actionpack-3.1.2 lib/sprockets/bootstrap.rb
actionpack-3.1.2.rc2 lib/sprockets/bootstrap.rb
actionpack-3.1.2.rc1 lib/sprockets/bootstrap.rb
actionpack-3.1.1 lib/sprockets/bootstrap.rb
actionpack-3.1.1.rc3 lib/sprockets/bootstrap.rb
actionpack-3.1.1.rc2 lib/sprockets/bootstrap.rb