bankrupt 2.1.1 → 2.1.2

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: 1409314669d3b6ac7f02a307d69bebaa0f179ba5d6a6990ceec82f3335cdba7e
4
- data.tar.gz: 38847aa1a145f910d54761a799bdb22a8472a2608848909e8bcc4843db8c8387
3
+ metadata.gz: 4a9d75977ce24ba0712d558d3ab5003c1877e5f2099af75911788f3f0ef7fd53
4
+ data.tar.gz: 7996990b475cc9cca5df4aade17e7a2815bab0ab85edb6d76fd3083f4cfef4d3
5
5
  SHA512:
6
- metadata.gz: 511f7aa62155396cb3aeba42c919ab07dd1bff771c26acc0de87d088cb19c7bb89119f08a42c3b073055a36656585795ba7a0c6ec41b8fa99ce0edd17db7b0d7
7
- data.tar.gz: 2cf717e16d200124b1f5957cfd27a8ff144dacde64fe4c8f6a775b44b19cf426fc312ba680fef4c3e9ed1f181367b637bb5b043ecf7b867445904bbcf0fb4793
6
+ metadata.gz: 15dd67b22ac708a464dfce8b95214661bb1fc90dc10e7ad4199aa685582cd9a5acf48f19ff8459494e19cdc7f3ec79b7de00bb3a3c346ba509e753e19a4ffcd6
7
+ data.tar.gz: 2af9d31bfcc234aa2e845b0a34b9fc718f71f86af0361356c0e088a0410f58136952dc7d18ac8ab2e34336b9e82cbc8ea3654d6b1b929ce462571a37fbc755e4
@@ -7,13 +7,16 @@ AllCops:
7
7
  Layout/ExtraSpacing:
8
8
  AllowForAlignment: false
9
9
 
10
+ Metrics/AbcSize:
11
+ Max: 20
12
+
10
13
  Metrics/BlockLength:
11
14
  Max: 100
12
15
  Exclude:
13
16
  - 'spec/**/*_spec.rb'
14
17
 
15
18
  Metrics/MethodLength:
16
- Max: 15
19
+ Max: 20
17
20
 
18
21
  RSpec/DescribeClass:
19
22
  Exclude:
@@ -3,6 +3,10 @@
3
3
  This file keeps track of changes between releases for the bankrupt project
4
4
  which adheres to [semantic versioning](https://semver.org).
5
5
 
6
+ ## v2.1.2 2020-01-20
7
+
8
+ Take options into account to ensure unique asset lookups.
9
+
6
10
  ## v2.1.1 2020-01-09
7
11
 
8
12
  Ensure that the `purge` task works with hashless assets.
data/README.md CHANGED
@@ -170,3 +170,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
170
  See the License for the specific language governing permissions and
171
171
  limitations under the License.
172
172
  ```
173
+
174
+ TODO: tests to ensure the lookups are separate
@@ -49,9 +49,6 @@ module Bankrupt
49
49
  #
50
50
  # @todo we compute the options on every call, we should do the
51
51
  # lookup first and short circuit
52
- # @todo lookup needs to be based on path _and_ options so that the
53
- # same asset can be used in multiple places with e.g. different
54
- # css classes applied
55
52
  #
56
53
  # @param path [String] relative (from public) path to the img
57
54
  # @param options [Hash] additional attributes to add to the img tag
@@ -60,7 +57,7 @@ module Bankrupt
60
57
  o = Hash(options).map { |k, v| "#{k}='#{v}'" }.join(' ')
61
58
 
62
59
  asset_html(path, [IMAGE_CDN.chomp, o].join(' '),
63
- [IMAGE_LOCAL.chomp, o].join(' '))
60
+ [IMAGE_LOCAL.chomp, o].join(' '), options)
64
61
  end
65
62
 
66
63
  # Return a javascript html tag for the asset.
@@ -95,9 +92,14 @@ module Bankrupt
95
92
  # Return a precomputed asset path if it exists
96
93
  #
97
94
  # @param path [String] asset on which to perform the lookup
95
+ # @params options [String] the options string to use in the lookup
98
96
  # @return [String] the rendered slim template with the asset in place
99
- def lookup(path)
100
- @_assets.fetch(path)
97
+ def lookup(path, options = nil)
98
+ if actual_options?(options)
99
+ @_assets.fetch([path, options].join('?'))
100
+ else
101
+ @_assets.fetch(path)
102
+ end
101
103
  rescue KeyError
102
104
  nil
103
105
  end
@@ -133,24 +135,56 @@ module Bankrupt
133
135
  # @param path [String] relative path to the asset
134
136
  # @param cdn [String] a slim template for generating a cdn asset
135
137
  # @param local [String] a slim template for generating a local asset
138
+ # @param options [String] options as a string to make unique lookups
136
139
  # @return [String] the asset html
137
- def asset_html(path, cdn, local)
138
- if (asset = lookup("/#{path}"))
140
+ def asset_html(path, cdn, local, options = nil)
141
+ opts = options_string(options)
142
+
143
+ if (asset = lookup("/#{path}", opts))
139
144
  return asset
140
145
  end
141
146
 
147
+ lookup_path = "/#{actual_options?(opts) ? [path, opts].join('?') : path}"
148
+
142
149
  begin
143
150
  details = ASSETS.fetch(path)
144
151
 
145
152
  fullpath = create_fullpath(path, details[:md5], details[:hashless])
146
153
 
147
- @_assets["/#{path}"] = Slim::Template.new { cdn }.render(
154
+ @_assets[lookup_path] = Slim::Template.new { cdn }.render(
148
155
  ASSET.new(fullpath, details[:sri])
149
156
  )
150
157
  rescue KeyError
151
- @_assets["/#{path}"] = Slim::Template.new { local }.render(
158
+ @_assets[lookup_path] = Slim::Template.new { local }.render(
152
159
  ASSET.new("/#{path}", nil)
153
160
  )
154
161
  end
155
162
  end
163
+
164
+ # Turn the options hash into a concatenated string for use in the lookup.
165
+ #
166
+ # @param options [Hash] the options has to convert
167
+ # @return [String] concatenated options suitable for use in lookups
168
+ def options_string(options)
169
+ return nil if Hash(options).size.zero?
170
+
171
+ options.map do |k, v|
172
+ [k.to_s, v.to_s].join
173
+ end.join.gsub(/[^A-Za-z0-9\-_]/, '')
174
+ end
175
+
176
+ # Determine if we actually have options regardless if input is a string,
177
+ # hash, or nil.
178
+ #
179
+ # @param options [String, Hash] options to check
180
+ # @return [Boolean] true if there are options, false otherwise
181
+ def actual_options?(options)
182
+ return false if options.nil?
183
+
184
+ if (options.is_a?(String) || options.is_a?(Hash)) && !options.size.zero?
185
+ true
186
+ else
187
+ false
188
+ end
189
+ end
156
190
  end
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Bankrupt
18
- VERSION = '2.1.1'
18
+ VERSION = '2.1.2'
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankrupt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Finelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim