Class: Hanami::Assets::Compiler Private
- Inherits:
-
Object
- Object
- Hanami::Assets::Compiler
- Includes:
- Utils::ClassAttribute
- Defined in:
- lib/hanami/assets/compiler.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.
Assets compiler
It compiles assets that needs to be preprocessed (eg. Sass or ES6) into the destination directory.
Vanilla javascripts or stylesheets are just copied over.
Direct Known Subclasses
Hanami::Assets::Compilers::Less, Hanami::Assets::Compilers::Sass
Constant Summary collapse
- DEFAULT_PERMISSIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0o644
- COMPILE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'*.*.*'.freeze
- EXTENSIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ '.js' => true, '.css' => true, '.map' => true }.freeze
Class Method Summary collapse
-
.cache ⇒ Object
private
Assets cache.
-
.compile(configuration, name) ⇒ Object
private
Compile the given asset.
- .eligible?(_name) ⇒ Boolean private
- .fabricate(configuration, name) ⇒ Object private
- .inherited(subclass) ⇒ Object private
Instance Method Summary collapse
-
#compile ⇒ Object
private
Compile the asset.
-
#initialize(configuration, name) ⇒ Hanami::Assets::Compiler
constructor
private
Return a new instance.
Constructor Details
#initialize(configuration, name) ⇒ Hanami::Assets::Compiler
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.
Return a new instance
115 116 117 118 |
# File 'lib/hanami/assets/compiler.rb', line 115 def initialize(configuration, name) @configuration = configuration @name = Pathname.new(name) end |
Class Method Details
.cache ⇒ 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.
Assets cache
100 101 102 |
# File 'lib/hanami/assets/compiler.rb', line 100 def self.cache @@cache ||= Assets::Cache.new # rubocop:disable Style/ClassVars end |
.compile(configuration, name) ⇒ 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.
Compile the given asset
67 68 69 70 71 72 73 74 75 |
# File 'lib/hanami/assets/compiler.rb', line 67 def self.compile(configuration, name) return unless configuration.compile require 'tilt' require 'hanami/assets/cache' require 'hanami/assets/compilers/sass' require 'hanami/assets/compilers/less' fabricate(configuration, name).compile end |
.eligible?(_name) ⇒ 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.
90 91 92 |
# File 'lib/hanami/assets/compiler.rb', line 90 def self.eligible?(_name) true end |
.fabricate(configuration, name) ⇒ 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.
79 80 81 82 83 84 85 86 |
# File 'lib/hanami/assets/compiler.rb', line 79 def self.fabricate(configuration, name) source = configuration.source(name) engine = (subclasses + [self]).find do |klass| klass.eligible?(source) end engine.new(configuration, name) end |
.inherited(subclass) ⇒ 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.
53 54 55 56 |
# File 'lib/hanami/assets/compiler.rb', line 53 def self.inherited(subclass) super subclasses.add(subclass) end |
Instance Method Details
#compile ⇒ 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.
Compile the asset
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/hanami/assets/compiler.rb', line 127 def compile raise MissingAsset.new(@name, @configuration.sources) unless exist? return unless modified? if compile? compile! else copy! end cache! end |