Module: Hanami::Assets

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

Overview

Assets management for Ruby web applications

Since:

  • 0.1.0

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.configure(&blk) ⇒ Object

Configure framework

Parameters:

  • blk (Proc)

    configuration code block

Returns:

  • self

See Also:

  • Configuration

Since:

  • 0.1.0

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

.deployObject

Prepare assets for deploys

Since:

  • 0.1.0

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

  Precompiler.new(configuration, duplicates).run
  Bundler.new(configuration,     duplicates).run
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:

  • #dupe
  • Configuration

Since:

  • 0.1.0

def self.duplicate(_mod, &blk)
  dupe.tap do |duplicated|
    duplicated.configure(&blk) if block_given?
    duplicates << duplicated
  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

def self.load!
  configuration.load!
end

.precompile(configurations) ⇒ Object

Precompile assets

Since:

  • 0.4.0

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:

  • (Hanami::Assets::Config::GlobalSources)

Since:

  • 0.1.0

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