Class: CoffeeBundler
- Inherits:
-
Object
- Object
- CoffeeBundler
- Defined in:
- lib/asset_build/coffee_bundler.rb
Instance Method Summary collapse
- #append(*args) ⇒ Object
- #compressed ⇒ Object
-
#initialize(*args) ⇒ CoffeeBundler
constructor
A new instance of CoffeeBundler.
- #save(name, options = {}) ⇒ Object
- #to_javascript ⇒ Object
Constructor Details
#initialize(*args) ⇒ CoffeeBundler
Returns a new instance of CoffeeBundler.
5 6 7 8 9 10 |
# File 'lib/asset_build/coffee_bundler.rb', line 5 def initialize(*args) @@yui = YUI::JavaScriptCompressor.new @files = {} @processed_js = [] append(*args) end |
Instance Method Details
#append(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asset_build/coffee_bundler.rb', line 12 def append(*args) unless args.nil? || args.length < 1 if args.length == 1 args = args[0] if args.class == Array args = [args] if args.class == String end for path in args if File.directory?(path) for inner_path in Dir.glob(File.join(path,'*.coffee')).to_a process_path(inner_path) end else process_path(path) end end end end |
#compressed ⇒ Object
34 35 36 |
# File 'lib/asset_build/coffee_bundler.rb', line 34 def compressed @@yui.compress(to_javascript) end |
#save(name, options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/asset_build/coffee_bundler.rb', line 38 def save(name,={}) compress = [:compress] || false File.open(name,'w') {|f| f.write compress ? compressed : to_javascript } end |
#to_javascript ⇒ Object
30 31 32 |
# File 'lib/asset_build/coffee_bundler.rb', line 30 def to_javascript @files.sort{|a,b| a[1][:position]<=>b[1][:position]}.map{ |path,values| values[:contents] }.join("") end |