Class: CabezaDeTermo::Assets::Bundle
- Inherits:
-
Object
- Object
- CabezaDeTermo::Assets::Bundle
- Defined in:
- lib/cabeza-de-termo/assets/bundles/bundle.rb
Overview
A list of assets and other bundles to be collected by an assets_collector. A bundle can include a reference to an asset, such as ‘jquery.js’, or require a reference to another bundle.
The bundles are defined in the Library.definition, example:
CabezaDeTermo::Assets::Library.definition do bundle :‘bootstrap-js’ do require :jquery include ‘asset_2.js’ end end
Instance Method Summary collapse
-
#collect_assets_with(assets_collector) ⇒ Object
Add all the referenced assets to the assets_collector.
-
#include(asset) ⇒ Object
Include a reference to the asset.
-
#initialize ⇒ Bundle
constructor
Initialize the instance.
-
#new_asset_reference_on(asset) ⇒ Object
Create a new AssetReference on the asset.
-
#new_assets_bundle_reference_on(bundle_name) ⇒ Object
Create a new BundleReference on the bundle_name.
-
#references ⇒ Object
Answer the list of references defined for this bundle.
-
#require(bundle_name) ⇒ Object
Require a reference to another bundle named bundle_name.
Constructor Details
#initialize ⇒ Bundle
Initialize the instance
21 22 23 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 21 def initialize @references = [] end |
Instance Method Details
#collect_assets_with(assets_collector) ⇒ Object
Add all the referenced assets to the assets_collector. Add both the assets included in this bundle and the assets included in another bundles required by this bundle.
45 46 47 48 49 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 45 def collect_assets_with(assets_collector) @references.each do |asset| asset.collect_assets_with assets_collector end end |
#include(asset) ⇒ Object
Include a reference to the asset. The asset can be any string, such as ‘/vendor/jquery.js’.
32 33 34 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 32 def include(asset) @references << new_asset_reference_on(asset) end |
#new_asset_reference_on(asset) ⇒ Object
Create a new AssetReference on the asset
52 53 54 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 52 def new_asset_reference_on(asset) AssetReference.on asset end |
#new_assets_bundle_reference_on(bundle_name) ⇒ Object
Create a new BundleReference on the bundle_name
57 58 59 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 57 def new_assets_bundle_reference_on(bundle_name) BundleReference.on bundle_name end |
#references ⇒ Object
Answer the list of references defined for this bundle. References may be any combination of AssetReference and BundleReference.
27 28 29 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 27 def references @references end |
#require(bundle_name) ⇒ Object
Require a reference to another bundle named bundle_name. By requiring another bundle, the assets_collector will collect all the assets in the another bundle.
39 40 41 |
# File 'lib/cabeza-de-termo/assets/bundles/bundle.rb', line 39 def require(bundle_name) @references << new_assets_bundle_reference_on(bundle_name) end |