hanami-assets 2.1.0.rc1 → 2.1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +13 -22
- data/lib/hanami/assets/base_url.rb +0 -5
- data/lib/hanami/assets/config.rb +38 -41
- data/lib/hanami/assets/errors.rb +4 -12
- data/lib/hanami/assets/version.rb +1 -1
- data/lib/hanami/assets.rb +33 -16
- metadata +6 -8
- data/bin/hanami-assets +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 524bcdefad223b559accd2e027f37b4a2b28af80ac8db368ece9c18d6676dcd6
|
4
|
+
data.tar.gz: 9baf4a521bbe0549503d2b79bb4ef38b0a65aeb141f2f9299c599edb7e78f2f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6203631c1b5a42cd593e35f37a2274803c0a651e3d81f479a2c5c4ffb60e1df781397b26d087a5d36fd71435222ba7770c9c83b5458d3be55ab52f578501190
|
7
|
+
data.tar.gz: 3ae4c5aceccd0062ce40c73fe259320074bf14300bcc5aebd5d290af5ff1bce7db086c9b37317bc1ac8bcce07c7b52c91bd28dd85d882c35e7a586529fd84fc4
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Hanami::Assets
|
2
2
|
Assets management for Ruby web applications
|
3
3
|
|
4
|
+
## v2.1.0.rc3 - 2024-02-16
|
5
|
+
### Changed
|
6
|
+
- [Tim Riley] Require a `root:` argument when initializing `Hanami::Assets`. This should be the directory containing the compiled assets and their `assets.json` manifest file.
|
7
|
+
- [Tim Riley] Removed `manifest_path` setting; the manifest path is no longer user-configurable.
|
8
|
+
- [Tim Riley] Replaced `package_manager_run_command` setting with `node_command` setting.
|
9
|
+
- [Tim Riley] Removed unused `sources`, `entry_point_patterns` and `destination` settings.
|
10
|
+
- [Tim Riley] Removed `bin/hanami-assets` executable.
|
11
|
+
|
12
|
+
## v2.1.0.rc2 - 2023-11-08
|
13
|
+
|
4
14
|
## v2.1.0.rc1 - 2023-11-01
|
5
15
|
|
6
16
|
## v2.1.0.beta2 - 2023-10-04
|
data/README.md
CHANGED
@@ -66,13 +66,13 @@ Given the following template:
|
|
66
66
|
<html>
|
67
67
|
<head>
|
68
68
|
<title>Assets example</title>
|
69
|
-
<%=
|
69
|
+
<%= stylesheet_tag "reset", "app" %>
|
70
70
|
</head>
|
71
71
|
|
72
72
|
<body>
|
73
73
|
<!-- ... -->
|
74
|
-
<%=
|
75
|
-
<%=
|
74
|
+
<%= javascript_tag "app" %>
|
75
|
+
<%= javascript_tag "https://cdn.somethirdparty.script/foo.js", async: true %>
|
76
76
|
</body>
|
77
77
|
</html>
|
78
78
|
```
|
@@ -98,15 +98,16 @@ It will output this markup:
|
|
98
98
|
|
99
99
|
### Available Helpers
|
100
100
|
|
101
|
-
|
101
|
+
The `hanami` gem ships with the following helpers for assets:
|
102
102
|
|
103
|
-
* `
|
104
|
-
* `
|
105
|
-
* `
|
106
|
-
* `
|
107
|
-
* `
|
108
|
-
* `
|
109
|
-
* `
|
103
|
+
* `asset_url`
|
104
|
+
* `javascript_tag`
|
105
|
+
* `stylesheet_tag`
|
106
|
+
* `favicon_tag`
|
107
|
+
* `image_tag`
|
108
|
+
* `video_tag`
|
109
|
+
* `audio_tag`
|
110
|
+
* `path_tag`
|
110
111
|
|
111
112
|
## App Structure
|
112
113
|
|
@@ -153,16 +154,6 @@ If you have a custom directory `app/assets/fonts`, all the fonts are copied to t
|
|
153
154
|
|
154
155
|
The destination directory is `public/assets`.
|
155
156
|
|
156
|
-
### Sources
|
157
|
-
|
158
|
-
Hanami Assets works with [Yarn](https://yarnpkg.com/).
|
159
|
-
|
160
|
-
In order to add/remove a source to your application, you should follow Yarn's dependencies management.
|
161
|
-
|
162
|
-
### Preprocessors
|
163
|
-
|
164
|
-
Hanami Assets is able to preprocess any kind of JavaScript and CSS flavor.
|
165
|
-
|
166
157
|
### Deployment
|
167
158
|
|
168
159
|
To process the assets during deployment run `bundle exec hanami assets compile`.
|
@@ -265,7 +256,7 @@ __Hanami::Assets__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
265
256
|
|
266
257
|
## Contributing
|
267
258
|
|
268
|
-
1. Fork it (
|
259
|
+
1. Fork it (https://github.com/hanami/assets/fork)
|
269
260
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
270
261
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
271
262
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/hanami/assets/config.rb
CHANGED
@@ -5,51 +5,54 @@ require_relative "base_url"
|
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
class Assets
|
8
|
-
#
|
8
|
+
# Hanami assets configuration.
|
9
9
|
#
|
10
|
+
# @api public
|
10
11
|
# @since 0.1.0
|
11
12
|
class Config
|
12
13
|
include Dry::Configurable
|
13
14
|
|
15
|
+
# @api public
|
14
16
|
# @since 2.1.0
|
15
|
-
# @api private
|
16
17
|
BASE_URL = ""
|
17
18
|
private_constant :BASE_URL
|
18
19
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
20
|
+
# @!attribute [rw] node_command
|
21
|
+
# @return [String]
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
# @since 2.1.0
|
25
|
+
setting :node_command, default: "node"
|
22
26
|
|
23
|
-
#
|
24
|
-
#
|
27
|
+
# @!attribute [rw] path_prefix
|
28
|
+
# @return [String]
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
# @since 2.1.0
|
25
32
|
setting :path_prefix, default: "/assets"
|
26
33
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
34
|
+
# @!attribute [rw] subresource_integrity
|
35
|
+
# @return [Array<Symbol>]
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# config.subresource_integrity # => [:sha256, :sha512]
|
39
|
+
#
|
40
|
+
# @api public
|
41
|
+
# @since 2.1.0
|
33
42
|
setting :subresource_integrity, default: []
|
34
43
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
#
|
40
|
-
#
|
44
|
+
# @!attribute [rw] base_url
|
45
|
+
# @return [BaseUrl]
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# config.base_url = "http://some-cdn.com/assets"
|
49
|
+
#
|
50
|
+
# @api public
|
51
|
+
# @since 2.1.0
|
41
52
|
setting :base_url, constructor: -> url { BaseUrl.new(url.to_s) }
|
42
53
|
|
54
|
+
# @api public
|
43
55
|
# @since 2.1.0
|
44
|
-
# @api private
|
45
|
-
setting :entry_points_pattern, default: "index.{js,jsx,ts,tsx}"
|
46
|
-
|
47
|
-
# @since 2.1.0
|
48
|
-
# @api private
|
49
|
-
setting :manifest_path
|
50
|
-
|
51
|
-
# @since 2.1.0
|
52
|
-
# @api private
|
53
56
|
def initialize(**values)
|
54
57
|
super()
|
55
58
|
|
@@ -58,29 +61,24 @@ module Hanami
|
|
58
61
|
yield(config) if block_given?
|
59
62
|
end
|
60
63
|
|
61
|
-
#
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
# Check if the given source is linked via Cross-Origin policy.
|
70
|
-
# In other words, the given source, doesn't satisfy the Same-Origin policy.
|
64
|
+
# Returns true if the given source is linked via Cross-Origin policy (or in other words, if
|
65
|
+
# the given source does not satisfy the Same-Origin policy).
|
66
|
+
#
|
67
|
+
# @param source [String]
|
68
|
+
#
|
69
|
+
# @return [Boolean]
|
71
70
|
#
|
72
71
|
# @see https://en.wikipedia.org/wiki/Same-origin_policy#Origin_determination_rules
|
73
72
|
# @see https://en.wikipedia.org/wiki/Same-origin_policy#document.domain_property
|
74
73
|
#
|
75
|
-
# @since 1.2.0
|
76
74
|
# @api private
|
75
|
+
# @since 1.2.0
|
77
76
|
def crossorigin?(source)
|
78
77
|
base_url.crossorigin?(source)
|
79
78
|
end
|
80
79
|
|
81
80
|
private
|
82
81
|
|
83
|
-
# @api private
|
84
82
|
def method_missing(name, ...)
|
85
83
|
if config.respond_to?(name)
|
86
84
|
config.public_send(name, ...)
|
@@ -89,7 +87,6 @@ module Hanami
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
# @api private
|
93
90
|
def respond_to_missing?(name, _incude_all = false)
|
94
91
|
config.respond_to?(name) || super
|
95
92
|
end
|
data/lib/hanami/assets/errors.rb
CHANGED
@@ -2,25 +2,17 @@
|
|
2
2
|
|
3
3
|
module Hanami
|
4
4
|
class Assets
|
5
|
-
# Base error for Hanami::Assets
|
6
|
-
#
|
7
|
-
# All the errors defined in this framework MUST inherit from it.
|
5
|
+
# Base error for Hanami::Assets.
|
8
6
|
#
|
7
|
+
# @api public
|
9
8
|
# @since 0.1.0
|
10
9
|
class Error < ::StandardError
|
11
10
|
end
|
12
11
|
|
13
|
-
# Error raised when assets config is not valid.
|
14
|
-
#
|
15
|
-
# @since 2.1.0
|
16
|
-
# @api public
|
17
|
-
class ConfigError < Error
|
18
|
-
end
|
19
|
-
|
20
12
|
# Error returned when the assets manifest file is missing.
|
21
13
|
#
|
22
|
-
# @since 2.1.0
|
23
14
|
# @api public
|
15
|
+
# @since 2.1.0
|
24
16
|
class ManifestMissingError < Error
|
25
17
|
def initialize(manifest_path)
|
26
18
|
super(<<~TEXT)
|
@@ -33,8 +25,8 @@ module Hanami
|
|
33
25
|
|
34
26
|
# Error raised when no asset can be found for a source path.
|
35
27
|
#
|
36
|
-
# @since 2.1.0
|
37
28
|
# @api public
|
29
|
+
# @since 2.1.0
|
38
30
|
class AssetMissingError < Error
|
39
31
|
def initialize(source_path)
|
40
32
|
super(<<~TEXT)
|
data/lib/hanami/assets.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
+
require "pathname"
|
4
5
|
require "zeitwerk"
|
5
6
|
|
6
|
-
# Hanami
|
7
|
-
#
|
8
|
-
# @since 0.1.0
|
9
7
|
module Hanami
|
10
8
|
# Assets management for Ruby web applications
|
11
9
|
#
|
@@ -31,21 +29,34 @@ module Hanami
|
|
31
29
|
require_relative "assets/version"
|
32
30
|
require_relative "assets/errors"
|
33
31
|
|
34
|
-
# @since 2.1.0
|
35
32
|
# @api private
|
36
|
-
|
37
|
-
|
33
|
+
# @since 2.1.0
|
34
|
+
MANIFEST_PATH = "assets.json"
|
35
|
+
private_constant :MANIFEST_PATH
|
38
36
|
|
37
|
+
# @api private
|
38
|
+
# @since 2.1.0
|
39
39
|
attr_reader :config
|
40
40
|
|
41
|
+
# @api private
|
41
42
|
# @since 2.1.0
|
43
|
+
attr_reader :root
|
44
|
+
|
42
45
|
# @api public
|
43
|
-
|
46
|
+
# @since 2.1.0
|
47
|
+
def initialize(config:, root:)
|
44
48
|
@config = config
|
49
|
+
@root = Pathname(root)
|
45
50
|
end
|
46
51
|
|
47
|
-
#
|
52
|
+
# Returns the asset at the given path.
|
53
|
+
#
|
54
|
+
# @return [Hanami::Assets::Asset] the asset
|
55
|
+
#
|
56
|
+
# @raise AssetMissingError if no asset can be found at the path
|
57
|
+
#
|
48
58
|
# @api public
|
59
|
+
# @since 2.1.0
|
49
60
|
def [](path)
|
50
61
|
asset_attrs = manifest
|
51
62
|
.fetch(path) { raise AssetMissingError.new(path) }
|
@@ -62,14 +73,22 @@ module Hanami
|
|
62
73
|
)
|
63
74
|
end
|
64
75
|
|
65
|
-
#
|
76
|
+
# Returns true if subresource integrity is configured.
|
77
|
+
#
|
78
|
+
# @return [Boolean]
|
79
|
+
#
|
66
80
|
# @api public
|
81
|
+
# @since 2.1.0
|
67
82
|
def subresource_integrity?
|
68
83
|
config.subresource_integrity.any?
|
69
84
|
end
|
70
85
|
|
71
|
-
#
|
86
|
+
# Returns true if the given source path is a cross-origin request.
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
89
|
+
#
|
72
90
|
# @api public
|
91
|
+
# @since 2.1.0
|
73
92
|
def crossorigin?(source_path)
|
74
93
|
config.crossorigin?(source_path)
|
75
94
|
end
|
@@ -79,15 +98,13 @@ module Hanami
|
|
79
98
|
def manifest
|
80
99
|
return @manifest if instance_variable_defined?(:@manifest)
|
81
100
|
|
82
|
-
|
83
|
-
raise ConfigError, "no manifest_path configured"
|
84
|
-
end
|
101
|
+
full_manifest_path = root.join(MANIFEST_PATH)
|
85
102
|
|
86
|
-
unless
|
87
|
-
raise ManifestMissingError.new(
|
103
|
+
unless full_manifest_path.exist?
|
104
|
+
raise ManifestMissingError.new(full_manifest_path.to_s)
|
88
105
|
end
|
89
106
|
|
90
|
-
@manifest = JSON.parse(File.read(
|
107
|
+
@manifest = JSON.parse(File.read(full_manifest_path))
|
91
108
|
end
|
92
109
|
end
|
93
110
|
end
|
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: 2.1.0.
|
4
|
+
version: 2.1.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -145,15 +145,13 @@ dependencies:
|
|
145
145
|
description: Assets management for Ruby web applications
|
146
146
|
email:
|
147
147
|
- me@lucaguidi.com
|
148
|
-
executables:
|
149
|
-
- hanami-assets
|
148
|
+
executables: []
|
150
149
|
extensions: []
|
151
150
|
extra_rdoc_files: []
|
152
151
|
files:
|
153
152
|
- CHANGELOG.md
|
154
153
|
- LICENSE.md
|
155
154
|
- README.md
|
156
|
-
- bin/hanami-assets
|
157
155
|
- hanami-assets.gemspec
|
158
156
|
- lib/hanami-assets.rb
|
159
157
|
- lib/hanami/assets.rb
|
@@ -178,11 +176,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
176
|
version: '3.0'
|
179
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
178
|
requirements:
|
181
|
-
- - "
|
179
|
+
- - ">="
|
182
180
|
- !ruby/object:Gem::Version
|
183
|
-
version:
|
181
|
+
version: '0'
|
184
182
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.5.6
|
186
184
|
signing_key:
|
187
185
|
specification_version: 4
|
188
186
|
summary: Assets management
|
data/bin/hanami-assets
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "optparse"
|
5
|
-
require "pathname"
|
6
|
-
|
7
|
-
options = {}
|
8
|
-
OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: hanami-assets --config=path/to/config.rb"
|
10
|
-
|
11
|
-
opts.on("-c", "--config FILE", "Path to config") do |c|
|
12
|
-
options[:config] = c
|
13
|
-
end
|
14
|
-
end.parse!
|
15
|
-
|
16
|
-
config = options.fetch(:config) { raise ArgumentError.new("You must specify a configuration file") }
|
17
|
-
config = Pathname.new(config)
|
18
|
-
config.exist? or raise ArgumentError.new("Cannot find configuration file: #{config}")
|
19
|
-
|
20
|
-
require "hanami/assets"
|
21
|
-
load config
|
22
|
-
|
23
|
-
Hanami::Assets.deploy
|