template-ruby 0.2.2 → 0.2.3
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/CHANGELOG.md +4 -0
- data/lib/code.rb +15 -10
- data/lib/template-ruby.rb +1 -0
- data/lib/template.rb +17 -12
- 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: d5e2a863316056d011b034cc0c819984d710899e8b51657dd15636e45db058b0
|
4
|
+
data.tar.gz: 47974cad2e705fb70706b68a496523f414b3027c6f57ec6d22344c588cdce143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ba52300910fb32458e115c200842c3a2ef18a19e8fddee92c38a961d60637d3c3c73906304184ef0ec5771ad85cc5dd19d8dbe0803a872a2c5c0dd69cc82a16
|
7
|
+
data.tar.gz: d526bbd95df4375aee06d4c9cc8bb8c6f2927b725514527dd9d3e29229223235bf0c8870d917eb61ae30cbce52e2c27a5f18ba31a2b1fcc94b0dfc574bf77bd1
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## 0.2.3 / 2022-08-31
|
9
|
+
|
10
|
+
- Add default timeout for code and template parsing and evaluation
|
11
|
+
|
8
12
|
## 0.2.2 / 2022-08-31
|
9
13
|
|
10
14
|
- Fix parsing error when the template is empty, e.g. ""
|
data/lib/code.rb
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
class Code
|
2
|
-
def initialize(input, io: $stdout)
|
2
|
+
def initialize(input, io: $stdout, timeout: 10)
|
3
3
|
@input = input
|
4
|
-
@parsed = ::
|
4
|
+
@parsed = Timeout::timeout(timeout) do
|
5
|
+
::Code::Parser::Code.new.parse(@input)
|
6
|
+
end
|
5
7
|
@io = io
|
8
|
+
@timeout = timeout
|
6
9
|
end
|
7
10
|
|
8
|
-
def self.evaluate(input, context = "", io: $stdout)
|
9
|
-
new(input, io: io).evaluate(context)
|
11
|
+
def self.evaluate(input, context = "", io: $stdout, timeout: 10)
|
12
|
+
new(input, io: io, timeout: timeout).evaluate(context)
|
10
13
|
end
|
11
14
|
|
12
15
|
def evaluate(context = "")
|
13
|
-
|
14
|
-
context
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
Timeout::timeout(@timeout) do
|
17
|
+
if context.present?
|
18
|
+
context = ::Code.evaluate(context, timeout: @timeout)
|
19
|
+
else
|
20
|
+
context = ::Code::Object::Dictionnary.new
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
::Code::Node::Code.new(parsed).evaluate(context: context, io: @io)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
private
|
data/lib/template-ruby.rb
CHANGED
data/lib/template.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
1
|
class Template
|
2
|
-
VERSION = Gem::Version.new("0.2.
|
2
|
+
VERSION = Gem::Version.new("0.2.3")
|
3
3
|
|
4
|
-
def initialize(input, io: StringIO.new)
|
4
|
+
def initialize(input, io: StringIO.new, timeout: 10)
|
5
5
|
@input = input
|
6
|
-
@parsed = ::
|
6
|
+
@parsed = Timeout::timeout(timeout) do
|
7
|
+
::Template::Parser::Template.new.parse(@input)
|
8
|
+
end
|
7
9
|
@io = io
|
10
|
+
@timeout = timeout
|
8
11
|
end
|
9
12
|
|
10
|
-
def self.render(input, context = "", io: StringIO.new)
|
11
|
-
new(input, io: io).render(context)
|
13
|
+
def self.render(input, context = "", io: StringIO.new, timeout: 10)
|
14
|
+
new(input, io: io, timeout: timeout).render(context)
|
12
15
|
end
|
13
16
|
|
14
17
|
def render(context = "")
|
15
|
-
|
16
|
-
context
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
Timeout::timeout(@timeout) do
|
19
|
+
if context.present?
|
20
|
+
context = ::Code.evaluate(context, timeout: @timeout)
|
21
|
+
else
|
22
|
+
context = ::Code::Object::Dictionnary.new
|
23
|
+
end
|
20
24
|
|
21
|
-
|
25
|
+
::Template::Node::Template.new(@parsed).evaluate(context: context, io: @io)
|
22
26
|
|
23
|
-
|
27
|
+
@io.is_a?(StringIO) ? @io.string : nil
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|