Class: Merb::Assets::AbstractAssetBundler Abstract
- Inherits:
-
Object
- Object
- Merb::Assets::AbstractAssetBundler
- Includes:
- AssetHelpers
- Defined in:
- merb-assets/lib/merb-assets/assets.rb
Overview
This class is abstract.
Override #asset_type in your implementation.
An abstract class for bundling text assets into single files.
Direct Known Subclasses
Constant Summary
Constant Summary
Constants included from AssetHelpers
Merb::Assets::AssetHelpers::ASSET_FILE_EXTENSIONS
Class Method Summary (collapse)
-
+ (Object) add_callback {|filename| ... }
(also: after_bundling)
-
+ (Symbol) asset_type
The type of asset for which the bundler is responsible.
-
+ (Object) cache_bundle(name)
Mark a bundle as cached.
-
+ (Boolean) cached_bundle?(name)
Test if a bundle has been cached.
-
+ (Array<Proc>) callbacks
Retrieve existing callbacks.
-
+ (Object) purge_bundle(name)
Purge a bundle from the cache.
Instance Method Summary (collapse)
-
- (Symbol) bundle!
Creates the new bundled file, executing all the callbacks.
-
- (AbstractAssetBundler) initialize(name, *files)
constructor
A new instance of AbstractAssetBundler.
Methods included from AssetHelpers
Constructor Details
- (AbstractAssetBundler) initialize(name, *files)
A new instance of AbstractAssetBundler
162 163 164 165 166 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 162 def initialize(name, *files) @bundle_name = name == true ? :all : name @bundle_filename = Merb.root / asset_path(self.class.asset_type, @bundle_name, true) @files = files.map { |f| Merb.root / asset_path(self.class.asset_type, f, true) } end |
Class Method Details
+ (Object) add_callback {|filename| ... } Also known as: after_bundling
134 135 136 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 134 def add_callback(&block) callbacks << block end |
+ (Symbol) asset_type
The type of asset for which the bundler is responsible. Override this method in your bundler code.
154 155 156 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 154 def asset_type raise NotImplementedError, "should return a symbol for the first argument to be passed to asset_path" end |
+ (Object) cache_bundle(name)
Mark a bundle as cached.
109 110 111 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 109 def cache_bundle(name) cached_bundles.push(name.to_s) end |
+ (Boolean) cached_bundle?(name)
Test if a bundle has been cached.
126 127 128 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 126 def cached_bundle?(name) cached_bundles.include?(name.to_s) end |
+ (Array<Proc>) callbacks
Retrieve existing callbacks.
142 143 144 145 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 142 def callbacks @callbacks ||= [] return @callbacks end |
+ (Object) purge_bundle(name)
Purge a bundle from the cache.
117 118 119 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 117 def purge_bundle(name) cached_bundles.delete(name.to_s) end |
Instance Method Details
- (Symbol) bundle!
Creates the new bundled file, executing all the callbacks.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'merb-assets/lib/merb-assets/assets.rb', line 171 def bundle! # TODO: push it out to the helper level so we don't have to create the helper object. unless self.class.cached_bundle?(@bundle_name) # skip regeneration of new bundled files - preventing multiple merb apps stepping on eachother # file needs to be older than 60 seconds to be regenerated if File.exist?(@bundle_filename) && File.mtime(@bundle_filename) >= Time.now - 60 return @bundle_name # serve the old file for now - to be regenerated later end bundle_files(@bundle_filename, *@files) if File.exist?(@bundle_filename) self.class.callbacks.each { |c| c.call(@bundle_filename) } Merb.logger.info("Assets: bundled :#{@bundle_name} into #{File.basename(@bundle_filename)}") self.class.cache_bundle(@bundle_name) end end return @bundle_name end |