Module: Hanami::Assets

Includes:
Utils::ClassAttribute
Defined in:
lib/hanami/assets.rb,
lib/hanami/assets/cache.rb,
lib/hanami/assets/bundler.rb,
lib/hanami/assets/helpers.rb,
lib/hanami/assets/version.rb,
lib/hanami/assets/compiler.rb,
lib/hanami/assets/precompiler.rb,
lib/hanami/assets/bundler/asset.rb,
lib/hanami/assets/configuration.rb,
lib/hanami/assets/compilers/less.rb,
lib/hanami/assets/compilers/sass.rb,
lib/hanami/assets/config/sources.rb,
lib/hanami/assets/config/manifest.rb,
lib/hanami/assets/bundler/compressor.rb,
lib/hanami/assets/compressors/abstract.rb,
lib/hanami/assets/config/global_sources.rb,
lib/hanami/assets/bundler/manifest_entry.rb,
lib/hanami/assets/compressors/javascript.rb,
lib/hanami/assets/compressors/stylesheet.rb,
lib/hanami/assets/compressors/yui_javascript.rb,
lib/hanami/assets/compressors/yui_stylesheet.rb,
lib/hanami/assets/compressors/null_compressor.rb,
lib/hanami/assets/compressors/sass_stylesheet.rb,
lib/hanami/assets/compressors/builtin_javascript.rb,
lib/hanami/assets/compressors/builtin_stylesheet.rb,
lib/hanami/assets/compressors/closure_javascript.rb,
lib/hanami/assets/compressors/uglifier_javascript.rb

Overview

Assets management for Ruby web applications

Since:

  • 0.1.0

Defined Under Namespace

Modules: Compilers, Compressors, Config, Helpers Classes: Bundler, Cache, Compiler, Configuration, Error, MissingAsset, MissingManifestAssetError, MissingManifestFileError, Precompiler, UnknownAssetEngine

Constant Summary collapse

VERSION =

Defines the version

Since:

  • 0.1.0

'1.3.4'.freeze

Class Method Summary collapse

Class Method Details

.configure(&blk) ⇒ Object

Configure framework

See Also:

Since:

  • 0.1.0


42
43
44
45
# File 'lib/hanami/assets.rb', line 42

def self.configure(&blk)
  configuration.instance_eval(&blk)
  self
end

.deployObject

Prepare assets for deploys

Since:

  • 0.1.0


50
51
52
53
54
55
56
# File 'lib/hanami/assets.rb', line 50

def self.deploy
  require 'hanami/assets/precompiler'
  require 'hanami/assets/bundler'

  Precompiler.new(configuration, duplicates).run
  Bundler.new(configuration,     duplicates).run
end

.dupeModule

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Since:

  • 0.1.0


142
143
144
145
146
# File 'lib/hanami/assets.rb', line 142

def self.dupe
  dup.tap do |duplicated|
    duplicated.configuration = configuration.duplicate
  end
end

.duplicate(_mod, &blk) ⇒ Module

Duplicate the framework and generate modules for the target application

See Also:

Since:

  • 0.1.0


124
125
126
127
128
129
# File 'lib/hanami/assets.rb', line 124

def self.duplicate(_mod, &blk)
  dupe.tap do |duplicated|
    duplicated.configure(&blk) if block_given?
    duplicates << duplicated
  end
end

.duplicatesArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Keep track of duplicated frameworks

See Also:

  • #duplicate
  • #dupe

Since:

  • 0.1.0


157
158
159
160
161
# File 'lib/hanami/assets.rb', line 157

def self.duplicates
  synchronize do
    @@duplicates ||= [] # rubocop:disable Style/ClassVars
  end
end

.load!Object

Preload the framework

This MUST be used in production mode

Examples:

Direct Invocation

require 'hanami/assets'

Hanami::Assets.load!

Load Via Configuration Block

require 'hanami/assets'

Hanami::Assets.configure do
  # ...
end.load!

Since:

  • 0.1.0


86
87
88
# File 'lib/hanami/assets.rb', line 86

def self.load!
  configuration.load!
end

.precompile(configurations) ⇒ Object

Precompile assets

Since:

  • 0.4.0


61
62
63
64
65
66
67
# File 'lib/hanami/assets.rb', line 61

def self.precompile(configurations)
  require 'hanami/assets/precompiler'
  require 'hanami/assets/bundler'

  Precompiler.new(configuration, configurations).run
  Bundler.new(configuration,     configurations).run
end

.sourcesHanami::Assets::Config::GlobalSources

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.

Examples:

Ember.js Integration

# lib/hanami/emberjs.rb (third party gem)
require 'hanami/assets'

Hanami::Assets.sources << '/path/to/emberjs/assets'

Since:

  • 0.1.0


107
108
109
110
111
# File 'lib/hanami/assets.rb', line 107

def self.sources
  synchronize do
    @@sources ||= Config::GlobalSources.new # rubocop:disable Style/ClassVars
  end
end