Class: Hanami::Assets::Configuration

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-assets-1.3.3/lib/hanami/assets/configuration.rb,
gems/gems/hanami-assets-1.3.4/lib/hanami/assets/configuration.rb

Overview

Framework configuration

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cdn(value = nil) ⇒ Object

CDN mode

Determine if the helpers should always generate absolute URL. This is useful in production mode.

Since:

  • 0.1.0

def cdn(value = nil)
  if value.nil?
    @cdn
  else
    @cdn = !!value # rubocop:disable Style/DoubleNegation
  end
end

#compile(value = nil) ⇒ Object

Compile mode

Determine if compile assets from sources to destination. Usually this is turned off in production mode.

Since:

  • 0.1.0

def compile(value = nil)
  if value.nil?
    @compile
  else
    @compile = value
  end
end

#host(value = nil) ⇒ Object

URL host for the application

This is used to generate absolute URL from helpers.

Since:

  • 0.1.0

def host(value = nil)
  if value.nil?
    @host
  else
    @host = value
  end
end

#javascript_compressor(value = nil) ⇒ Object

JavaScript compressor

Determine which compressor to use for JavaScript files during deploy.

By default it's nil, that means it doesn't compress JavaScripts at deploy time.

It accepts a Symbol or an object that respond to #compress(file).

The following symbols are accepted:

  • :builtin - Ruby based implementation of jsmin. It doesn't require any external gem.

  • :yui - YUI Compressor, it depends on yui-compressor gem and it requires Java 1.4+

  • :uglifier - UglifyJS, it depends on uglifier gem and it requires Node.js

  • :closure - Google Closure Compiler, it depends on closure-compiler gem and it requires Java

Examples:

YUI Compressor

require 'hanami/assets'

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

Custom Compressor

require 'hanami/assets'

Hanami::Assets.configure do
  # ...
  javascript_compressor MyCustomJavascriptCompressor.new
end.load!

Parameters:

  • value (Symbol, #compress) (defaults to: nil)

    the compressor

See Also:

Since:

  • 0.1.0

def javascript_compressor(value = nil)
  if value.nil?
    @javascript_compressor
  else
    @javascript_compressor = value
  end
end

#manifest(value = nil) ⇒ Object

Manifest path from public directory

Since:

  • 0.1.0

def manifest(value = nil)
  if value.nil?
    @manifest
  else
    @manifest = value.to_s
  end
end

#nested(value = nil) ⇒ Object

Support for nested path

Since:

  • 1.3.1

def nested(value = nil)
  if value.nil?
    @nested
  else
    @nested = !!value # rubocop:disable Style/DoubleNegation
  end
end

#port(value = nil) ⇒ Object

URL port for the application

This is used to generate absolute URL from helpers.

Since:

  • 0.1.0

def port(value = nil)
  if value.nil?
    @port
  else
    @port = value.to_s
  end
end

#prefix(value = nil) ⇒ Object

URL port for the application

This is used to generate absolute or relative URL from helpers.

Since:

  • 0.1.0

def prefix(value = nil)
  if value.nil?
    @prefix
  else
    @prefix = Utils::PathPrefix.new(value)
  end
end

#public_directory(value = nil) ⇒ Object

Application public directory

Since:

  • 0.1.0

def public_directory(value = nil)
  if value.nil?
    @public_directory
  else
    @public_directory = Pathname.new(::File.expand_path(value))
  end
end

#root(value = nil) ⇒ Object

Sources root

Since:

  • 0.1.0

def root(value = nil)
  if value.nil?
    @root
  else
    @root = Pathname.new(value).realpath
    sources.root = @root
  end
end

#scheme(value = nil) ⇒ Object

URL scheme for the application

This is used to generate absolute URL from helpers.

Since:

  • 0.1.0

def scheme(value = nil)
  if value.nil?
    @scheme
  else
    @scheme = value
  end
end

#stylesheet_compressor(value = nil) ⇒ Object

Stylesheet compressor

Determine which compressor to use for Stylesheet files during deploy.

By default it's nil, that means it doesn't compress Stylesheets at deploy time.

It accepts a Symbol or an object that respond to #compress(file).

The following symbols are accepted:

  • :builtin - Ruby based compressor. It doesn't require any external gem. It's fast, but not an efficient compressor.

  • :yui - YUI-Compressor, it depends on yui-compressor gem and requires Java 1.4+

  • :sass - Sass, it depends on sassc gem

Examples:

YUI Compressor

require 'hanami/assets'

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

Custom Compressor

require 'hanami/assets'

Hanami::Assets.configure do
  # ...
  stylesheet_compressor MyCustomStylesheetCompressor.new
end.load!

Parameters:

  • value (Symbol, #compress) (defaults to: nil)

    the compressor

See Also:

Since:

  • 0.1.0

def stylesheet_compressor(value = nil)
  if value.nil?
    @stylesheet_compressor
  else
    @stylesheet_compressor = value
  end
end

#subresource_integrity(*values) ⇒ Object

Subresource integrity mode

Determine if the helpers should generate the integrity attribute for an asset. Usually this is turned on in production mode.

Since:

  • 0.3.0

def subresource_integrity(*values)
  if values.empty?
    @subresource_integrity
  elsif values.length == 1
    @subresource_integrity = values.first
  else
    @subresource_integrity = values
  end
end

Instance Method Details

#base_directoriesObject

Since:

  • 1.3.0

def base_directories
  @base_directories ||= %w[
    stylesheets
    javascripts
    images
    fonts
  ]
end

#fingerprint(value = nil) ⇒ Object

Fingerprint mode

Determine if the helpers should generate the fingerprinted path for an asset. Usually this is turned on in production mode.

Since:

  • 0.1.0

def fingerprint(value = nil)
  if value.nil?
    @fingerprint
  else
    @fingerprint = value
  end
end

#subresource_integrity_algorithmsObject

An array of crypographically secure hashing algorithms to use for generating asset subresource integrity checks

Since:

  • 0.3.0

def subresource_integrity_algorithms
  if @subresource_integrity == true
    [DEFAULT_SUBRESOURCE_INTEGRITY_ALGORITHM]
  else
    # Using Array() allows us to accept Array or Symbol, and '|| nil' lets
    # us return an empty array when @subresource_integrity is `false`
    Array(@subresource_integrity || nil)
  end
end