module Hanami::Assets
Assets
management for Ruby web applications
@since 0.1.0
Constants
- VERSION
Defines the version
@since 0.1.0
Public Class Methods
Configure framework
@param blk [Proc] configuration code block
@return self
@since 0.1.0
@see Hanami::Assets::Configuration
# File lib/hanami/assets.rb, line 44 def self.configure(&blk) configuration.instance_eval(&blk) self end
Prepare assets for deploys
@since 0.1.0
# File lib/hanami/assets.rb, line 52 def self.deploy require "hanami/assets/precompiler" require "hanami/assets/bundler" Precompiler.new(configuration, duplicates).run Bundler.new(configuration, duplicates).run end
Duplicate Hanami::Assets
in order to create a new separated instance of the framework.
The new instance of the framework will be completely decoupled from the original. It will inherit the configuration, but all the changes that happen after the duplication, won't be reflected on the other copies.
@return [Module] a copy of Hanami::Assets
@since 0.1.0 @api private
# File lib/hanami/assets.rb, line 144 def self.dupe dup.tap do |duplicated| duplicated.configuration = configuration.duplicate end end
Duplicate the framework and generate modules for the target application
@param _mod [Module] the Ruby namespace of the application @param blk [Proc] an optional block to configure the framework
@return [Module] a copy of Hanami::Assets
@since 0.1.0
@see Hanami::Assets#dupe @see Hanami::Assets::Configuration
# File lib/hanami/assets.rb, line 126 def self.duplicate(_mod, &blk) dupe.tap do |duplicated| duplicated.configure(&blk) if block_given? duplicates << duplicated end end
Keep track of duplicated frameworks
@return [Array] a collection of duplicated frameworks
@since 0.1.0 @api private
@see Hanami::Assets#duplicate @see Hanami::Assets#dupe
# File lib/hanami/assets.rb, line 159 def self.duplicates synchronize do @@duplicates ||= [] # rubocop:disable Style/ClassVars end end
Preload the framework
This MUST be used in production mode
@since 0.1.0
@example Direct Invocation
require 'hanami/assets' Hanami::Assets.load!
@example Load Via Configuration
Block
require 'hanami/assets' Hanami::Assets.configure do # ... end.load!
# File lib/hanami/assets.rb, line 88 def self.load! configuration.load! end
Precompile assets
@since 0.4.0
# File lib/hanami/assets.rb, line 63 def self.precompile(configurations) require "hanami/assets/precompiler" require "hanami/assets/bundler" Precompiler.new(configuration, configurations).run Bundler.new(configuration, configurations).run end
Global assets sources
This is designed for third party integration gems with frontend frameworks like Bootstrap, Ember.js or React.
Developers can maintain gems that ship static assets for these frameworks and make them available to Hanami::Assets
.
@return [Hanami::Assets::Config::GlobalSources]
@since 0.1.0
@example Ember.js Integration
# lib/hanami/emberjs.rb (third party gem) require 'hanami/assets' Hanami::Assets.sources << '/path/to/emberjs/assets'
# File lib/hanami/assets.rb, line 109 def self.sources synchronize do @@sources ||= Config::GlobalSources.new # rubocop:disable Style/ClassVars end end
Private Class Methods
@since 0.1.0 @api private
# File lib/hanami/assets.rb, line 170 def synchronize(&blk) Mutex.new.synchronize(&blk) end