Module: Locomotive::Mounter::Extensions::Sprockets

Defined in:
lib/locomotive/mounter/extensions/sprockets.rb

Constant Summary collapse

@@env =
@@path = nil

Class Method Summary collapse

Class Method Details

.environment(site_path, minify = false) ⇒ Object

Build a Sprocket environment for the current site. This method returns an unique environment for each call unless the site_path changed.

Parameters:

  • site_path (String)

    The root directory of the site

  • minify (Boolean) (defaults to: false)

    Minify the js and css assets (default: false)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/locomotive/mounter/extensions/sprockets.rb', line 18

def self.environment(site_path, minify = false)
  return @@env if @@env && @@path == site_path

  @@path  = site_path
  @@env   = ::Sprockets::Environment.new.tap do |env|
    if minify && is_java_installed?
      # minify javascripts and stylesheets
      env.js_compressor  = YUI::JavaScriptCompressor.new
      env.css_compressor = YUI::CssCompressor.new
    else
      message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n"
      Locomotive::Mounter.logger.warn message.colorize(color: :red)
    end

    %w(fonts stylesheets javascripts).each do |name|
      env.append_path File.join(site_path, 'public', name)
    end
  end
end

.is_java_installed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/locomotive/mounter/extensions/sprockets.rb', line 38

def self.is_java_installed?
  `which java` != '' && (!ENV['JAVA_HOME'].blank? && File.exists?(ENV['JAVA_HOME']))
end