Sha256: b62ea8ffda9f076855b207f9586a7611b8e5565230d69ebbccfb254da0838313

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 KB

Contents

require 'sprockets'
require 'sass'
require 'coffee_script'
require 'compass'
require 'uglifier'
require 'autoprefixer-rails'

require 'execjs'

module Locomotive::Steam

  class SprocketsEnvironment < ::Sprockets::Environment

    attr_reader :steam_path

    def initialize(root, options = {})
      super(root)

      @steam_path = root

      append_steam_paths

      install_minifiers if options[:minify]

      install_autoprefixer

      context_class.class_eval do
        def asset_path(path, options = {})
          path
        end
      end
    end

    private

    def append_steam_paths
      %w(fonts stylesheets javascripts).each do |name|
        append_path File.join(@steam_path, name)
      end

      Compass::Frameworks::ALL.each { |f| append_path(f.stylesheets_directory) }
    end

    def install_minifiers
      # minify javascripts and stylesheets
      self.js_compressor  = :uglify
      self.css_compressor = :scss
    end

    def install_autoprefixer
      file = File.join(root, '..', 'config', 'autoprefixer.yml')

      if File.exists?(file)
        params = (::YAML.load_file(file) || {}).symbolize_keys
        AutoprefixerRails.install(self, params)

        Locomotive::Common::Logger.info "[Autoprefixer] detected and installed".light_white

        if ENV['EXECJS_RUNTIME'].blank?
          Locomotive::Common::Logger.warn "[Autoprefixer]".light_white + " [Warning] if you notice bad performance, install NodeJS and run \"export EXECJS_RUNTIME=Node\" in your shell"
        end

        Locomotive::Common::Logger.info "\n"
      end
    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
locomotivecms_steam-1.6.1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/initializers/sprockets.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/initializers/sprockets.rb