Module: UnifiedAssets::Minifier

Defined in:
lib/unified_assets/minifier.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



5
6
7
# File 'lib/unified_assets/minifier.rb', line 5

def enabled
  @enabled
end

.extensionsObject

Returns the value of attribute extensions.



6
7
8
# File 'lib/unified_assets/minifier.rb', line 6

def extensions
  @extensions
end

.jarfileObject

Returns the value of attribute jarfile.



7
8
9
# File 'lib/unified_assets/minifier.rb', line 7

def jarfile
  @jarfile
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/unified_assets/minifier.rb', line 13

def self.available?
  @available ||= !`which java`.empty?   # warning: linux only way of checking if java is available
end

.enabled?(name = nil) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/unified_assets/minifier.rb', line 17

def self.enabled?(name = nil)
  enabled && available? && (name.nil? || extensions.include?(File.extname(name)))
end

.minified_name(name) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/unified_assets/minifier.rb', line 21

def self.minified_name(name)
  if enabled?(name)
    ext = File.extname(name)
    name.sub(ext, ".min#{ext}")
  else
    name
  end
end

.minify(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/unified_assets/minifier.rb', line 30

def self.minify(name)
  if name && enabled?(name) && File.exists?(name)
    minified_name = minified_name(name)
    `java -jar "#{jarfile}" "#{name}" -o "#{minified_name}"`
  end
end