Class: Fletch::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/fletch/asset.rb

Instance Method Summary collapse

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

#contentObject



15
16
17
# File 'lib/fletch/asset.rb', line 15

def content
  @content ||= open(@url).read
end

#logObject



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_contentObject



23
24
25
# File 'lib/fletch/asset.rb', line 23

def minified_content
  Uglifier.compile(content)
end

#output_file_pathObject



19
20
21
# File 'lib/fletch/asset.rb', line 19

def output_file_path
  File.join(@path, @output_filename)
end

#writeObject



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