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.5"

Class Method Summary collapse

Class Method Details

.configure(&blk) ⇒ Object

Configure framework

Parameters:

  • blk (Proc)

    configuration code block

Returns:

  • self

See Also:

Since:

  • 0.1.0


44
45
46
47
# File 'lib/hanami/assets.rb', line 44

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

.deployObject

Prepare assets for deploys

Since:

  • 0.1.0


52
53
54
55
56
57
58
# 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

.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.

Returns:

  • (Module)

    a copy of Hanami::Assets

Since:

  • 0.1.0


144
145
146
147
148
# File 'lib/hanami/assets.rb', line 144

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

Parameters:

  • _mod (Module)

    the Ruby namespace of the application

  • blk (Proc)

    an optional block to configure the framework

Returns:

  • (Module)

    a copy of Hanami::Assets

See Also:

Since:

  • 0.1.0


126
127
128
129
130
131
# 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

.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

Returns:

  • (Array)

    a collection of duplicated frameworks

See Also:

  • #duplicate
  • #dupe

Since:

  • 0.1.0


159
160
161
162
163
# File 'lib/hanami/assets.rb', line 159

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


88
89
90
# File 'lib/hanami/assets.rb', line 88

def self.load!
  configuration.load!
end

.precompile(configurations) ⇒ Object

Precompile assets

Since:

  • 0.4.0


63
64
65
66
67
68
69
# 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

.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'

Returns:

Since:

  • 0.1.0


109
110
111
112
113
# File 'lib/hanami/assets.rb', line 109

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