howzit 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: 28505fefd411902ebd75d786f31e6967822aaff975dbb1f55bb13994e583b792
4
- data.tar.gz: 105e760d5595f4b8664969b6258240d17fb16ede995d3698e2d7bb4a36276824
3
+ metadata.gz: 23a304a27d457b410c8764ed0b83f0a00e2e6e9108ba3fd4a7bef722695d8607
4
+ data.tar.gz: 2041090127040e2315691750de2ee9ccaf3d770a7b8561d328f573e78e633a50
5
5
  SHA512:
6
- metadata.gz: 338ad20ebae27dc9d504671df84789be608fd73b123b1a7966ae5cd6c160c7543d21596df6c6b4268fb827f732d80f581d8cb15520f02b19cb27014f4903ff51
7
- data.tar.gz: 6283e6c567425ea667e399ca338ccdea86023157b9b58709d1f006fd94f8b71286eba18f6c170a25d2cae4bbc571f79b0a667936ec162967115b7cdb8b374684
6
+ metadata.gz: 8dda575709255dec600f6ba6f259c856b67ab91d9418fbcbc374f85a8eaa6a2842ac8a0b9bdd22a5eec9621e17353b6f2dfa7bc7b6f9b7de9d0c64006d5a27b1
7
+ data.tar.gz: 236c40bbd997c4bd956aa9796999771b965907add10b208929ba45a09c04679126177232dce1a5d29d15cec4ebfd09315b8bc274e588b0fccc02a938395731ef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 2.1.2
2
+
3
+ 2023-03-07 10:24
4
+
5
+ #### IMPROVED
6
+
7
+ - Merge metadata into named variables so they're also available as ${NAME}
8
+
1
9
  ### 2.1.1
2
10
 
3
11
  2023-03-07 09:47
data/lib/howzit/colors.rb CHANGED
@@ -227,7 +227,7 @@ module Howzit
227
227
  def template(input)
228
228
  input = input.join(' ') if input.is_a? Array
229
229
  fmt = input.gsub(/%/, '%%')
230
- fmt = fmt.gsub(/(?<!\\u)\{(\w+)\}/i) do
230
+ fmt = fmt.gsub(/(?<!\\u|\$)\{(\w+)\}/i) do
231
231
  Regexp.last_match(1).split('').map { |c| "%<#{c}>s" }.join('')
232
232
  end
233
233
 
@@ -242,25 +242,25 @@ module Howzit
242
242
  ##
243
243
  def render_arguments
244
244
  str = dup
245
- str.gsub!(/\$\{(?<name>[A-Z0-9_]+(?::.*?)?)\}/i) do |mtch|
245
+ str.render_named_placeholders
246
+ str.render_numeric_placeholders
247
+ Howzit.arguments.nil? ? str : str.gsub(/\$[@*]/, Shellwords.join(Howzit.arguments))
248
+ end
249
+
250
+ def render_named_placeholders
251
+ gsub!(/\$\{(?<name>[A-Z0-9_]+(?::.*?)?)\}/i) do
246
252
  m = Regexp.last_match
247
253
  arg, default = m['name'].split(/:/).map(&:strip)
248
254
  Howzit.named_arguments.key?(arg) && !Howzit.named_arguments[arg].nil? ? Howzit.named_arguments[arg] : default
249
255
  end
256
+ end
250
257
 
251
- str.gsub!(/\$\{?(\d+)\}?/) do
252
- m = Regexp.last_match
253
- arg, default = m[1].split(/:/)
258
+ def render_numeric_placeholders
259
+ gsub!(/\$\{?(\d+)\}?/) do
260
+ arg, default = Regexp.last_match(1).split(/:/)
254
261
  idx = arg.to_i - 1
255
- if Howzit.arguments.length > idx
256
- Howzit.arguments[idx]
257
- elsif default
258
- default
259
- else
260
- m[0]
261
- end
262
+ Howzit.arguments.length > idx ? Howzit.arguments[idx] : default || Regexp.last_match(0)
262
263
  end
263
- Howzit.arguments.nil? ? str : str.gsub(/\$[@*]/, Shellwords.join(Howzit.arguments))
264
264
  end
265
265
 
266
266
  ##
@@ -289,7 +289,10 @@ module Howzit
289
289
  scan(/(?mi)^(\S[\s\S]+?): ([\s\S]*?)(?=\n\S[\s\S]*?:|\Z)/).each do |m|
290
290
  data[m[0].strip.downcase] = m[1]
291
291
  end
292
- normalize_metadata(data)
292
+ out = normalize_metadata(data)
293
+ Howzit.named_arguments ||= {}
294
+ Howzit.named_arguments = out.merge(Howzit.named_arguments)
295
+ out
293
296
  end
294
297
 
295
298
  ##
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.1.1'
6
+ VERSION = '2.1.2'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
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
  - Brett Terpstra