hanami-assets 2.1.0.beta2 → 2.1.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da6a6be342f7e3a9e3147c0583c3ad707a0173a3deab09e0d98e48b1cd12adb3
4
- data.tar.gz: ace54aa27a7f37393e94643bcf841c1b1a98260d69b83d0687e95aaef5fa5e5f
3
+ metadata.gz: 71f6b2236cb6f96e86f9bbf25453b179685db554ef87faa5c64a09457aaefea3
4
+ data.tar.gz: 513533d8e23d48cc02dbaad76188724c934ddc4bf51bcd31b706fa61ef611a35
5
5
  SHA512:
6
- metadata.gz: 98d2d451da096daa3e3ee398985c175de38cc7745ee46e037176ac689e0387611473eca736b79fcddfe4436456c693fcb99bf60f27a46226bc7d7e590f0d341d
7
- data.tar.gz: f540b8ed261fba7efcc2c0c48a1e5b5656f1a6fd9b69b403e2bc29d092cb9961760c34695c57df961f67983d175a32994dce192b699067a03623a24abfaa58e8
6
+ metadata.gz: b47ce4c26181b7f0bb21ec64522162fd212ba33ab9284bdbfafd7c8b96bb983ca90a220266f1a5608dd0b990ca4ed40dd0a130445aab6de60f824ca018423347
7
+ data.tar.gz: 4df3a64885b684132af03c206ae224ad1f3855180aac4b6f15fb323dba8199f5195a4a0c5f6123854427888e96ff2b3201d037a6035b5a396b5561f9c2a5d26a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Hanami::Assets
2
2
  Assets management for Ruby web applications
3
3
 
4
+ ## v2.1.0.rc2 - 2023-11-08
5
+
6
+ ## v2.1.0.rc1 - 2023-11-01
7
+
4
8
  ## v2.1.0.beta2 - 2023-10-04
5
9
  ### Added
6
10
  - [Luca Guidi] Official support for Ruby: Ruby 3.1, and 3.2
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
- <%= assets.css "reset", "app" %>
69
+ <%= stylesheet_tag "reset", "app" %>
70
70
  </head>
71
71
 
72
72
  <body>
73
73
  <!-- ... -->
74
- <%= assets.js "app" %>
75
- <%= assets.js "https://cdn.somethirdparty.script/foo.js", async: true %>
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
- This gem ships with the following helpers:
101
+ The `hanami` gem ships with the following helpers for assets:
102
102
 
103
- * `javascript` (aliased as `js`)
104
- * `stylesheet` (aliased as `css`)
105
- * `favicon`
106
- * `image` (aliased as `img`)
107
- * `video`
108
- * `audio`
109
- * `path`
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
 
@@ -118,9 +119,9 @@ Among other directories, it generates a specific structure for assets:
118
119
  $ tree app/assets
119
120
  ├── images
120
121
  │   └── favicon.ico
121
- ├── javascripts
122
+ ├── js
122
123
  │   └── app.ts
123
- └── stylesheets
124
+ └── css
124
125
     └── app.css
125
126
  ```
126
127
 
@@ -135,16 +136,16 @@ This process includes any kind of asset: other JavaScript files, stylesheets, im
135
136
 
136
137
  The default entry points are:
137
138
 
138
- * `app/assets/javascripts/app.ts`
139
- * `slices/[slice-name]/assets/javascripts/app.ts`
139
+ * `app/assets/js/app.ts`
140
+ * `slices/[slice-name]/assets/js/app.ts`
140
141
 
141
142
  You can specify custom Entry Points, by adding an `app.{js,ts,mjs,mts,tsx,jsx}` file into the assets directory of the app or a slice.
142
143
 
143
- An example is: `app/assets/javascripts/login/app.ts` to define a new Entry Point for a Login page where you want to have a more lightweight bundle.
144
+ An example is: `app/assets/js/login/app.ts` to define a new Entry Point for a Login page where you want to have a more lightweight bundle.
144
145
 
145
146
  #### Static Assets
146
147
 
147
- Except for `javascripts` and `stylesheets` directories, all the other directories are considered **static**.
148
+ Except for `js` and `css` directories, all the other directories are considered **static**.
148
149
  Their files will be copied as they are to the destination directory.
149
150
 
150
151
  If you have a custom directory `app/assets/fonts`, all the fonts are copied to the destination direcotry.
@@ -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`.
@@ -176,7 +167,7 @@ By doing so, you can safely cache and deliver updated versions of assets to clie
176
167
 
177
168
  During the deployment process, Hanami Assets appends to the file name a unique hash.
178
169
 
179
- Example: `app/assets/javascripts/app.ts` -> `public/assets/app-QECGTTYG.js`
170
+ Example: `app/assets/js/app.ts` -> `public/assets/app-QECGTTYG.js`
180
171
 
181
172
  It creates a `/public/assets.json` to map the original asset name to the fingerprint name.
182
173
 
@@ -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 ( https://github.com/hanami/assets/fork )
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`)
@@ -5,59 +5,61 @@ require_relative "base_url"
5
5
 
6
6
  module Hanami
7
7
  class Assets
8
- # Framework configuration
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
- # @since 2.1.0
20
- # @api private
21
- setting :package_manager_executable, default: "npm"
22
-
23
- # @since 2.1.0
24
- # @api private
25
- setting :package_manager_command, default: "exec"
26
-
27
- # @since 2.1.0
28
- # @api private
29
- setting :executable, default: "hanami-assets"
20
+ # @!attribute [rw] package_manager_run_command
21
+ # @return [String]
22
+ #
23
+ # @api public
24
+ # @since 2.1.0
25
+ setting :package_manager_run_command, default: "npm run --silent"
30
26
 
31
- # @since 2.1.0
32
- # @api private
27
+ # @!attribute [rw] path_prefix
28
+ # @return [String]
29
+ #
30
+ # @api public
31
+ # @since 2.1.0
33
32
  setting :path_prefix, default: "/assets"
34
33
 
35
- # @since 2.1.0
36
- # @api private
37
- setting :destination
38
-
39
- # @since 2.1.0
40
- # @api private
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
41
42
  setting :subresource_integrity, default: []
42
43
 
43
- # @since 2.1.0
44
- # @api private
45
- setting :sources, default: [], constructor: -> v { Array(v).flatten }
46
-
47
- # @since 2.1.0
48
- # @api private
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
49
52
  setting :base_url, constructor: -> url { BaseUrl.new(url.to_s) }
50
53
 
51
- # @since 2.1.0
52
- # @api private
53
- setting :entry_points_pattern, default: "index.{js,jsx,ts,tsx}"
54
-
55
- # @since 2.1.0
56
- # @api private
54
+ # @!attribute [rw] manifest_path
55
+ # @return [String, nil]
56
+ #
57
+ # @api public
58
+ # @since 2.1.0
57
59
  setting :manifest_path
58
60
 
61
+ # @api public
59
62
  # @since 2.1.0
60
- # @api private
61
63
  def initialize(**values)
62
64
  super()
63
65
 
@@ -66,29 +68,24 @@ module Hanami
66
68
  yield(config) if block_given?
67
69
  end
68
70
 
69
- # @since 2.1.0
70
- # @api private
71
- def entry_points
72
- sources.map do |source|
73
- Dir.glob(File.join(source, "**", config.entry_points_pattern))
74
- end.flatten
75
- end
76
-
77
- # Check if the given source is linked via Cross-Origin policy.
78
- # In other words, the given source, doesn't satisfy the Same-Origin policy.
71
+ # Returns true if the given source is linked via Cross-Origin policy (or in other words, if
72
+ # the given source does not satisfy the Same-Origin policy).
73
+ #
74
+ # @param source [String]
75
+ #
76
+ # @return [Boolean]
79
77
  #
80
78
  # @see https://en.wikipedia.org/wiki/Same-origin_policy#Origin_determination_rules
81
79
  # @see https://en.wikipedia.org/wiki/Same-origin_policy#document.domain_property
82
80
  #
83
- # @since 1.2.0
84
81
  # @api private
82
+ # @since 1.2.0
85
83
  def crossorigin?(source)
86
84
  base_url.crossorigin?(source)
87
85
  end
88
86
 
89
87
  private
90
88
 
91
- # @api private
92
89
  def method_missing(name, ...)
93
90
  if config.respond_to?(name)
94
91
  config.public_send(name, ...)
@@ -97,7 +94,6 @@ module Hanami
97
94
  end
98
95
  end
99
96
 
100
- # @api private
101
97
  def respond_to_missing?(name, _incude_all = false)
102
98
  config.respond_to?(name) || super
103
99
  end
@@ -2,25 +2,24 @@
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
12
  # Error raised when assets config is not valid.
14
13
  #
15
- # @since 2.1.0
16
14
  # @api public
15
+ # @since 2.1.0
17
16
  class ConfigError < Error
18
17
  end
19
18
 
20
19
  # Error returned when the assets manifest file is missing.
21
20
  #
22
- # @since 2.1.0
23
21
  # @api public
22
+ # @since 2.1.0
24
23
  class ManifestMissingError < Error
25
24
  def initialize(manifest_path)
26
25
  super(<<~TEXT)
@@ -33,8 +32,8 @@ module Hanami
33
32
 
34
33
  # Error raised when no asset can be found for a source path.
35
34
  #
36
- # @since 2.1.0
37
35
  # @api public
36
+ # @since 2.1.0
38
37
  class AssetMissingError < Error
39
38
  def initialize(source_path)
40
39
  super(<<~TEXT)
@@ -5,6 +5,6 @@ module Hanami
5
5
  # Defines the version
6
6
  #
7
7
  # @since 0.1.0
8
- VERSION = "2.1.0.beta2"
8
+ VERSION = "2.1.0.rc2"
9
9
  end
10
10
  end
data/lib/hanami/assets.rb CHANGED
@@ -3,9 +3,6 @@
3
3
  require "json"
4
4
  require "zeitwerk"
5
5
 
6
- # Hanami
7
- #
8
- # @since 0.1.0
9
6
  module Hanami
10
7
  # Assets management for Ruby web applications
11
8
  #
@@ -31,21 +28,29 @@ module Hanami
31
28
  require_relative "assets/version"
32
29
  require_relative "assets/errors"
33
30
 
34
- # @since 2.1.0
35
31
  # @api private
32
+ # @since 2.1.0
36
33
  SEPARATOR = "/"
37
34
  private_constant :SEPARATOR
38
35
 
36
+ # @api private
37
+ # @since 2.1.0
39
38
  attr_reader :config
40
39
 
41
- # @since 2.1.0
42
40
  # @api public
41
+ # @since 2.1.0
43
42
  def initialize(config:)
44
43
  @config = config
45
44
  end
46
45
 
47
- # @since 2.1.0
46
+ # Returns the asset at the given path.
47
+ #
48
+ # @return [Hanami::Assets::Asset] the asset
49
+ #
50
+ # @raise AssetMissingError if no asset can be found at the path
51
+ #
48
52
  # @api public
53
+ # @since 2.1.0
49
54
  def [](path)
50
55
  asset_attrs = manifest
51
56
  .fetch(path) { raise AssetMissingError.new(path) }
@@ -62,14 +67,22 @@ module Hanami
62
67
  )
63
68
  end
64
69
 
65
- # @since 2.1.0
70
+ # Returns true if subresource integrity is configured.
71
+ #
72
+ # @return [Boolean]
73
+ #
66
74
  # @api public
75
+ # @since 2.1.0
67
76
  def subresource_integrity?
68
77
  config.subresource_integrity.any?
69
78
  end
70
79
 
71
- # @since 2.1.0
80
+ # Returns true if the given source path is a cross-origin request.
81
+ #
82
+ # @return [Boolean]
83
+ #
72
84
  # @api public
85
+ # @since 2.1.0
73
86
  def crossorigin?(source_path)
74
87
  config.crossorigin?(source_path)
75
88
  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.beta2
4
+ version: 2.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-04 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: 1.3.1
184
184
  requirements: []
185
- rubygems_version: 3.4.13
185
+ rubygems_version: 3.4.21
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Assets management