Class: RakeAssets

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_assets.rb,
lib/rake_assets/version.rb

Constant Summary collapse

VERSION =
'1.0.2'

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ RakeAssets

Returns a new instance of RakeAssets.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rake_assets.rb', line 8

def initialize(settings = {})
  @settings = {
    env:          Sprockets::Environment.new(Dir.pwd) { |env| env.logger = Logger.new(STDOUT) },
    root:         Dir.pwd,
    js_path:      'app/assets/javascripts',
    js_compiled:  "#{Dir.pwd}/public/assets/javascripts/application.js",
    css_path:     'app/assets/stylesheets',
    css_compiled: "#{Dir.pwd}/public/assets/stylesheets/application.css",
    # Uglifier Config - https://github.com/lautis/uglifier
    uglifier:     { mangle: true }, 
    # Ruby-YUI Compressor Config - https://github.com/sstephenson/ruby-yui-compressor
    yuicomp:      {} 
  }.merge(settings)
end

Instance Method Details

#checkObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rake_assets.rb', line 23

def check
  unless File.directory? @settings[:root]
    raise "Root path (#{@settings[:root]}) was not found."
  end

  unless File.directory? File.join(@settings[:root], @settings[:js_path])
    raise "Javascript path (#{@settings[:js_path]}) was not found."
  end

  unless File.directory? File.dirname(@settings[:js_compiled])
    raise "Javascript compiled path (#{File.dirname @settings[:js_compiled]}) was not found."
  end

  unless File.directory? File.join(@settings[:root], @settings[:css_path])
    raise "Style path (#{@settings[:css_path]}) was not found."
  end

  unless File.directory? File.dirname(@settings[:css_compiled])
    raise "Style compiled path (#{File.dirname @settings[:css_compiled]}) was not found."
  end
end

#compile_cssObject



52
53
54
55
56
57
# File 'lib/rake_assets.rb', line 52

def compile_css
  @settings[:env].clear_paths
  @settings[:env].css_compressor = YUI::CssCompressor.new(@settings[:yuicomp])
  @settings[:env].append_path(@settings[:css_path])
  @settings[:env].find_asset('application').write_to(@settings[:css_compiled])
end

#compile_jsObject



45
46
47
48
49
50
# File 'lib/rake_assets.rb', line 45

def compile_js
  @settings[:env].clear_paths
  @settings[:env].js_compressor = Uglifier.new(@settings[:uglifier])
  @settings[:env].append_path(@settings[:js_path])
  @settings[:env].find_asset('application').write_to(@settings[:js_compiled])
end