Class: Gumbo::AssetPackage
- Inherits:
-
Object
- Object
- Gumbo::AssetPackage
- Defined in:
- lib/gumbo/asset_package.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#files ⇒ Object
Returns the value of attribute files.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build ⇒ Object
- #compress(out) ⇒ Object
- #eql?(o) ⇒ Boolean (also: #==)
- #file_name ⇒ Object
- #hash ⇒ Object
-
#initialize(attrs = {}) ⇒ AssetPackage
constructor
A new instance of AssetPackage.
- #logger ⇒ Object
- #output_file ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ AssetPackage
Returns a new instance of AssetPackage.
9 10 11 12 13 |
# File 'lib/gumbo/asset_package.rb', line 9 def initialize(attrs={}) attrs.each do |k,v| send("#{k}=", v) end end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
7 8 9 |
# File 'lib/gumbo/asset_package.rb', line 7 def digest @digest end |
#files ⇒ Object
Returns the value of attribute files.
7 8 9 |
# File 'lib/gumbo/asset_package.rb', line 7 def files @files end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/gumbo/asset_package.rb', line 7 def name @name end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
7 8 9 |
# File 'lib/gumbo/asset_package.rb', line 7 def output_dir @output_dir end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/gumbo/asset_package.rb', line 7 def type @type end |
Instance Method Details
#build ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gumbo/asset_package.rb', line 27 def build out = "" files.each do |file| out << File.read(file.output_file) out << "\n" end out = compress(out) self.digest = Digest::MD5.hexdigest(out) open(output_file, 'w') do |f| f << out end logger.info "Created package #{output_file}" end |
#compress(out) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gumbo/asset_package.rb', line 45 def compress(out) case type when 'css' CSSMin.minify(out) when 'js' Uglifier.compile(out, :mangle => true) else raise "Unknown package type '#{type}'" end end |
#eql?(o) ⇒ Boolean Also known as: ==
56 57 58 59 60 |
# File 'lib/gumbo/asset_package.rb', line 56 def eql?(o) o.is_a?(self.class) && o.type == type && o.name == name end |
#file_name ⇒ Object
19 20 21 |
# File 'lib/gumbo/asset_package.rb', line 19 def file_name @file_name ||= "#{name}-#{digest}.#{type}" end |
#hash ⇒ Object
63 64 65 |
# File 'lib/gumbo/asset_package.rb', line 63 def hash type.hash ^ name.hash end |
#output_file ⇒ Object
23 24 25 |
# File 'lib/gumbo/asset_package.rb', line 23 def output_file @output_file ||= File.join(output_dir, file_name) end |