Class: Fletch::Asset
- Inherits:
-
Object
- Object
- Fletch::Asset
- Defined in:
- lib/fletch/asset.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(library, attributes) ⇒ Asset
constructor
A new instance of Asset.
- #log ⇒ Object
- #minified_content ⇒ Object
- #output_file_path ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(library, attributes) ⇒ Asset
Returns a new instance of Asset.
7 8 9 10 11 12 13 |
# File 'lib/fletch/asset.rb', line 7 def initialize(library, attributes) @library = library @url = attributes['url'] @path = attributes['path'] @minify = attributes['minify'] @output_filename = attributes['output_filename'] || File.basename(@url) end |
Instance Method Details
#content ⇒ Object
15 16 17 |
# File 'lib/fletch/asset.rb', line 15 def content @content ||= open(@url).read end |
#log ⇒ Object
36 37 38 39 40 41 |
# File 'lib/fletch/asset.rb', line 36 def log puts "#{@library}:" puts "\tfetching #{@url}" puts "\tminifying" if @minify puts "\twriting #{output_file_path}" end |
#minified_content ⇒ Object
23 24 25 |
# File 'lib/fletch/asset.rb', line 23 def minified_content Uglifier.compile(content) end |
#output_file_path ⇒ Object
19 20 21 |
# File 'lib/fletch/asset.rb', line 19 def output_file_path File.join(@path, @output_filename) end |
#write ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/fletch/asset.rb', line 27 def write log open(output_file_path, 'wb') do |file| file << (@minify ? minified_content : content) end rescue Exception => e puts "\tFAILED: #{e}" end |