hanami-assets 1.3.0 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/LICENSE.md +1 -1
- data/README.md +27 -6
- data/bin/hanami-assets +7 -6
- data/hanami-assets.gemspec +4 -2
- data/lib/hanami/assets.rb +11 -9
- data/lib/hanami/assets/bundler.rb +10 -8
- data/lib/hanami/assets/bundler/asset.rb +4 -2
- data/lib/hanami/assets/bundler/compressor.rb +8 -6
- data/lib/hanami/assets/bundler/manifest_entry.rb +6 -4
- data/lib/hanami/assets/cache.rb +3 -1
- data/lib/hanami/assets/compiler.rb +27 -16
- data/lib/hanami/assets/compilers/less.rb +3 -1
- data/lib/hanami/assets/compilers/sass.rb +26 -11
- data/lib/hanami/assets/compressors/sass_stylesheet.rb +9 -11
- data/lib/hanami/assets/config/global_sources.rb +4 -2
- data/lib/hanami/assets/config/manifest.rb +4 -2
- data/lib/hanami/assets/config/sources.rb +5 -3
- data/lib/hanami/assets/configuration.rb +54 -32
- data/lib/hanami/assets/helpers.rb +41 -33
- data/lib/hanami/assets/precompiler.rb +7 -5
- data/lib/hanami/assets/version.rb +3 -1
- metadata +31 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5176826ee1e6f1cdf7930ec50f52e9e2c3ddaad08c29081f50c3b523edf39910
|
|
4
|
+
data.tar.gz: 5cdb9005b3f3c818d0ede825faa6e022ea61bf0d11d5d48c290b96797f28b0e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 249d3393b9b7936b601b680273da8f3ca07e5eca1dd684b0906d6132a476741a80729d7f0ac596de525b4e48a7a97cc5ca67bfc38806e9209ac1c6cf031d68c1
|
|
7
|
+
data.tar.gz: 66588d6713351e17e2777fcf08f2eb65aa06c9d67dc6329dcacd119dfa3d41c8a57b7fe0875863a9e2a1c4a792f0b4142f61c849ec26add1f6951250d6c3e685
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
# Hanami::Assets
|
|
2
2
|
Assets management for Ruby web applications
|
|
3
3
|
|
|
4
|
+
## v1.3.5 - 2021-01-14
|
|
5
|
+
### Added
|
|
6
|
+
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
|
7
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.7
|
|
8
|
+
|
|
9
|
+
## v1.3.4 - 2019-10-11
|
|
10
|
+
### Fixed
|
|
11
|
+
- [unleashy] Precompile assets using binary mode to ensure compatibility with Windows
|
|
12
|
+
|
|
13
|
+
## v1.3.3 - 2019-09-13
|
|
14
|
+
### Fixed
|
|
15
|
+
- [Landon Grindheim] Lazily load `sassc` only when required
|
|
16
|
+
- [Landon Grindheim] Ensure assets precompilation to not crash when SASS stylesheet doesn't have dependencies
|
|
17
|
+
|
|
18
|
+
## v1.3.2 - 2019-08-02
|
|
19
|
+
### Added
|
|
20
|
+
- [Landon Grindheim & Sean Collins] Added support for `sassc` gem, because `sass` is no longer maintained
|
|
21
|
+
|
|
22
|
+
## v1.3.1 - 2019-01-18
|
|
23
|
+
### Added
|
|
24
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.6
|
|
25
|
+
- [Luca Guidi] Support `bundler` 2.0+
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- [Luca Guidi] Make optional nested assets feature to maintain backward compatibility with `1.2.x`
|
|
29
|
+
|
|
4
30
|
## v1.3.0 - 2018-10-24
|
|
5
31
|
|
|
6
32
|
## v1.3.0.beta1 - 2018-08-08
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
|
@@ -5,8 +5,7 @@ Assets management for Ruby web projects
|
|
|
5
5
|
## Status
|
|
6
6
|
|
|
7
7
|
[](https://badge.fury.io/rb/hanami-assets)
|
|
8
|
-
[](https://circleci.com/gh/hanami/assets/tree/master)
|
|
8
|
+
[](https://github.com/hanami/assets/actions?query=workflow%3Aci+branch%3Amaster)
|
|
10
9
|
[](https://codecov.io/gh/hanami/assets)
|
|
11
10
|
[](https://depfu.com/github/hanami/assets?project=Bundler)
|
|
12
11
|
[](http://inch-ci.org/github/hanami/assets)
|
|
@@ -15,7 +14,7 @@ Assets management for Ruby web projects
|
|
|
15
14
|
|
|
16
15
|
* Home page: http://hanamirb.org
|
|
17
16
|
* Community: http://hanamirb.org/community
|
|
18
|
-
* Guides:
|
|
17
|
+
* Guides: https://guides.hanamirb.org
|
|
19
18
|
* Mailing List: http://hanamirb.org/mailing-list
|
|
20
19
|
* API Doc: http://rdoc.info/gems/hanami-assets
|
|
21
20
|
* Bugs/Issues: https://github.com/hanami/assets/issues
|
|
@@ -200,7 +199,7 @@ handling: `.css` for stylesheets.
|
|
|
200
199
|
The second one is optional and it's for a preprocessor: `.scss` for Sass.
|
|
201
200
|
|
|
202
201
|
```ruby
|
|
203
|
-
require '
|
|
202
|
+
require 'sassc'
|
|
204
203
|
require 'hanami/assets'
|
|
205
204
|
|
|
206
205
|
Hanami::Assets.configure do
|
|
@@ -353,7 +352,7 @@ Hanami can use the following compressors (aka minifiers) for stylesheets.
|
|
|
353
352
|
|
|
354
353
|
* `:builtin` - Ruby based compressor. It doesn't require any external gem. It's fast, but not an efficient compressor.
|
|
355
354
|
* `:yui` - [YUI Compressor](http://yui.github.io/yuicompressor), it depends on [`yui-compressor`](https://rubygems.org/gems/yui-compressor) gem and it requires Java 1.4+
|
|
356
|
-
* `:sass` - [Sass](http://sass-lang.com/), it depends on [`
|
|
355
|
+
* `:sass` - [Sass](http://sass-lang.com/), it depends on [`sassc`](https://rubygems.org/gems/sassc) gem
|
|
357
356
|
|
|
358
357
|
```ruby
|
|
359
358
|
Hanami::Assets.configure do
|
|
@@ -437,6 +436,28 @@ From now on, helpers will return the absolute URL for the asset, hosted on the C
|
|
|
437
436
|
<script src="https://123.cloudfront.net/assets/application-d1829dc353b734e3adc24855693b70f9.js" type="text/javascript"></script>
|
|
438
437
|
```
|
|
439
438
|
|
|
439
|
+
## Standalone mode
|
|
440
|
+
|
|
441
|
+
If you're using `hanami-assets` without `hanami`, you must explicitly boot the framework with:
|
|
442
|
+
|
|
443
|
+
```ruby
|
|
444
|
+
Hanami::Assets.configure do
|
|
445
|
+
# ...
|
|
446
|
+
end.load!
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
or
|
|
450
|
+
|
|
451
|
+
```ruby
|
|
452
|
+
Hanami::Assets.configure do
|
|
453
|
+
# ...
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
# ...
|
|
457
|
+
|
|
458
|
+
Hanami::Assets.load!
|
|
459
|
+
```
|
|
460
|
+
|
|
440
461
|
## Third party gems
|
|
441
462
|
|
|
442
463
|
Developers can maintain gems that distribute assets for Hanami. For instance `hanami-ember` or `hanami-jquery`.
|
|
@@ -472,6 +493,6 @@ __Hanami::Assets__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
|
472
493
|
|
|
473
494
|
## Copyright
|
|
474
495
|
|
|
475
|
-
Copyright © 2014-
|
|
496
|
+
Copyright © 2014-2021 Luca Guidi – Released under MIT License
|
|
476
497
|
|
|
477
498
|
This project was formerly known as Lotus (`lotus-assets`).
|
data/bin/hanami-assets
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "pathname"
|
|
5
6
|
|
|
6
7
|
options = {}
|
|
7
8
|
OptionParser.new do |opts|
|
|
8
|
-
opts.banner =
|
|
9
|
+
opts.banner = "Usage: hanami-assets --config=path/to/config.rb"
|
|
9
10
|
|
|
10
|
-
opts.on(
|
|
11
|
+
opts.on("-c", "--config FILE", "Path to config") do |c|
|
|
11
12
|
options[:config] = c
|
|
12
13
|
end
|
|
13
14
|
end.parse!
|
|
14
15
|
|
|
15
|
-
config = options.fetch(:config) { raise ArgumentError.new(
|
|
16
|
+
config = options.fetch(:config) { raise ArgumentError.new("You must specify a configuration file") }
|
|
16
17
|
config = Pathname.new(config)
|
|
17
18
|
config.exist? or raise ArgumentError.new("Cannot find configuration file: #{config}")
|
|
18
19
|
|
|
19
|
-
require
|
|
20
|
+
require "hanami/assets"
|
|
20
21
|
load config
|
|
21
22
|
|
|
22
23
|
Hanami::Assets.deploy
|
data/hanami-assets.gemspec
CHANGED
|
@@ -24,15 +24,17 @@ Gem::Specification.new do |spec|
|
|
|
24
24
|
spec.add_runtime_dependency 'hanami-helpers', '~> 1.3'
|
|
25
25
|
spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.2'
|
|
26
26
|
|
|
27
|
-
spec.add_development_dependency 'bundler'
|
|
27
|
+
spec.add_development_dependency 'bundler', '>= 1.6', '< 3'
|
|
28
28
|
spec.add_development_dependency 'rake', '~> 12.0'
|
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
|
30
30
|
|
|
31
31
|
spec.add_development_dependency 'yui-compressor', '~> 0.12'
|
|
32
32
|
spec.add_development_dependency 'uglifier', '~> 2.7'
|
|
33
33
|
spec.add_development_dependency 'closure-compiler', '~> 1.1'
|
|
34
|
-
spec.add_development_dependency '
|
|
34
|
+
spec.add_development_dependency 'sassc', '~> 2.0'
|
|
35
35
|
|
|
36
36
|
spec.add_development_dependency 'coffee-script', '~> 2.3'
|
|
37
37
|
spec.add_development_dependency 'babel-transpiler', '~> 0.7'
|
|
38
|
+
|
|
39
|
+
spec.add_development_dependency 'rubocop', '0.81'
|
|
38
40
|
end
|
data/lib/hanami/assets.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hanami/utils/class_attribute"
|
|
2
4
|
|
|
3
5
|
# Hanami
|
|
4
6
|
#
|
|
@@ -16,10 +18,10 @@ module Hanami
|
|
|
16
18
|
class Error < ::StandardError
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
require
|
|
20
|
-
require
|
|
21
|
-
require
|
|
22
|
-
require
|
|
21
|
+
require "hanami/assets/version"
|
|
22
|
+
require "hanami/assets/configuration"
|
|
23
|
+
require "hanami/assets/config/global_sources"
|
|
24
|
+
require "hanami/assets/helpers"
|
|
23
25
|
|
|
24
26
|
include Utils::ClassAttribute
|
|
25
27
|
|
|
@@ -48,8 +50,8 @@ module Hanami
|
|
|
48
50
|
#
|
|
49
51
|
# @since 0.1.0
|
|
50
52
|
def self.deploy
|
|
51
|
-
require
|
|
52
|
-
require
|
|
53
|
+
require "hanami/assets/precompiler"
|
|
54
|
+
require "hanami/assets/bundler"
|
|
53
55
|
|
|
54
56
|
Precompiler.new(configuration, duplicates).run
|
|
55
57
|
Bundler.new(configuration, duplicates).run
|
|
@@ -59,8 +61,8 @@ module Hanami
|
|
|
59
61
|
#
|
|
60
62
|
# @since 0.4.0
|
|
61
63
|
def self.precompile(configurations)
|
|
62
|
-
require
|
|
63
|
-
require
|
|
64
|
+
require "hanami/assets/precompiler"
|
|
65
|
+
require "hanami/assets/bundler"
|
|
64
66
|
|
|
65
67
|
Precompiler.new(configuration, configurations).run
|
|
66
68
|
Bundler.new(configuration, configurations).run
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
require 'json'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
require "hanami/assets/bundler/compressor"
|
|
7
|
+
require "hanami/assets/bundler/asset"
|
|
8
|
+
require "hanami/assets/bundler/manifest_entry"
|
|
7
9
|
|
|
8
10
|
module Hanami
|
|
9
11
|
module Assets
|
|
@@ -18,11 +20,11 @@ module Hanami
|
|
|
18
20
|
|
|
19
21
|
# @since 0.1.0
|
|
20
22
|
# @api private
|
|
21
|
-
URL_SEPARATOR =
|
|
23
|
+
URL_SEPARATOR = "/"
|
|
22
24
|
|
|
23
25
|
# @since 0.1.0
|
|
24
26
|
# @api private
|
|
25
|
-
URL_REPLACEMENT =
|
|
27
|
+
URL_REPLACEMENT = ""
|
|
26
28
|
|
|
27
29
|
# Return a new instance
|
|
28
30
|
#
|
|
@@ -105,7 +107,7 @@ module Hanami
|
|
|
105
107
|
# @api private
|
|
106
108
|
def _convert_to_url(path)
|
|
107
109
|
path.sub(public_directory.to_s, URL_REPLACEMENT)
|
|
108
|
-
|
|
110
|
+
.gsub(File::SEPARATOR, URL_SEPARATOR)
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
# @since 0.1.0
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "openssl"
|
|
2
4
|
|
|
3
5
|
module Hanami
|
|
4
6
|
module Assets
|
|
@@ -20,7 +22,7 @@ module Hanami
|
|
|
20
22
|
|
|
21
23
|
# @since 0.3.0
|
|
22
24
|
# @api private
|
|
23
|
-
WILDCARD_EXT =
|
|
25
|
+
WILDCARD_EXT = ".*"
|
|
24
26
|
|
|
25
27
|
# Return a new instance
|
|
26
28
|
#
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Hanami
|
|
2
4
|
module Assets
|
|
3
5
|
class Bundler
|
|
@@ -8,11 +10,11 @@ module Hanami
|
|
|
8
10
|
class Compressor
|
|
9
11
|
# @since 0.3.0
|
|
10
12
|
# @api private
|
|
11
|
-
JAVASCRIPT_EXT =
|
|
13
|
+
JAVASCRIPT_EXT = ".js"
|
|
12
14
|
|
|
13
15
|
# @since 0.3.0
|
|
14
16
|
# @api private
|
|
15
|
-
STYLESHEET_EXT =
|
|
17
|
+
STYLESHEET_EXT = ".css"
|
|
16
18
|
|
|
17
19
|
# Return a new instance
|
|
18
20
|
#
|
|
@@ -39,19 +41,19 @@ module Hanami
|
|
|
39
41
|
# @since 0.3.0
|
|
40
42
|
# @api private
|
|
41
43
|
def compressor(type)
|
|
42
|
-
@configuration.__send__(:"#{
|
|
44
|
+
@configuration.__send__(:"#{type}_compressor")
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
# @since 0.3.0
|
|
46
48
|
# @api private
|
|
47
49
|
def _compress(compressor)
|
|
48
50
|
compressor.compress(@path)
|
|
49
|
-
rescue =>
|
|
51
|
+
rescue => exception # rubocop:disable Style/RescueStandardError
|
|
50
52
|
warn(
|
|
51
53
|
[
|
|
52
54
|
"Skipping compression of: `#{@path}'",
|
|
53
|
-
"Reason: #{
|
|
54
|
-
"\t#{
|
|
55
|
+
"Reason: #{exception}\n",
|
|
56
|
+
"\t#{exception.backtrace.join("\n\t")}\n\n"
|
|
55
57
|
].join("\n")
|
|
56
58
|
)
|
|
57
59
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Hanami
|
|
2
4
|
module Assets
|
|
3
5
|
class Bundler
|
|
@@ -8,7 +10,7 @@ module Hanami
|
|
|
8
10
|
class ManifestEntry
|
|
9
11
|
# @since 0.3.0
|
|
10
12
|
# @api private
|
|
11
|
-
SUBRESOURCE_INTEGRITY_SEPARATOR =
|
|
13
|
+
SUBRESOURCE_INTEGRITY_SEPARATOR = "-"
|
|
12
14
|
|
|
13
15
|
# Return a new instance
|
|
14
16
|
#
|
|
@@ -22,7 +24,7 @@ module Hanami
|
|
|
22
24
|
# @since 0.3.0
|
|
23
25
|
# @api private
|
|
24
26
|
def entry
|
|
25
|
-
{
|
|
27
|
+
{name => values}
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
private
|
|
@@ -38,7 +40,7 @@ module Hanami
|
|
|
38
40
|
def values
|
|
39
41
|
Hash[
|
|
40
42
|
target: _convert_to_url(@asset.expanded_fingerprinted_target),
|
|
41
|
-
sri:
|
|
43
|
+
sri: subresource_integrity_values
|
|
42
44
|
]
|
|
43
45
|
end
|
|
44
46
|
|
|
@@ -54,7 +56,7 @@ module Hanami
|
|
|
54
56
|
# @api private
|
|
55
57
|
def _convert_to_url(path)
|
|
56
58
|
path.sub(@asset.configuration.public_directory.to_s, URL_REPLACEMENT)
|
|
57
|
-
|
|
59
|
+
.gsub(File::SEPARATOR, URL_SEPARATOR)
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
end
|
data/lib/hanami/assets/cache.rb
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "set"
|
|
4
|
+
require "find"
|
|
5
|
+
require "hanami/utils/class_attribute"
|
|
4
6
|
|
|
5
7
|
module Hanami
|
|
6
8
|
module Assets
|
|
7
9
|
# Missing Asset error
|
|
8
10
|
class MissingAsset < Error
|
|
9
11
|
def initialize(name, sources)
|
|
10
|
-
sources = sources.map(&:to_s).join(
|
|
12
|
+
sources = sources.map(&:to_s).join(", ")
|
|
11
13
|
super("Missing asset: `#{name}' (sources: #{sources})")
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -28,18 +30,18 @@ module Hanami
|
|
|
28
30
|
#
|
|
29
31
|
# @since 0.1.0
|
|
30
32
|
# @api private
|
|
31
|
-
class Compiler
|
|
33
|
+
class Compiler
|
|
32
34
|
# @since 0.1.0
|
|
33
35
|
# @api private
|
|
34
36
|
DEFAULT_PERMISSIONS = 0o644
|
|
35
37
|
|
|
36
38
|
# @since 0.1.0
|
|
37
39
|
# @api private
|
|
38
|
-
COMPILE_PATTERN =
|
|
40
|
+
COMPILE_PATTERN = "*.*.*" # Example hello.js.es6
|
|
39
41
|
|
|
40
42
|
# @since 0.1.0
|
|
41
43
|
# @api private
|
|
42
|
-
EXTENSIONS = {
|
|
44
|
+
EXTENSIONS = {".js" => true, ".css" => true, ".map" => true}.freeze
|
|
43
45
|
|
|
44
46
|
include Utils::ClassAttribute
|
|
45
47
|
|
|
@@ -67,10 +69,10 @@ module Hanami
|
|
|
67
69
|
def self.compile(configuration, name)
|
|
68
70
|
return unless configuration.compile
|
|
69
71
|
|
|
70
|
-
require
|
|
71
|
-
require
|
|
72
|
-
require
|
|
73
|
-
require
|
|
72
|
+
require "tilt"
|
|
73
|
+
require "hanami/assets/cache"
|
|
74
|
+
require "hanami/assets/compilers/sass"
|
|
75
|
+
require "hanami/assets/compilers/less"
|
|
74
76
|
fabricate(configuration, name).compile
|
|
75
77
|
end
|
|
76
78
|
|
|
@@ -177,11 +179,10 @@ module Hanami
|
|
|
177
179
|
relative_destination_name(name: Pathname.new(result), add_prefix: false)
|
|
178
180
|
end
|
|
179
181
|
|
|
180
|
-
# @since
|
|
182
|
+
# @since 1.3.0
|
|
181
183
|
# @api private
|
|
182
184
|
def destination_name
|
|
183
|
-
result =
|
|
184
|
-
result = result.to_s
|
|
185
|
+
result = destination_path
|
|
185
186
|
|
|
186
187
|
if compile?
|
|
187
188
|
result.scan(/\A[[[:alnum:]][\-\_]]*\.[[\w]]*/).first || result
|
|
@@ -190,6 +191,16 @@ module Hanami
|
|
|
190
191
|
end
|
|
191
192
|
end
|
|
192
193
|
|
|
194
|
+
# @since 1.3.1
|
|
195
|
+
# @api private
|
|
196
|
+
def destination_path
|
|
197
|
+
if @configuration.nested
|
|
198
|
+
@name.relative? ? relative_destination_name : absolute_destination_name
|
|
199
|
+
else
|
|
200
|
+
::File.basename(@name)
|
|
201
|
+
end.to_s
|
|
202
|
+
end
|
|
203
|
+
|
|
193
204
|
# @since 0.1.0
|
|
194
205
|
# @api private
|
|
195
206
|
def exist?
|
|
@@ -222,7 +233,7 @@ module Hanami
|
|
|
222
233
|
# @since 0.1.0
|
|
223
234
|
# @api private
|
|
224
235
|
def copy!
|
|
225
|
-
write { source.
|
|
236
|
+
write { source.binread }
|
|
226
237
|
end
|
|
227
238
|
|
|
228
239
|
# @since 0.1.0
|
|
@@ -235,7 +246,7 @@ module Hanami
|
|
|
235
246
|
# @api private
|
|
236
247
|
def write
|
|
237
248
|
destination.dirname.mkpath
|
|
238
|
-
destination.open(File::WRONLY | File::TRUNC | File::CREAT, DEFAULT_PERMISSIONS) do |file|
|
|
249
|
+
destination.open(File::WRONLY | File::TRUNC | File::CREAT | File::BINARY, DEFAULT_PERMISSIONS) do |file|
|
|
239
250
|
file.write(yield)
|
|
240
251
|
end
|
|
241
252
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Hanami
|
|
2
4
|
module Assets
|
|
3
5
|
module Compilers
|
|
@@ -8,7 +10,7 @@ module Hanami
|
|
|
8
10
|
class Less < Compiler
|
|
9
11
|
# @since 0.3.0
|
|
10
12
|
# @api private
|
|
11
|
-
EXTENSIONS = /\.(less)\z
|
|
13
|
+
EXTENSIONS = /\.(less)\z/.freeze
|
|
12
14
|
|
|
13
15
|
# @since 0.3.0
|
|
14
16
|
# @api private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Hanami
|
|
2
4
|
module Assets
|
|
3
5
|
module Compilers
|
|
@@ -8,12 +10,7 @@ module Hanami
|
|
|
8
10
|
class Sass < Compiler
|
|
9
11
|
# @since 0.3.0
|
|
10
12
|
# @api private
|
|
11
|
-
EXTENSIONS = /\.(sass|scss)\z
|
|
12
|
-
|
|
13
|
-
# @since 0.1.0
|
|
14
|
-
# @api private
|
|
15
|
-
CACHE_LOCATION = Pathname(Hanami.respond_to?(:root) ? # rubocop:disable Style/MultilineTernaryOperator
|
|
16
|
-
Hanami.root : Dir.pwd).join('tmp', 'sass-cache')
|
|
13
|
+
EXTENSIONS = /\.(sass|scss)\z/.freeze
|
|
17
14
|
|
|
18
15
|
# @since 0.3.0
|
|
19
16
|
# @api private
|
|
@@ -21,24 +18,42 @@ module Hanami
|
|
|
21
18
|
name.to_s =~ EXTENSIONS
|
|
22
19
|
end
|
|
23
20
|
|
|
21
|
+
# @since 1.3.3
|
|
22
|
+
# @api private
|
|
23
|
+
def initialize(*)
|
|
24
|
+
super
|
|
25
|
+
require "sassc"
|
|
26
|
+
end
|
|
27
|
+
|
|
24
28
|
private
|
|
25
29
|
|
|
26
30
|
# @since 0.3.0
|
|
27
31
|
# @api private
|
|
28
32
|
def renderer
|
|
29
|
-
|
|
33
|
+
@renderer ||=
|
|
34
|
+
::SassC::Engine.new(
|
|
35
|
+
source.read,
|
|
36
|
+
syntax: target_syntax,
|
|
37
|
+
load_paths: load_paths
|
|
38
|
+
)
|
|
30
39
|
end
|
|
31
40
|
|
|
32
41
|
# @since 0.3.0
|
|
33
42
|
# @api private
|
|
34
43
|
def dependencies
|
|
35
|
-
|
|
44
|
+
renderer.dependencies.map(&:filename)
|
|
45
|
+
rescue source::NotRenderedError
|
|
46
|
+
[]
|
|
36
47
|
end
|
|
37
48
|
|
|
38
|
-
# @since
|
|
49
|
+
# @since 1.3.2
|
|
39
50
|
# @api private
|
|
40
|
-
def
|
|
41
|
-
|
|
51
|
+
def target_syntax
|
|
52
|
+
if source.extname =~ /sass\z/.freeze
|
|
53
|
+
:sass
|
|
54
|
+
else
|
|
55
|
+
:scss
|
|
56
|
+
end
|
|
42
57
|
end
|
|
43
58
|
end
|
|
44
59
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
require 'hanami/assets/compressors/stylesheet'
|
|
2
|
-
require 'sass'
|
|
3
2
|
|
|
4
3
|
module Hanami
|
|
5
4
|
module Assets
|
|
6
5
|
module Compressors
|
|
7
6
|
# Sass compressor for stylesheet
|
|
8
7
|
#
|
|
9
|
-
# It depends on <tt>
|
|
8
|
+
# It depends on <tt>sassc</tt> gem.
|
|
10
9
|
#
|
|
11
10
|
# @since 0.1.0
|
|
12
11
|
# @api private
|
|
@@ -16,21 +15,20 @@ module Hanami
|
|
|
16
15
|
class SassStylesheet < Stylesheet
|
|
17
16
|
# @since 0.1.0
|
|
18
17
|
# @api private
|
|
19
|
-
#
|
|
20
|
-
# FIXME This is the same logic that we have for Hanami::Assets::Compiler
|
|
21
|
-
SASS_CACHE_LOCATION = Pathname(Hanami.respond_to?(:root) ? # rubocop:disable Style/MultilineTernaryOperator
|
|
22
|
-
Hanami.root : Dir.pwd).join('tmp', 'sass-cache')
|
|
23
|
-
# @since 0.1.0
|
|
24
|
-
# @api private
|
|
25
18
|
def initialize
|
|
26
|
-
|
|
19
|
+
require 'sassc'
|
|
20
|
+
@compressor = ::SassC::Engine
|
|
27
21
|
end
|
|
28
22
|
|
|
29
23
|
# @since 0.1.0
|
|
30
24
|
# @api private
|
|
31
25
|
def compress(filename)
|
|
32
|
-
compressor.new(
|
|
33
|
-
|
|
26
|
+
compressor.new(
|
|
27
|
+
read(filename),
|
|
28
|
+
filename: filename,
|
|
29
|
+
syntax: :scss,
|
|
30
|
+
style: :compressed
|
|
31
|
+
).render
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hanami/utils/load_paths"
|
|
2
4
|
|
|
3
5
|
module Hanami
|
|
4
6
|
module Assets
|
|
@@ -27,7 +29,7 @@ module Hanami
|
|
|
27
29
|
|
|
28
30
|
# @since 0.1.0
|
|
29
31
|
# @api private
|
|
30
|
-
|
|
32
|
+
alias_method :<<, :push
|
|
31
33
|
|
|
32
34
|
private
|
|
33
35
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Hanami
|
|
2
4
|
module Assets
|
|
3
5
|
# This error is raised when the application starts but can't be load the
|
|
@@ -83,11 +85,11 @@ module Hanami
|
|
|
83
85
|
class Manifest
|
|
84
86
|
# @since 0.4.0
|
|
85
87
|
# @api private
|
|
86
|
-
TARGET =
|
|
88
|
+
TARGET = "target"
|
|
87
89
|
|
|
88
90
|
# @since 0.3.0
|
|
89
91
|
# @api private
|
|
90
|
-
SUBRESOURCE_INTEGRITY =
|
|
92
|
+
SUBRESOURCE_INTEGRITY = "sri"
|
|
91
93
|
|
|
92
94
|
# Return a new instance
|
|
93
95
|
#
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hanami/utils/load_paths"
|
|
4
|
+
require "hanami/utils/file_list"
|
|
3
5
|
|
|
4
6
|
module Hanami
|
|
5
7
|
module Assets
|
|
@@ -20,7 +22,7 @@ module Hanami
|
|
|
20
22
|
class Sources < Utils::LoadPaths
|
|
21
23
|
# @since 0.3.0
|
|
22
24
|
# @api private
|
|
23
|
-
SKIPPED_FILE_PREFIX =
|
|
25
|
+
SKIPPED_FILE_PREFIX = "_"
|
|
24
26
|
|
|
25
27
|
# @since 0.1.0
|
|
26
28
|
# @api private
|
|
@@ -1,61 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pathname"
|
|
4
|
+
require "json"
|
|
5
|
+
require "hanami/utils/string"
|
|
6
|
+
require "hanami/utils/class"
|
|
7
|
+
require "hanami/utils/path_prefix"
|
|
8
|
+
require "hanami/utils/basic_object"
|
|
9
|
+
require "hanami/assets/config/manifest"
|
|
10
|
+
require "hanami/assets/config/sources"
|
|
9
11
|
|
|
10
12
|
module Hanami
|
|
11
13
|
module Assets
|
|
12
14
|
# Framework configuration
|
|
13
15
|
#
|
|
14
16
|
# @since 0.1.0
|
|
15
|
-
class Configuration
|
|
17
|
+
class Configuration
|
|
16
18
|
# @since 0.1.0
|
|
17
19
|
# @api private
|
|
18
|
-
DEFAULT_SCHEME =
|
|
20
|
+
DEFAULT_SCHEME = "http"
|
|
19
21
|
|
|
20
22
|
# @since 0.1.0
|
|
21
23
|
# @api private
|
|
22
|
-
DEFAULT_HOST =
|
|
24
|
+
DEFAULT_HOST = "localhost"
|
|
23
25
|
|
|
24
26
|
# @since 0.1.0
|
|
25
27
|
# @api private
|
|
26
|
-
DEFAULT_PORT =
|
|
28
|
+
DEFAULT_PORT = "2300"
|
|
27
29
|
|
|
28
30
|
# @since 0.1.0
|
|
29
31
|
# @api private
|
|
30
|
-
DEFAULT_PUBLIC_DIRECTORY =
|
|
32
|
+
DEFAULT_PUBLIC_DIRECTORY = "public"
|
|
31
33
|
|
|
32
34
|
# @since 0.1.0
|
|
33
35
|
# @api private
|
|
34
|
-
DEFAULT_MANIFEST =
|
|
36
|
+
DEFAULT_MANIFEST = "assets.json"
|
|
35
37
|
|
|
36
38
|
# @since 0.1.0
|
|
37
39
|
# @api private
|
|
38
|
-
DEFAULT_PREFIX =
|
|
40
|
+
DEFAULT_PREFIX = "/assets"
|
|
39
41
|
|
|
40
42
|
# @since 0.1.0
|
|
41
43
|
# @api private
|
|
42
|
-
URL_SEPARATOR =
|
|
44
|
+
URL_SEPARATOR = "/"
|
|
43
45
|
|
|
44
46
|
# @since 0.1.0
|
|
45
47
|
# @api private
|
|
46
|
-
HTTP_SCHEME =
|
|
48
|
+
HTTP_SCHEME = "http"
|
|
47
49
|
|
|
48
50
|
# @since 0.1.0
|
|
49
51
|
# @api private
|
|
50
|
-
HTTP_PORT =
|
|
52
|
+
HTTP_PORT = "80"
|
|
51
53
|
|
|
52
54
|
# @since 0.1.0
|
|
53
55
|
# @api private
|
|
54
|
-
HTTPS_SCHEME =
|
|
56
|
+
HTTPS_SCHEME = "https"
|
|
55
57
|
|
|
56
58
|
# @since 0.1.0
|
|
57
59
|
# @api private
|
|
58
|
-
HTTPS_PORT =
|
|
60
|
+
HTTPS_PORT = "443"
|
|
59
61
|
|
|
60
62
|
# @since 0.3.0
|
|
61
63
|
# @api private
|
|
@@ -63,7 +65,7 @@ module Hanami
|
|
|
63
65
|
|
|
64
66
|
# @since 0.3.0
|
|
65
67
|
# @api private
|
|
66
|
-
SUBRESOURCE_INTEGRITY_SEPARATOR =
|
|
68
|
+
SUBRESOURCE_INTEGRITY_SEPARATOR = " "
|
|
67
69
|
|
|
68
70
|
# Return a copy of the configuration of the framework instance associated
|
|
69
71
|
# with the given class.
|
|
@@ -80,9 +82,10 @@ module Hanami
|
|
|
80
82
|
# @since 0.1.0
|
|
81
83
|
# @api private
|
|
82
84
|
def self.for(base)
|
|
83
|
-
# TODO: this implementation is similar to Hanami::Controller::Configuration
|
|
85
|
+
# TODO: this implementation is similar to Hanami::Controller::Configuration
|
|
86
|
+
# consider to extract it into Hanami::Utils
|
|
84
87
|
namespace = Utils::String.namespace(base)
|
|
85
|
-
framework = Utils::Class.load("#{namespace}::Assets") || Utils::Class.load!(
|
|
88
|
+
framework = Utils::Class.load("#{namespace}::Assets") || Utils::Class.load!("Hanami::Assets")
|
|
86
89
|
framework.configuration
|
|
87
90
|
end
|
|
88
91
|
|
|
@@ -129,6 +132,17 @@ module Hanami
|
|
|
129
132
|
end
|
|
130
133
|
end
|
|
131
134
|
|
|
135
|
+
# Support for nested path
|
|
136
|
+
#
|
|
137
|
+
# @since 1.3.1
|
|
138
|
+
def nested(value = nil)
|
|
139
|
+
if value.nil?
|
|
140
|
+
@nested
|
|
141
|
+
else
|
|
142
|
+
@nested = !!value
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
132
146
|
# Subresource integrity mode
|
|
133
147
|
#
|
|
134
148
|
# Determine if the helpers should generate the integrity attribute for an
|
|
@@ -155,7 +169,7 @@ module Hanami
|
|
|
155
169
|
if value.nil?
|
|
156
170
|
@cdn
|
|
157
171
|
else
|
|
158
|
-
@cdn = !!value
|
|
172
|
+
@cdn = !!value
|
|
159
173
|
end
|
|
160
174
|
end
|
|
161
175
|
|
|
@@ -172,7 +186,8 @@ module Hanami
|
|
|
172
186
|
# * <tt>:builtin</tt> - Ruby based implementation of jsmin. It doesn't require any external gem.
|
|
173
187
|
# * <tt>:yui</tt> - YUI Compressor, it depends on <tt>yui-compressor</tt> gem and it requires Java 1.4+
|
|
174
188
|
# * <tt>:uglifier</tt> - UglifyJS, it depends on <tt>uglifier</tt> gem and it requires Node.js
|
|
175
|
-
# * <tt>:closure</tt> - Google Closure Compiler, it depends on <tt>closure-compiler</tt> gem
|
|
189
|
+
# * <tt>:closure</tt> - Google Closure Compiler, it depends on <tt>closure-compiler</tt> gem
|
|
190
|
+
# and it requires Java
|
|
176
191
|
#
|
|
177
192
|
# @param value [Symbol,#compress] the compressor
|
|
178
193
|
#
|
|
@@ -220,9 +235,10 @@ module Hanami
|
|
|
220
235
|
#
|
|
221
236
|
# The following symbols are accepted:
|
|
222
237
|
#
|
|
223
|
-
# * <tt>:builtin</tt> - Ruby based compressor. It doesn't require any external gem.
|
|
238
|
+
# * <tt>:builtin</tt> - Ruby based compressor. It doesn't require any external gem.
|
|
239
|
+
# It's fast, but not an efficient compressor.
|
|
224
240
|
# * <tt>:yui</tt> - YUI-Compressor, it depends on <tt>yui-compressor</tt> gem and requires Java 1.4+
|
|
225
|
-
# * <tt>:sass</tt> - Sass, it depends on <tt>
|
|
241
|
+
# * <tt>:sass</tt> - Sass, it depends on <tt>sassc</tt> gem
|
|
226
242
|
#
|
|
227
243
|
# @param value [Symbol,#compress] the compressor
|
|
228
244
|
#
|
|
@@ -232,7 +248,7 @@ module Hanami
|
|
|
232
248
|
# @see https://rubygems.org/gems/yui-compressor
|
|
233
249
|
#
|
|
234
250
|
# @see http://sass-lang.com
|
|
235
|
-
# @see https://rubygems.org/gems/
|
|
251
|
+
# @see https://rubygems.org/gems/sassc
|
|
236
252
|
#
|
|
237
253
|
# @example YUI Compressor
|
|
238
254
|
# require 'hanami/assets'
|
|
@@ -473,7 +489,7 @@ module Hanami
|
|
|
473
489
|
# @see Hanami::Assets::Configuration#javascript_compressor
|
|
474
490
|
# @see Hanami::Assets::Compressors::Javascript#for
|
|
475
491
|
def js_compressor
|
|
476
|
-
require
|
|
492
|
+
require "hanami/assets/compressors/javascript"
|
|
477
493
|
Hanami::Assets::Compressors::Javascript.for(javascript_compressor)
|
|
478
494
|
end
|
|
479
495
|
|
|
@@ -490,13 +506,13 @@ module Hanami
|
|
|
490
506
|
# @see Hanami::Assets::Configuration#stylesheet_compressor
|
|
491
507
|
# @see Hanami::Assets::Compressors::Stylesheet#for
|
|
492
508
|
def css_compressor
|
|
493
|
-
require
|
|
509
|
+
require "hanami/assets/compressors/stylesheet"
|
|
494
510
|
Hanami::Assets::Compressors::Stylesheet.for(stylesheet_compressor)
|
|
495
511
|
end
|
|
496
512
|
|
|
497
513
|
# @since 0.1.0
|
|
498
514
|
# @api private
|
|
499
|
-
def duplicate
|
|
515
|
+
def duplicate
|
|
500
516
|
Configuration.new.tap do |c|
|
|
501
517
|
c.root = root
|
|
502
518
|
c.scheme = scheme
|
|
@@ -506,6 +522,7 @@ module Hanami
|
|
|
506
522
|
c.subresource_integrity = subresource_integrity
|
|
507
523
|
c.cdn = cdn
|
|
508
524
|
c.compile = compile
|
|
525
|
+
c.nested = nested
|
|
509
526
|
c.public_directory = public_directory
|
|
510
527
|
c.manifest = manifest
|
|
511
528
|
c.sources = sources.dup
|
|
@@ -516,7 +533,7 @@ module Hanami
|
|
|
516
533
|
|
|
517
534
|
# @since 0.1.0
|
|
518
535
|
# @api private
|
|
519
|
-
def reset!
|
|
536
|
+
def reset!
|
|
520
537
|
@scheme = DEFAULT_SCHEME
|
|
521
538
|
@host = DEFAULT_HOST
|
|
522
539
|
@port = DEFAULT_PORT
|
|
@@ -526,6 +543,7 @@ module Hanami
|
|
|
526
543
|
@cdn = false
|
|
527
544
|
@fingerprint = false
|
|
528
545
|
@compile = false
|
|
546
|
+
@nested = false
|
|
529
547
|
@base_url = nil
|
|
530
548
|
@destination_directory = nil
|
|
531
549
|
@public_manifest = Config::NullManifest.new(self)
|
|
@@ -569,6 +587,10 @@ module Hanami
|
|
|
569
587
|
# @api private
|
|
570
588
|
attr_writer :compile
|
|
571
589
|
|
|
590
|
+
# @since 1.3.1
|
|
591
|
+
# @api private
|
|
592
|
+
attr_writer :nested
|
|
593
|
+
|
|
572
594
|
# @since 0.1.0
|
|
573
595
|
# @api private
|
|
574
596
|
attr_writer :scheme
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
require "hanami/helpers/html_helper"
|
|
5
|
+
require "hanami/utils/escape"
|
|
4
6
|
|
|
5
7
|
module Hanami
|
|
6
8
|
module Assets
|
|
@@ -13,51 +15,50 @@ module Hanami
|
|
|
13
15
|
# @see http://www.rubydoc.info/gems/hanami-helpers/Hanami/Helpers/HtmlHelper
|
|
14
16
|
#
|
|
15
17
|
# rubocop:disable Metrics/ModuleLength
|
|
16
|
-
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
17
18
|
module Helpers
|
|
18
19
|
# @since 0.1.0
|
|
19
20
|
# @api private
|
|
20
|
-
NEW_LINE_SEPARATOR = "\n"
|
|
21
|
+
NEW_LINE_SEPARATOR = "\n"
|
|
21
22
|
|
|
22
23
|
# @since 0.1.0
|
|
23
24
|
# @api private
|
|
24
|
-
WILDCARD_EXT =
|
|
25
|
+
WILDCARD_EXT = ".*"
|
|
25
26
|
|
|
26
27
|
# @since 0.1.0
|
|
27
28
|
# @api private
|
|
28
|
-
JAVASCRIPT_EXT =
|
|
29
|
+
JAVASCRIPT_EXT = ".js"
|
|
29
30
|
|
|
30
31
|
# @since 0.1.0
|
|
31
32
|
# @api private
|
|
32
|
-
STYLESHEET_EXT =
|
|
33
|
+
STYLESHEET_EXT = ".css"
|
|
33
34
|
|
|
34
35
|
# @since 0.1.0
|
|
35
36
|
# @api private
|
|
36
|
-
JAVASCRIPT_MIME_TYPE =
|
|
37
|
+
JAVASCRIPT_MIME_TYPE = "text/javascript"
|
|
37
38
|
|
|
38
39
|
# @since 0.1.0
|
|
39
40
|
# @api private
|
|
40
|
-
STYLESHEET_MIME_TYPE =
|
|
41
|
+
STYLESHEET_MIME_TYPE = "text/css"
|
|
41
42
|
|
|
42
43
|
# @since 0.1.0
|
|
43
44
|
# @api private
|
|
44
|
-
FAVICON_MIME_TYPE =
|
|
45
|
+
FAVICON_MIME_TYPE = "image/x-icon"
|
|
45
46
|
|
|
46
47
|
# @since 0.1.0
|
|
47
48
|
# @api private
|
|
48
|
-
STYLESHEET_REL =
|
|
49
|
+
STYLESHEET_REL = "stylesheet"
|
|
49
50
|
|
|
50
51
|
# @since 0.1.0
|
|
51
52
|
# @api private
|
|
52
|
-
FAVICON_REL =
|
|
53
|
+
FAVICON_REL = "shortcut icon"
|
|
53
54
|
|
|
54
55
|
# @since 0.1.0
|
|
55
56
|
# @api private
|
|
56
|
-
DEFAULT_FAVICON =
|
|
57
|
+
DEFAULT_FAVICON = "favicon.ico"
|
|
57
58
|
|
|
58
59
|
# @since 0.3.0
|
|
59
60
|
# @api private
|
|
60
|
-
CROSSORIGIN_ANONYMOUS =
|
|
61
|
+
CROSSORIGIN_ANONYMOUS = "anonymous"
|
|
61
62
|
|
|
62
63
|
# @since 0.3.0
|
|
63
64
|
# @api private
|
|
@@ -65,7 +66,7 @@ module Hanami
|
|
|
65
66
|
|
|
66
67
|
# @since 1.1.0
|
|
67
68
|
# @api private
|
|
68
|
-
QUERY_STRING_MATCHER =
|
|
69
|
+
QUERY_STRING_MATCHER = /\?/.freeze
|
|
69
70
|
|
|
70
71
|
include Hanami::Helpers::HtmlHelper
|
|
71
72
|
|
|
@@ -140,13 +141,15 @@ module Hanami
|
|
|
140
141
|
#
|
|
141
142
|
# <%= javascript 'application' %>
|
|
142
143
|
#
|
|
143
|
-
# # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
|
|
144
|
+
# # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
|
|
145
|
+
# # type="text/javascript" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
|
|
144
146
|
#
|
|
145
147
|
# @example Subresource Integrity for 3rd Party Scripts
|
|
146
148
|
#
|
|
147
149
|
# <%= javascript 'https://example.com/assets/example.js', integrity: 'sha384-oqVu...Y8wC' %>
|
|
148
150
|
#
|
|
149
|
-
# # <script src="https://example.com/assets/example.js" type="text/javascript"
|
|
151
|
+
# # <script src="https://example.com/assets/example.js" type="text/javascript"
|
|
152
|
+
# # integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
|
|
150
153
|
#
|
|
151
154
|
# @example Deferred Execution
|
|
152
155
|
#
|
|
@@ -170,18 +173,19 @@ module Hanami
|
|
|
170
173
|
#
|
|
171
174
|
# <%= javascript 'application' %>
|
|
172
175
|
#
|
|
173
|
-
# # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
|
|
176
|
+
# # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
|
|
177
|
+
# # type="text/javascript"></script>
|
|
174
178
|
#
|
|
175
179
|
# @example Disable Push Promise/Early Hints
|
|
176
180
|
#
|
|
177
181
|
# <%= javascript 'application', push: false %>
|
|
178
182
|
# <%= javascript 'http://cdn.example.test/jquery.js', 'dashboard', push: false %>
|
|
179
|
-
def javascript(*sources, push: true, **options)
|
|
183
|
+
def javascript(*sources, push: true, **options)
|
|
180
184
|
options = options.reject { |k, _| k.to_sym == :src }
|
|
181
185
|
|
|
182
186
|
_safe_tags(*sources) do |source|
|
|
183
187
|
attributes = {
|
|
184
|
-
src:
|
|
188
|
+
src: _typed_asset_path(source, JAVASCRIPT_EXT, push: push, as: :script),
|
|
185
189
|
type: JAVASCRIPT_MIME_TYPE
|
|
186
190
|
}
|
|
187
191
|
attributes.merge!(options)
|
|
@@ -247,19 +251,22 @@ module Hanami
|
|
|
247
251
|
#
|
|
248
252
|
# <%= stylesheet 'application' %>
|
|
249
253
|
#
|
|
250
|
-
# # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
|
|
254
|
+
# # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
|
|
255
|
+
# # type="text/css" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
|
|
251
256
|
#
|
|
252
257
|
# @example Subresource Integrity for 3rd Party Assets
|
|
253
258
|
#
|
|
254
259
|
# <%= stylesheet 'https://example.com/assets/example.css', integrity: 'sha384-oqVu...Y8wC' %>
|
|
255
260
|
#
|
|
256
|
-
# # <link href="https://example.com/assets/example.css"
|
|
261
|
+
# # <link href="https://example.com/assets/example.css"
|
|
262
|
+
# # type="text/css" rel="stylesheet" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
|
|
257
263
|
#
|
|
258
264
|
# @example Absolute URL
|
|
259
265
|
#
|
|
260
266
|
# <%= stylesheet 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' %>
|
|
261
267
|
#
|
|
262
|
-
# # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
|
|
268
|
+
# # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
|
|
269
|
+
# # type="text/css" rel="stylesheet">
|
|
263
270
|
#
|
|
264
271
|
# @example Fingerprint Mode
|
|
265
272
|
#
|
|
@@ -271,20 +278,21 @@ module Hanami
|
|
|
271
278
|
#
|
|
272
279
|
# <%= stylesheet 'application' %>
|
|
273
280
|
#
|
|
274
|
-
# # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
|
|
281
|
+
# # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
|
|
282
|
+
# # type="text/css" rel="stylesheet">
|
|
275
283
|
#
|
|
276
284
|
# @example Disable Push Promise/Early Hints
|
|
277
285
|
#
|
|
278
286
|
# <%= stylesheet 'application', push: false %>
|
|
279
287
|
# <%= stylesheet 'http://cdn.example.test/bootstrap.css', 'dashboard', push: false %>
|
|
280
|
-
def stylesheet(*sources, push: true, **options)
|
|
288
|
+
def stylesheet(*sources, push: true, **options)
|
|
281
289
|
options = options.reject { |k, _| k.to_sym == :href }
|
|
282
290
|
|
|
283
291
|
_safe_tags(*sources) do |source|
|
|
284
292
|
attributes = {
|
|
285
293
|
href: _typed_asset_path(source, STYLESHEET_EXT, push: push, as: :style),
|
|
286
294
|
type: STYLESHEET_MIME_TYPE,
|
|
287
|
-
rel:
|
|
295
|
+
rel: STYLESHEET_REL
|
|
288
296
|
}
|
|
289
297
|
attributes.merge!(options)
|
|
290
298
|
|
|
@@ -435,7 +443,8 @@ module Hanami
|
|
|
435
443
|
#
|
|
436
444
|
# <%= favicon %>
|
|
437
445
|
#
|
|
438
|
-
# # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico"
|
|
446
|
+
# # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico"
|
|
447
|
+
# rel="shortcut icon" type="image/x-icon">
|
|
439
448
|
#
|
|
440
449
|
# @example Enable Push Promise/Early Hints
|
|
441
450
|
#
|
|
@@ -445,7 +454,7 @@ module Hanami
|
|
|
445
454
|
|
|
446
455
|
attributes = {
|
|
447
456
|
href: asset_path(source, push: options.delete(:push) || false, as: :image),
|
|
448
|
-
rel:
|
|
457
|
+
rel: FAVICON_REL,
|
|
449
458
|
type: FAVICON_MIME_TYPE
|
|
450
459
|
}
|
|
451
460
|
attributes.merge!(options)
|
|
@@ -863,7 +872,7 @@ module Hanami
|
|
|
863
872
|
|
|
864
873
|
# @api private
|
|
865
874
|
def _subresource_integrity?
|
|
866
|
-
!!self.class.assets_configuration.subresource_integrity
|
|
875
|
+
!!self.class.assets_configuration.subresource_integrity
|
|
867
876
|
end
|
|
868
877
|
|
|
869
878
|
# @api private
|
|
@@ -910,7 +919,7 @@ module Hanami
|
|
|
910
919
|
end
|
|
911
920
|
|
|
912
921
|
if !options[:src] && !block_given?
|
|
913
|
-
raise ArgumentError.new(
|
|
922
|
+
raise ArgumentError.new("You should provide a source via `src` option or with a `source` HTML tag")
|
|
914
923
|
end
|
|
915
924
|
|
|
916
925
|
options
|
|
@@ -920,7 +929,7 @@ module Hanami
|
|
|
920
929
|
# @api private
|
|
921
930
|
def _push_promise(url, as: nil)
|
|
922
931
|
Thread.current[:__hanami_assets] ||= {}
|
|
923
|
-
Thread.current[:__hanami_assets][url.to_s] = {
|
|
932
|
+
Thread.current[:__hanami_assets][url.to_s] = {as: as, crossorigin: _crossorigin?(url)}
|
|
924
933
|
|
|
925
934
|
url
|
|
926
935
|
end
|
|
@@ -931,7 +940,6 @@ module Hanami
|
|
|
931
940
|
source !~ QUERY_STRING_MATCHER && source !~ /#{Regexp.escape(ext)}\z/
|
|
932
941
|
end
|
|
933
942
|
end
|
|
934
|
-
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
935
943
|
# rubocop:enable Metrics/ModuleLength
|
|
936
944
|
end
|
|
937
945
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "hanami/assets/compiler"
|
|
3
5
|
|
|
4
6
|
module Hanami
|
|
5
7
|
module Assets
|
|
@@ -48,18 +50,18 @@ module Hanami
|
|
|
48
50
|
# @api private
|
|
49
51
|
def clear_manifest(manifest)
|
|
50
52
|
JSON.parse(manifest).each_value do |asset_hash|
|
|
51
|
-
asset_file_name = @configuration.public_directory.join(asset_hash[
|
|
53
|
+
asset_file_name = @configuration.public_directory.join(asset_hash["target"])
|
|
52
54
|
asset_file_name.unlink if asset_file_name.exist?
|
|
53
55
|
end
|
|
54
56
|
rescue JSON::ParserError
|
|
55
|
-
warn
|
|
57
|
+
warn "Non JSON manifest found and unlinked."
|
|
56
58
|
ensure
|
|
57
59
|
manifest.unlink
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
# @since 0.1.0
|
|
61
63
|
# @api private
|
|
62
|
-
def precompile
|
|
64
|
+
def precompile
|
|
63
65
|
applications.each do |duplicate|
|
|
64
66
|
config = if duplicate.respond_to?(:configuration)
|
|
65
67
|
duplicate.configuration
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hanami-assets
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luca Guidi
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: hanami-utils
|
|
@@ -64,14 +64,20 @@ dependencies:
|
|
|
64
64
|
requirements:
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '
|
|
67
|
+
version: '1.6'
|
|
68
|
+
- - "<"
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '3'
|
|
68
71
|
type: :development
|
|
69
72
|
prerelease: false
|
|
70
73
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
74
|
requirements:
|
|
72
75
|
- - ">="
|
|
73
76
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '
|
|
77
|
+
version: '1.6'
|
|
78
|
+
- - "<"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '3'
|
|
75
81
|
- !ruby/object:Gem::Dependency
|
|
76
82
|
name: rake
|
|
77
83
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -143,19 +149,19 @@ dependencies:
|
|
|
143
149
|
- !ruby/object:Gem::Version
|
|
144
150
|
version: '1.1'
|
|
145
151
|
- !ruby/object:Gem::Dependency
|
|
146
|
-
name:
|
|
152
|
+
name: sassc
|
|
147
153
|
requirement: !ruby/object:Gem::Requirement
|
|
148
154
|
requirements:
|
|
149
155
|
- - "~>"
|
|
150
156
|
- !ruby/object:Gem::Version
|
|
151
|
-
version: '
|
|
157
|
+
version: '2.0'
|
|
152
158
|
type: :development
|
|
153
159
|
prerelease: false
|
|
154
160
|
version_requirements: !ruby/object:Gem::Requirement
|
|
155
161
|
requirements:
|
|
156
162
|
- - "~>"
|
|
157
163
|
- !ruby/object:Gem::Version
|
|
158
|
-
version: '
|
|
164
|
+
version: '2.0'
|
|
159
165
|
- !ruby/object:Gem::Dependency
|
|
160
166
|
name: coffee-script
|
|
161
167
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -184,6 +190,20 @@ dependencies:
|
|
|
184
190
|
- - "~>"
|
|
185
191
|
- !ruby/object:Gem::Version
|
|
186
192
|
version: '0.7'
|
|
193
|
+
- !ruby/object:Gem::Dependency
|
|
194
|
+
name: rubocop
|
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
|
196
|
+
requirements:
|
|
197
|
+
- - '='
|
|
198
|
+
- !ruby/object:Gem::Version
|
|
199
|
+
version: '0.81'
|
|
200
|
+
type: :development
|
|
201
|
+
prerelease: false
|
|
202
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
203
|
+
requirements:
|
|
204
|
+
- - '='
|
|
205
|
+
- !ruby/object:Gem::Version
|
|
206
|
+
version: '0.81'
|
|
187
207
|
description: Assets management for Ruby web applications
|
|
188
208
|
email:
|
|
189
209
|
- me@lucaguidi.com
|
|
@@ -229,7 +249,7 @@ homepage: http://hanamirb.org
|
|
|
229
249
|
licenses:
|
|
230
250
|
- MIT
|
|
231
251
|
metadata: {}
|
|
232
|
-
post_install_message:
|
|
252
|
+
post_install_message:
|
|
233
253
|
rdoc_options: []
|
|
234
254
|
require_paths:
|
|
235
255
|
- lib
|
|
@@ -244,9 +264,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
244
264
|
- !ruby/object:Gem::Version
|
|
245
265
|
version: '0'
|
|
246
266
|
requirements: []
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
signing_key:
|
|
267
|
+
rubygems_version: 3.2.4
|
|
268
|
+
signing_key:
|
|
250
269
|
specification_version: 4
|
|
251
270
|
summary: Assets management
|
|
252
271
|
test_files: []
|