Class: AssetLibrary::AssetModule
- Inherits:
-
Object
- Object
- AssetLibrary::AssetModule
- Defined in:
- lib/asset_library/asset_module.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#assets(format = nil) ⇒ Object
Returns an Array of Assets to include.
-
#assets_with_extra_suffix(extra_suffix) ⇒ Object
Returns an Array of Assets to include.
-
#assets_with_format(format) ⇒ Object
Returns an Array of Assets to include.
-
#cache_asset(format = nil) ⇒ Object
Returns an Asset representing the cache file.
-
#compiler_flags ⇒ Object
Returns the Array of compiler flags to use.
-
#compiler_type ⇒ Object
Returns the type of compiler to use for this asset module.
-
#each_compilation ⇒ Object
Yield each set of input paths with their output path.
-
#formats ⇒ Object
Return the formats to generate.
-
#initialize(name, config) ⇒ AssetModule
constructor
A new instance of AssetModule.
Constructor Details
#initialize(name, config) ⇒ AssetModule
Returns a new instance of AssetModule.
7 8 9 10 11 |
# File 'lib/asset_library/asset_module.rb', line 7 def initialize(name, config) @name = name.to_s @config = config add_default_format end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/asset_library/asset_module.rb', line 5 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/asset_library/asset_module.rb', line 13 def name @name end |
Instance Method Details
#assets(format = nil) ⇒ Object
Returns an Array of Assets to include.
Arguments:
extra_suffix: if set, finds files with the given extra suffix
29 30 31 32 33 34 35 |
# File 'lib/asset_library/asset_module.rb', line 29 def assets(format = nil) if format assets_with_format(format) else assets_with_extra_suffix(nil) end end |
#assets_with_extra_suffix(extra_suffix) ⇒ Object
Returns an Array of Assets to include.
Arguments:
extra_suffix: if set, finds files with the given extra suffix
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/asset_library/asset_module.rb', line 41 def assets_with_extra_suffix(extra_suffix) return nil unless config GlobFu.find( config[:files], :suffix => config[:suffix], :extra_suffix => extra_suffix, :root => File.join(*([AssetLibrary.root, config[:base]].compact)), :optional_suffix => config[:optional_suffix] ).collect { |f| Asset.new(f) } end |
#assets_with_format(format) ⇒ Object
Returns an Array of Assets to include.
Calls assets_with_extra_suffix for each suffix in the given format
Arguments:
format: format specified in the config
59 60 61 62 63 64 |
# File 'lib/asset_library/asset_module.rb', line 59 def assets_with_format(format) return nil unless config extra_suffixes = config[:formats][format.to_sym] extra_suffixes.inject([]) { |r, s| r.concat(assets_with_extra_suffix(s)) } end |
#cache_asset(format = nil) ⇒ Object
Returns an Asset representing the cache file
67 68 69 70 |
# File 'lib/asset_library/asset_module.rb', line 67 def cache_asset(format = nil) extra = format ? ".#{format}" : '' Asset.new(File.join(AssetLibrary.root, config[:base], "#{config[:cache]}#{extra}.#{config[:suffix]}")) end |
#compiler_flags ⇒ Object
Returns the Array of compiler flags to use.
21 22 23 |
# File 'lib/asset_library/asset_module.rb', line 21 def compiler_flags Util.normalize_flags(config[:compiler_flags]) end |
#compiler_type ⇒ Object
Returns the type of compiler to use for this asset module.
16 17 18 |
# File 'lib/asset_library/asset_module.rb', line 16 def compiler_type (config[:compiler] || :default).to_sym end |
#each_compilation ⇒ Object
Yield each set of input paths with their output path. All paths are absolute.
79 80 81 82 83 84 85 |
# File 'lib/asset_library/asset_module.rb', line 79 def each_compilation formats.each do |format| inputs = assets(format).map { |asset| asset.absolute_path } output = cache_asset(format).absolute_path yield inputs, output end end |
#formats ⇒ Object
Return the formats to generate.
73 74 75 |
# File 'lib/asset_library/asset_module.rb', line 73 def formats (config[:formats] || {}).keys.sort_by{|sym| sym.to_s} end |