Class: Hanami::Assets::Config

Inherits:
Object
  • Object
show all
Includes:
Dry::Configurable
Defined in:
lib/hanami/sprockets/config.rb

Overview

Hanami sprockets configuration.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**values) {|config| ... } ⇒ Config

Returns a new instance of Config.

Yields:

Since:

  • 0.1.0



84
85
86
87
88
89
90
# File 'lib/hanami/sprockets/config.rb', line 84

def initialize(**values)
  super()

  config.update(values.select { |k| _settings.key?(k) })

  yield(config) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)

Since:

  • 0.1.0



110
111
112
113
114
115
116
# File 'lib/hanami/sprockets/config.rb', line 110

def method_missing(name, ...)
  if config.respond_to?(name)
    config.public_send(name, ...)
  else
    super
  end
end

Instance Attribute Details

#asset_pathsArray<String>

Returns:

  • (Array<String>)

Since:

  • 0.1.0



52
# File 'lib/hanami/sprockets/config.rb', line 52

setting :asset_paths, default: []

#base_urlBaseUrl

Examples:

config.base_url = "http://some-cdn.com/assets"

Returns:

Since:

  • 0.1.0



45
# File 'lib/hanami/sprockets/config.rb', line 45

setting :base_url, constructor: -> url { BaseUrl.new(url.to_s) }

#cacheString?

Returns Cache directory path.

Returns:

  • (String, nil)

    Cache directory path

Since:

  • 0.1.0



80
# File 'lib/hanami/sprockets/config.rb', line 80

setting :cache, default: nil

#compressBoolean

Returns Whether to compress assets.

Returns:

  • (Boolean)

    Whether to compress assets

Since:

  • 0.1.0



73
# File 'lib/hanami/sprockets/config.rb', line 73

setting :compress, default: true

#digestBoolean

Returns Whether to use fingerprinted asset names.

Returns:

  • (Boolean)

    Whether to use fingerprinted asset names

Since:

  • 0.1.0



66
# File 'lib/hanami/sprockets/config.rb', line 66

setting :digest, default: true

#path_prefixString

Returns:

  • (String)

Since:

  • 0.1.0



25
# File 'lib/hanami/sprockets/config.rb', line 25

setting :path_prefix, default: "/assets"

#precompileArray<String>

Returns:

  • (Array<String>)

Since:

  • 0.1.0



59
# File 'lib/hanami/sprockets/config.rb', line 59

setting :precompile, default: %w[*.js *.css *.png *.jpg *.gif *.svg]

#subresource_integrityArray<Symbol>

Examples:

config.subresource_integrity # => [:sha256, :sha512]

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0



35
# File 'lib/hanami/sprockets/config.rb', line 35

setting :subresource_integrity, default: []

Instance Method Details

#crossorigin?(source) ⇒ Boolean

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.

Returns true if the given source is linked via Cross-Origin policy (or in other words, if the given source does not satisfy the Same-Origin policy).



104
105
106
# File 'lib/hanami/sprockets/config.rb', line 104

def crossorigin?(source)
  base_url.crossorigin?(source)
end