tina4ruby 3.10.14 → 3.10.16
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 +4 -4
- data/lib/tina4/template.rb +41 -5
- data/lib/tina4/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b4c3594fbc563cd59432d661382280e066d4632f94d2e8244a42479d2016b10
|
|
4
|
+
data.tar.gz: 15d5e418f53d660591813dd65a7eab0ff66edb98bc4c99b6c22f062b7c36fd55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a0c02ec7be3a98f05845983cdea86f11dc9c9d6994e028fe61817daebe60bcec7b24dc07318932d66b8abd48d6145cddb6f1490b00a6fd9a2a74280a524591a6
|
|
7
|
+
data.tar.gz: a169f586a60bcd5c01b9600f3905aacb9ffa65c0cafc2e478acd31a09fbf572e94dc092b91cdf09cb02ada09fde75c04973b058a65c50a12ab7a488fea3fb96a
|
data/lib/tina4/template.rb
CHANGED
|
@@ -132,7 +132,10 @@ module Tina4
|
|
|
132
132
|
"slice" => ->(v, s, e) { v.to_s[(s.to_i)..(e ? e.to_i : -1)] },
|
|
133
133
|
"merge" => ->(v, o) { v.respond_to?(:merge) ? v.merge(o || {}) : v },
|
|
134
134
|
"batch" => ->(v, s) { v.respond_to?(:each_slice) ? v.each_slice(s.to_i).to_a : [v] },
|
|
135
|
-
"date" => ->(v, fmt) { TwigEngine.format_date(v, fmt) }
|
|
135
|
+
"date" => ->(v, fmt) { TwigEngine.format_date(v, fmt) },
|
|
136
|
+
"to_json" => ->(v) { JSON.generate(v).gsub("<", "\\u003c").gsub(">", "\\u003e").gsub("&", "\\u0026") rescue v.to_s },
|
|
137
|
+
"tojson" => ->(v) { JSON.generate(v).gsub("<", "\\u003c").gsub(">", "\\u003e").gsub("&", "\\u0026") rescue v.to_s },
|
|
138
|
+
"js_escape" => ->(v) { v.to_s.gsub("\\", "\\\\").gsub("'", "\\'").gsub('"', '\\"').gsub("\n", "\\n").gsub("\r", "\\r") }
|
|
136
139
|
}.freeze
|
|
137
140
|
|
|
138
141
|
def initialize(context = {}, base_dir = nil)
|
|
@@ -335,8 +338,15 @@ module Tina4
|
|
|
335
338
|
args = []
|
|
336
339
|
current = +""
|
|
337
340
|
in_quote = nil
|
|
341
|
+
escaped = false
|
|
338
342
|
args_str.each_char do |ch|
|
|
339
|
-
if
|
|
343
|
+
if escaped
|
|
344
|
+
current << ch
|
|
345
|
+
escaped = false
|
|
346
|
+
elsif ch == "\\"
|
|
347
|
+
current << ch
|
|
348
|
+
escaped = true
|
|
349
|
+
elsif in_quote
|
|
340
350
|
if ch == in_quote
|
|
341
351
|
current << ch
|
|
342
352
|
in_quote = nil
|
|
@@ -356,8 +366,8 @@ module Tina4
|
|
|
356
366
|
args << current.strip unless current.strip.empty?
|
|
357
367
|
|
|
358
368
|
args.map do |arg|
|
|
359
|
-
if arg =~ /\A["'](.*)
|
|
360
|
-
Regexp.last_match(
|
|
369
|
+
if arg =~ /\A(["'])(.*)\1\z/m
|
|
370
|
+
process_escapes(Regexp.last_match(2))
|
|
361
371
|
elsif arg =~ /\A\d+\z/
|
|
362
372
|
arg.to_i
|
|
363
373
|
elsif arg =~ /\A\d+\.\d+\z/
|
|
@@ -445,7 +455,9 @@ module Tina4
|
|
|
445
455
|
expr = expr.strip
|
|
446
456
|
|
|
447
457
|
# String literal early-return
|
|
448
|
-
|
|
458
|
+
if expr =~ /\A"([^"]*)"\z/ || expr =~ /\A'([^']*)'\z/
|
|
459
|
+
return process_escapes(Regexp.last_match(1))
|
|
460
|
+
end
|
|
449
461
|
|
|
450
462
|
return expr.to_i if expr =~ /\A-?\d+\z/
|
|
451
463
|
return expr.to_f if expr =~ /\A-?\d+\.\d+\z/
|
|
@@ -618,6 +630,30 @@ module Tina4
|
|
|
618
630
|
parts
|
|
619
631
|
end
|
|
620
632
|
|
|
633
|
+
# Process backslash escape sequences in a single pass so that
|
|
634
|
+
# \\' does not collapse to ' (it should become \').
|
|
635
|
+
def process_escapes(s)
|
|
636
|
+
out = +""
|
|
637
|
+
i = 0
|
|
638
|
+
while i < s.length
|
|
639
|
+
if s[i] == "\\" && i + 1 < s.length
|
|
640
|
+
nxt = s[i + 1]
|
|
641
|
+
case nxt
|
|
642
|
+
when "n" then out << "\n"; i += 2
|
|
643
|
+
when "t" then out << "\t"; i += 2
|
|
644
|
+
when "\\" then out << "\\"; i += 2
|
|
645
|
+
when "'" then out << "'"; i += 2
|
|
646
|
+
when '"' then out << '"'; i += 2
|
|
647
|
+
else out << "\\"; i += 1
|
|
648
|
+
end
|
|
649
|
+
else
|
|
650
|
+
out << s[i]
|
|
651
|
+
i += 1
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
out
|
|
655
|
+
end
|
|
656
|
+
|
|
621
657
|
def access_value(obj, key)
|
|
622
658
|
return nil if obj.nil?
|
|
623
659
|
if obj.is_a?(Hash)
|
data/lib/tina4/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tina4ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.10.
|
|
4
|
+
version: 3.10.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tina4 Team
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rack
|
|
@@ -400,7 +399,6 @@ licenses:
|
|
|
400
399
|
- MIT
|
|
401
400
|
metadata:
|
|
402
401
|
homepage_uri: https://tina4.com
|
|
403
|
-
post_install_message:
|
|
404
402
|
rdoc_options: []
|
|
405
403
|
require_paths:
|
|
406
404
|
- lib
|
|
@@ -415,8 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
415
413
|
- !ruby/object:Gem::Version
|
|
416
414
|
version: '0'
|
|
417
415
|
requirements: []
|
|
418
|
-
rubygems_version:
|
|
419
|
-
signing_key:
|
|
416
|
+
rubygems_version: 4.0.3
|
|
420
417
|
specification_version: 4
|
|
421
418
|
summary: Simple. Fast. Human. This is not a framework.
|
|
422
419
|
test_files: []
|