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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/howzit/colors.rb +1 -1
- data/lib/howzit/stringutils.rb +16 -13
- data/lib/howzit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a304a27d457b410c8764ed0b83f0a00e2e6e9108ba3fd4a7bef722695d8607
|
4
|
+
data.tar.gz: 2041090127040e2315691750de2ee9ccaf3d770a7b8561d328f573e78e633a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dda575709255dec600f6ba6f259c856b67ab91d9418fbcbc374f85a8eaa6a2842ac8a0b9bdd22a5eec9621e17353b6f2dfa7bc7b6f9b7de9d0c64006d5a27b1
|
7
|
+
data.tar.gz: 236c40bbd997c4bd956aa9796999771b965907add10b208929ba45a09c04679126177232dce1a5d29d15cec4ebfd09315b8bc274e588b0fccc02a938395731ef
|
data/CHANGELOG.md
CHANGED
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
|
|
data/lib/howzit/stringutils.rb
CHANGED
@@ -242,25 +242,25 @@ module Howzit
|
|
242
242
|
##
|
243
243
|
def render_arguments
|
244
244
|
str = dup
|
245
|
-
str.
|
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
|
-
|
252
|
-
|
253
|
-
arg, default =
|
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
|
-
|
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
|
##
|
data/lib/howzit/version.rb
CHANGED