template-ruby 0.6.2 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +9 -3
- data/bin/template +4 -12
- data/lib/template/node/code_part.rb +2 -0
- data/lib/template/node/part.rb +3 -1
- data/lib/template/node/template.rb +2 -0
- data/lib/template/node/text_part.rb +3 -1
- data/lib/template/node.rb +2 -0
- data/lib/template/parser/template.rb +2 -0
- data/lib/template/parser.rb +2 -0
- data/lib/template/version.rb +3 -1
- data/lib/template-ruby.rb +2 -0
- data/lib/template.rb +16 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/template_spec.rb +1 -1
- data/template-ruby.gemspec +5 -3
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 577e47841edac1911055ef3ab0d874e4f34dd8e90dc80d26eeb9ab8938cb9089
|
4
|
+
data.tar.gz: 746c3a27d41846c09eb0240860d01f288a47d19476c1ae1aacb44b50e1ff33bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c146b32bd894d140d3733c860454aef912e82f84be8d303f6b630b773388af9493810623872d9d0297cc0804a851cdb360cb85423886ab942f65df359c30ee6
|
7
|
+
data.tar.gz: 2d3458a5ea2bc4506001a40dd900bdfd3f84cf08b44a1f78d61ae32523f65212aaa980c3bc43ef64a546efa17d96b769b40670d3068b802ac7c61efa0cdc071a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.3.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
template-ruby (0.6.
|
4
|
+
template-ruby (0.6.3)
|
5
5
|
code-ruby (~> 0)
|
6
6
|
language-ruby (~> 0)
|
7
7
|
zeitwerk (~> 2)
|
@@ -9,7 +9,9 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
12
|
+
bigdecimal (3.1.6)
|
13
|
+
code-ruby (0.6.2)
|
14
|
+
bigdecimal (~> 3)
|
13
15
|
language-ruby (~> 0)
|
14
16
|
zeitwerk (~> 2)
|
15
17
|
diff-lcs (1.5.0)
|
@@ -28,16 +30,20 @@ GEM
|
|
28
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
31
|
rspec-support (~> 3.12.0)
|
30
32
|
rspec-support (3.12.1)
|
31
|
-
ruby-prof (1.
|
33
|
+
ruby-prof (1.7.0)
|
32
34
|
zeitwerk (2.6.12)
|
33
35
|
|
34
36
|
PLATFORMS
|
35
37
|
arm64-darwin-22
|
38
|
+
arm64-darwin-23
|
36
39
|
|
37
40
|
DEPENDENCIES
|
38
41
|
rspec
|
39
42
|
ruby-prof
|
40
43
|
template-ruby!
|
41
44
|
|
45
|
+
RUBY VERSION
|
46
|
+
ruby 3.3.0p0
|
47
|
+
|
42
48
|
BUNDLED WITH
|
43
49
|
2.4.22
|
data/bin/template
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "optparse"
|
4
5
|
require_relative "../lib/template-ruby"
|
@@ -9,11 +10,7 @@ OptionParser
|
|
9
10
|
.new do |opts|
|
10
11
|
opts.banner = "Usage: template [options]"
|
11
12
|
|
12
|
-
opts.on(
|
13
|
-
"-v",
|
14
|
-
"--version",
|
15
|
-
"Version of template"
|
16
|
-
) do |input|
|
13
|
+
opts.on("-v", "--version", "Version of template") do |_input|
|
17
14
|
puts Template::Version
|
18
15
|
exit
|
19
16
|
end
|
@@ -48,10 +45,7 @@ OptionParser
|
|
48
45
|
"Set timeout in seconds"
|
49
46
|
) { |timeout| options[:timeout] = timeout.to_f }
|
50
47
|
|
51
|
-
opts.on(
|
52
|
-
"--profile",
|
53
|
-
"Profile Ruby code"
|
54
|
-
) do |timeout|
|
48
|
+
opts.on("--profile", "Profile Ruby code") do |_timeout|
|
55
49
|
require "ruby-prof"
|
56
50
|
options[:profile] = true
|
57
51
|
end
|
@@ -70,9 +64,7 @@ OptionParser
|
|
70
64
|
input = options.fetch(:input, "")
|
71
65
|
context = options.fetch(:context, "")
|
72
66
|
|
73
|
-
if options[:profile]
|
74
|
-
RubyProf.start
|
75
|
-
end
|
67
|
+
RubyProf.start if options[:profile]
|
76
68
|
|
77
69
|
if options[:parse]
|
78
70
|
pp ::Template::Parser.parse(input).to_raw
|
data/lib/template/node/part.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Template
|
2
4
|
class Node
|
3
5
|
class Part < Node
|
@@ -7,7 +9,7 @@ class Template
|
|
7
9
|
elsif part.key?(:code)
|
8
10
|
@part = ::Template::Node::CodePart.new(part[:code])
|
9
11
|
else
|
10
|
-
raise NotImplementedError
|
12
|
+
raise NotImplementedError, part.inspect
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
data/lib/template/node.rb
CHANGED
data/lib/template/parser.rb
CHANGED
data/lib/template/version.rb
CHANGED
data/lib/template-ruby.rb
CHANGED
data/lib/template.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Template
|
2
4
|
EMPTY_STRING = ""
|
3
5
|
GLOBALS = %i[io context object].freeze
|
4
6
|
DEFAULT_TIMEOUT = 0
|
5
7
|
|
6
|
-
def initialize(input, io: StringIO.new, timeout: DEFAULT_TIMEOUT, ruby: {})
|
8
|
+
def initialize(input, io: ::StringIO.new, timeout: DEFAULT_TIMEOUT, ruby: {})
|
7
9
|
@input = input
|
8
|
-
@parsed =
|
10
|
+
@parsed =
|
11
|
+
Timeout.timeout(timeout) { ::Template::Parser.parse(@input).to_raw }
|
9
12
|
@io = io
|
10
13
|
@timeout = timeout || DEFAULT_TIMEOUT
|
11
|
-
@ruby =
|
14
|
+
@ruby =
|
15
|
+
Timeout.timeout(timeout) do
|
16
|
+
::Code::Ruby.to_code(ruby || {}).code_to_context
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
def self.evaluate(
|
15
21
|
input,
|
16
22
|
context = "",
|
17
|
-
io: StringIO.new,
|
23
|
+
io: ::StringIO.new,
|
18
24
|
timeout: DEFAULT_TIMEOUT,
|
19
25
|
ruby: {}
|
20
26
|
)
|
@@ -25,18 +31,20 @@ class Template
|
|
25
31
|
Timeout.timeout(timeout) do
|
26
32
|
context =
|
27
33
|
if context == EMPTY_STRING
|
28
|
-
Object::Context.new
|
34
|
+
::Code::Object::Context.new
|
29
35
|
else
|
30
|
-
Code.evaluate(context, timeout:, io:, ruby:).code_to_context
|
36
|
+
::Code.evaluate(context, timeout:, io:, ruby:).code_to_context
|
31
37
|
end
|
32
38
|
|
33
|
-
|
39
|
+
unless context.is_a?(::Code::Object::Context)
|
40
|
+
raise(Error::IncompatibleContext)
|
41
|
+
end
|
34
42
|
|
35
43
|
context = context.merge(ruby)
|
36
44
|
|
37
45
|
::Template::Node::Template.new(parsed).evaluate(context:, io:)
|
38
46
|
|
39
|
-
io.is_a?(StringIO) ? io.string : nil
|
47
|
+
io.is_a?(::StringIO) ? io.string : nil
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/template_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
[
|
7
|
-
["Hello {name}", "{name: :Dorian}", "Hello Dorian"]
|
7
|
+
["Hello {name}", "{name: :Dorian}", "Hello Dorian"]
|
8
8
|
].each do |input, context, expected|
|
9
9
|
it "#{input} (#{context}) == #{expected}" do
|
10
10
|
expect(Template.evaluate(input, context)).to eq(expected)
|
data/template-ruby.gemspec
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
1
4
|
require_relative "lib/template/version"
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
@@ -8,14 +11,13 @@ Gem::Specification.new do |s|
|
|
8
11
|
'A templating programming language, like "Hello {name}" with {name: "Dorian"} gives "Hello Dorian"'
|
9
12
|
s.authors = ["Dorian Marié"]
|
10
13
|
s.email = "dorian@dorianmarie.fr"
|
11
|
-
s.files = `git ls-files`.split(
|
12
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
15
|
s.require_paths = ["lib"]
|
14
16
|
s.homepage = "https://github.com/dorianmariefr/template-ruby"
|
15
17
|
s.license = "MIT"
|
16
18
|
s.executables = "template"
|
17
19
|
|
18
|
-
s.add_dependency "zeitwerk", "~> 2"
|
19
20
|
s.add_dependency "code-ruby", "~> 0"
|
20
21
|
s.add_dependency "language-ruby", "~> 0"
|
22
|
+
s.add_dependency "zeitwerk", "~> 2"
|
21
23
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: template-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: code-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: language-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: zeitwerk
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2'
|
55
55
|
description: 'A templating programming language, like "Hello {name}" with {name: "Dorian"}
|
56
56
|
gives "Hello Dorian"'
|
57
57
|
email: dorian@dorianmarie.fr
|
@@ -61,6 +61,8 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".rspec"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".tool-versions"
|
64
66
|
- Gemfile
|
65
67
|
- Gemfile.lock
|
66
68
|
- README.md
|
@@ -97,10 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
99
|
- !ruby/object:Gem::Version
|
98
100
|
version: '0'
|
99
101
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.5.3
|
101
103
|
signing_key:
|
102
104
|
specification_version: 4
|
103
105
|
summary: A templating programming language
|
104
|
-
test_files:
|
105
|
-
- spec/spec_helper.rb
|
106
|
-
- spec/template_spec.rb
|
106
|
+
test_files: []
|