hanami-assets 2.1.0.rc1 → 2.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c63f686712b26848bd0d228c8d16a17ff9c38096360dcd86b901fe9db7acde91
4
- data.tar.gz: f85ca3433bcec2d6003c770924e5f9d01713a8e35c5b5af13e93bc8c0741645b
3
+ metadata.gz: 71f6b2236cb6f96e86f9bbf25453b179685db554ef87faa5c64a09457aaefea3
4
+ data.tar.gz: 513533d8e23d48cc02dbaad76188724c934ddc4bf51bcd31b706fa61ef611a35
5
5
  SHA512:
6
- metadata.gz: 270ec0aad2e026303ffaa9e52d0d218b3cd1566e07d698dd6787eed98fc99d9526e81829f9e719594926f659956191cb7a323f6f21e897016d54b5e8b4f7a5b2
7
- data.tar.gz: aa83f4b50a3c763d7b3f3ec6e0817e9a0bcdc60ab5206cc856e02465394b6eb270f568dc38bba0a095897343979258aa04c94a0122eb92e9c681759b52b690ee
6
+ metadata.gz: b47ce4c26181b7f0bb21ec64522162fd212ba33ab9284bdbfafd7c8b96bb983ca90a220266f1a5608dd0b990ca4ed40dd0a130445aab6de60f824ca018423347
7
+ data.tar.gz: 4df3a64885b684132af03c206ae224ad1f3855180aac4b6f15fb323dba8199f5195a4a0c5f6123854427888e96ff2b3201d037a6035b5a396b5561f9c2a5d26a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Hanami::Assets
2
2
  Assets management for Ruby web applications
3
3
 
4
+ ## v2.1.0.rc2 - 2023-11-08
5
+
4
6
  ## v2.1.0.rc1 - 2023-11-01
5
7
 
6
8
  ## 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
- <%= 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
 
@@ -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 ( 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,51 +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
20
+ # @!attribute [rw] package_manager_run_command
21
+ # @return [String]
22
+ #
23
+ # @api public
24
+ # @since 2.1.0
21
25
  setting :package_manager_run_command, default: "npm run --silent"
22
26
 
23
- # @since 2.1.0
24
- # @api private
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
- # @since 2.1.0
28
- # @api private
29
- setting :destination
30
-
31
- # @since 2.1.0
32
- # @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
33
42
  setting :subresource_integrity, default: []
34
43
 
35
- # @since 2.1.0
36
- # @api private
37
- setting :sources, default: [], constructor: -> v { Array(v).flatten }
38
-
39
- # @since 2.1.0
40
- # @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
41
52
  setting :base_url, constructor: -> url { BaseUrl.new(url.to_s) }
42
53
 
43
- # @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
54
+ # @!attribute [rw] manifest_path
55
+ # @return [String, nil]
56
+ #
57
+ # @api public
58
+ # @since 2.1.0
49
59
  setting :manifest_path
50
60
 
61
+ # @api public
51
62
  # @since 2.1.0
52
- # @api private
53
63
  def initialize(**values)
54
64
  super()
55
65
 
@@ -58,29 +68,24 @@ module Hanami
58
68
  yield(config) if block_given?
59
69
  end
60
70
 
61
- # @since 2.1.0
62
- # @api private
63
- def entry_points
64
- sources.map do |source|
65
- Dir.glob(File.join(source, "**", config.entry_points_pattern))
66
- end.flatten
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.
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]
71
77
  #
72
78
  # @see https://en.wikipedia.org/wiki/Same-origin_policy#Origin_determination_rules
73
79
  # @see https://en.wikipedia.org/wiki/Same-origin_policy#document.domain_property
74
80
  #
75
- # @since 1.2.0
76
81
  # @api private
82
+ # @since 1.2.0
77
83
  def crossorigin?(source)
78
84
  base_url.crossorigin?(source)
79
85
  end
80
86
 
81
87
  private
82
88
 
83
- # @api private
84
89
  def method_missing(name, ...)
85
90
  if config.respond_to?(name)
86
91
  config.public_send(name, ...)
@@ -89,7 +94,6 @@ module Hanami
89
94
  end
90
95
  end
91
96
 
92
- # @api private
93
97
  def respond_to_missing?(name, _incude_all = false)
94
98
  config.respond_to?(name) || super
95
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.rc1"
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.rc1
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-11-01 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