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.
-
#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 |
# File 'lib/asset_library/asset_module.rb', line 7 def initialize(name, config) @name = name.to_s @config = config 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.
12 13 14 |
# File 'lib/asset_library/asset_module.rb', line 12 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
28 29 30 31 32 33 34 |
# File 'lib/asset_library/asset_module.rb', line 28 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
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/asset_library/asset_module.rb', line 40 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
58 59 60 61 62 63 |
# File 'lib/asset_library/asset_module.rb', line 58 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
66 67 68 69 |
# File 'lib/asset_library/asset_module.rb', line 66 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.
20 21 22 |
# File 'lib/asset_library/asset_module.rb', line 20 def compiler_flags Util.normalize_flags(config[:compiler_flags]) end |
#compiler_type ⇒ Object
Returns the type of compiler to use for this asset module.
15 16 17 |
# File 'lib/asset_library/asset_module.rb', line 15 def compiler_type (config[:compiler] || :default).to_sym end |