Class: Hanami::Components::App::Assets Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/components/app/assets.rb

Overview

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

hanami-assets configuration for a single Hanami application in the project.

Since:

  • 0.9.0

Class Method Summary collapse

Class Method Details

.resolve(app) ⇒ Object

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.

Configure hanami-assets for a single Hanami application in the project.

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Parameters:

Since:

  • 0.9.0



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hanami/components/app/assets.rb', line 22

def self.resolve(app)
  config    = app.configuration
  namespace = app.namespace

  unless namespace.const_defined?('Assets', false)
    assets = Hanami::Assets.duplicate(namespace) do
      root             config.root

      scheme           config.scheme
      host             config.host
      port             config.port

      public_directory Hanami.public_directory
      prefix           Utils::PathPrefix.new('/assets').join(config.path_prefix)

      manifest         Hanami.public_directory.join('assets.json')
      compile          true

      config.assets.__apply(self)
    end

    assets.configure do
      cdn host != config.host
    end

    namespace.const_set('Assets', assets)
  end

  name = "#{app.app_name}.assets"
  Components.resolved(name, namespace.const_get('Assets').configuration)
  Components[name]
end