template-ruby 0.6.5 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +38 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +88 -18
- data/bin/rspec +31 -0
- data/bin/template +76 -57
- data/bin/test +5 -0
- data/lib/template/node/template.rb +3 -3
- data/lib/template/version.rb +1 -1
- data/lib/template.rb +23 -32
- data/spec/spec_helper.rb +1 -0
- data/spec/template_spec.rb +4 -4
- data/yarn.lock +4 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec20f7b682a83a2c029fcaf5c5270439a4975f0eb76f18f44656548c5e753799
|
4
|
+
data.tar.gz: b3c010695b9257056998fb515f4f52e30f5df1ded3ec27736dc8db5f8c9e3950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77e4ce2e75c5e2f6cd8ad77777c491e2f62521fa5c061e213485d86e86dbc6780dd0669a5680992ad009ec86935781a2bf2cf9c806b73994e37b06ae192fab41
|
7
|
+
data.tar.gz: eac7a3063cd150e8d206fa6aa49e3f7637735cae5e78b99b416a7422bcd28978d3e5b212b0efd840f64ad839c1f2b61ac010af235995bbe9ab0c311ffbc7cdcc
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
version: 2
|
3
|
+
updates:
|
4
|
+
- directory: "/"
|
5
|
+
package-ecosystem: github-actions
|
6
|
+
schedule:
|
7
|
+
interval: daily
|
8
|
+
- directory: "/"
|
9
|
+
package-ecosystem: npm
|
10
|
+
schedule:
|
11
|
+
interval: daily
|
12
|
+
- directory: "/"
|
13
|
+
package-ecosystem: bundler
|
14
|
+
schedule:
|
15
|
+
interval: daily
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: CI
|
2
|
+
on: push
|
3
|
+
jobs:
|
4
|
+
bundler-audit:
|
5
|
+
name: Bundler Audit
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@v4
|
9
|
+
- uses: ruby/setup-ruby@v1
|
10
|
+
with:
|
11
|
+
bundler-cache: true
|
12
|
+
- run: bin/bundler-audit check --update
|
13
|
+
rspec:
|
14
|
+
name: Test
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v4
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3.3.0
|
21
|
+
bundler-cache: true
|
22
|
+
- run: bin/test
|
23
|
+
rubocop:
|
24
|
+
name: Rubocop
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v4
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
bundler-cache: true
|
31
|
+
- run: bin/rubocop
|
32
|
+
yarn-audit:
|
33
|
+
name: Yarn Audit
|
34
|
+
runs-on: ubuntu-latest
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v4
|
37
|
+
- uses: actions/setup-node@v4
|
38
|
+
- run: yarn audit
|
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.7)
|
5
5
|
code-ruby (~> 0)
|
6
6
|
language-ruby (~> 0)
|
7
7
|
zeitwerk (~> 2)
|
@@ -9,29 +9,98 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
13
|
-
|
12
|
+
activesupport (7.1.3.2)
|
13
|
+
base64
|
14
|
+
bigdecimal
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
connection_pool (>= 2.2.5)
|
17
|
+
drb
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
mutex_m
|
21
|
+
tzinfo (~> 2.0)
|
22
|
+
ast (2.4.2)
|
23
|
+
base64 (0.2.0)
|
24
|
+
bigdecimal (3.1.7)
|
25
|
+
code-ruby (0.14.3)
|
26
|
+
activesupport (~> 7)
|
14
27
|
bigdecimal (~> 3)
|
28
|
+
did-you-mean (~> 0)
|
29
|
+
json (~> 2)
|
15
30
|
language-ruby (~> 0)
|
16
31
|
zeitwerk (~> 2)
|
17
|
-
|
18
|
-
|
32
|
+
concurrent-ruby (1.2.3)
|
33
|
+
connection_pool (2.4.1)
|
34
|
+
did-you-mean (0.1.1)
|
35
|
+
levenshtein (>= 0.2.0)
|
36
|
+
diff-lcs (1.5.1)
|
37
|
+
drb (2.2.1)
|
38
|
+
i18n (1.14.4)
|
39
|
+
concurrent-ruby (~> 1.0)
|
40
|
+
json (2.7.1)
|
41
|
+
language-ruby (0.8.1)
|
19
42
|
zeitwerk (~> 2)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
43
|
+
language_server-protocol (3.17.0.3)
|
44
|
+
levenshtein (0.2.2)
|
45
|
+
minitest (5.22.3)
|
46
|
+
mutex_m (0.2.0)
|
47
|
+
parallel (1.24.0)
|
48
|
+
parser (3.3.0.5)
|
49
|
+
ast (~> 2.4.1)
|
50
|
+
racc
|
51
|
+
racc (1.7.3)
|
52
|
+
rack (3.0.10)
|
53
|
+
rainbow (3.1.1)
|
54
|
+
regexp_parser (2.9.0)
|
55
|
+
rexml (3.2.6)
|
56
|
+
rspec (3.13.0)
|
57
|
+
rspec-core (~> 3.13.0)
|
58
|
+
rspec-expectations (~> 3.13.0)
|
59
|
+
rspec-mocks (~> 3.13.0)
|
60
|
+
rspec-core (3.13.0)
|
61
|
+
rspec-support (~> 3.13.0)
|
62
|
+
rspec-expectations (3.13.0)
|
27
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
64
|
+
rspec-support (~> 3.13.0)
|
65
|
+
rspec-mocks (3.13.0)
|
30
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
67
|
+
rspec-support (~> 3.13.0)
|
68
|
+
rspec-support (3.13.1)
|
69
|
+
rubocop (1.62.1)
|
70
|
+
json (~> 2.3)
|
71
|
+
language_server-protocol (>= 3.17.0)
|
72
|
+
parallel (~> 1.10)
|
73
|
+
parser (>= 3.3.0.2)
|
74
|
+
rainbow (>= 2.2.2, < 4.0)
|
75
|
+
regexp_parser (>= 1.8, < 3.0)
|
76
|
+
rexml (>= 3.2.5, < 4.0)
|
77
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
78
|
+
ruby-progressbar (~> 1.7)
|
79
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
80
|
+
rubocop-ast (1.31.2)
|
81
|
+
parser (>= 3.3.0.4)
|
82
|
+
rubocop-minitest (0.35.0)
|
83
|
+
rubocop (>= 1.61, < 2.0)
|
84
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
85
|
+
rubocop-performance (1.21.0)
|
86
|
+
rubocop (>= 1.48.1, < 2.0)
|
87
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
88
|
+
rubocop-rails (2.24.1)
|
89
|
+
activesupport (>= 4.2.0)
|
90
|
+
rack (>= 1.1)
|
91
|
+
rubocop (>= 1.33.0, < 2.0)
|
92
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
93
|
+
rubocop-rails-omakase (1.0.0)
|
94
|
+
rubocop
|
95
|
+
rubocop-minitest
|
96
|
+
rubocop-performance
|
97
|
+
rubocop-rails
|
33
98
|
ruby-prof (1.7.0)
|
34
|
-
|
99
|
+
ruby-progressbar (1.13.0)
|
100
|
+
tzinfo (2.0.6)
|
101
|
+
concurrent-ruby (~> 1.0)
|
102
|
+
unicode-display_width (2.5.0)
|
103
|
+
zeitwerk (2.6.13)
|
35
104
|
|
36
105
|
PLATFORMS
|
37
106
|
arm64-darwin-22
|
@@ -39,6 +108,7 @@ PLATFORMS
|
|
39
108
|
|
40
109
|
DEPENDENCIES
|
41
110
|
rspec
|
111
|
+
rubocop-rails-omakase
|
42
112
|
ruby-prof
|
43
113
|
template-ruby!
|
44
114
|
|
@@ -46,4 +116,4 @@ RUBY VERSION
|
|
46
116
|
ruby 3.3.0p0
|
47
117
|
|
48
118
|
BUNDLED WITH
|
49
|
-
2.5.
|
119
|
+
2.5.7
|
data/bin/rspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300).include?(
|
17
|
+
"This file was generated by Bundler"
|
18
|
+
)
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort(
|
22
|
+
"Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
23
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again."
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require "rubygems"
|
29
|
+
require "bundler/setup"
|
30
|
+
|
31
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/template
CHANGED
@@ -4,76 +4,95 @@
|
|
4
4
|
require "optparse"
|
5
5
|
require_relative "../lib/template-ruby"
|
6
6
|
|
7
|
-
options = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"--
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
7
|
+
options = {
|
8
|
+
timeout: 0,
|
9
|
+
profile: false,
|
10
|
+
profiler: "text",
|
11
|
+
input: "",
|
12
|
+
parse: false
|
13
|
+
}
|
14
|
+
|
15
|
+
argv =
|
16
|
+
OptionParser
|
17
|
+
.new do |opts|
|
18
|
+
opts.banner = "Usage: template INPUT\n\n"
|
19
|
+
|
20
|
+
opts.on("-v", "--version", "Version of Template") do |_input|
|
21
|
+
puts Code::Version
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on(
|
26
|
+
"-i INPUT",
|
27
|
+
"--input INPUT",
|
28
|
+
"Input in the Template language (String or File)"
|
29
|
+
) do |input|
|
30
|
+
input = File.read(input) if File.exist?(input)
|
31
|
+
|
32
|
+
options[:input] = input
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-p", "--parse", "Parser tree for input") do |parse|
|
36
|
+
options[:parse] = parse
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on(
|
40
|
+
"-t TIMEOUT",
|
41
|
+
"--timeout TIMEOUT",
|
42
|
+
"Set timeout in seconds"
|
43
|
+
) { |timeout| options[:timeout] = timeout.to_f }
|
44
|
+
|
45
|
+
opts.on(
|
46
|
+
"-z TIME_ZONE",
|
47
|
+
"--time-zone TIME_ZONE",
|
48
|
+
"Set time zone"
|
49
|
+
) { |time_zone| Time.zone = time_zone }
|
50
|
+
|
51
|
+
opts.on("--profile", "Profile Ruby code") do |_timeout|
|
52
|
+
require "ruby-prof"
|
53
|
+
options[:profile] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on(
|
57
|
+
"--profiler TYPE",
|
58
|
+
"Profiler output type (text (default) or html)"
|
59
|
+
) do |profiler|
|
60
|
+
require "ruby-prof"
|
61
|
+
options[:profile] = true
|
62
|
+
options[:profiler] = profiler
|
63
|
+
end
|
26
64
|
end
|
65
|
+
.parse!
|
27
66
|
|
28
|
-
|
29
|
-
"-c CONTEXT",
|
30
|
-
"--context=CONTEXT",
|
31
|
-
"Context in the code language (String or File)"
|
32
|
-
) do |context|
|
33
|
-
context = File.read(context) if File.exist?(context)
|
34
|
-
|
35
|
-
options[:context] = context
|
36
|
-
end
|
67
|
+
options[:input] = argv.join(" ") if options[:input].empty?
|
37
68
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
69
|
+
abort <<~HELP if options[:input].empty?
|
70
|
+
Usage: template INPUT
|
41
71
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
require "ruby-prof"
|
50
|
-
options[:profile] = true
|
51
|
-
end
|
52
|
-
|
53
|
-
opts.on(
|
54
|
-
"--profiler TYPE",
|
55
|
-
"Profiler output type (text (default) or html)"
|
56
|
-
) do |profiler|
|
57
|
-
require "ruby-prof"
|
58
|
-
options[:profile] = true
|
59
|
-
options[:profiler] = profiler
|
60
|
-
end
|
61
|
-
end
|
62
|
-
.parse!
|
63
|
-
|
64
|
-
input = options.fetch(:input, "")
|
65
|
-
context = options.fetch(:context, "")
|
72
|
+
-v, --version Version of Template
|
73
|
+
-i, --input INPUT Input in the Template language (String or File)
|
74
|
+
-p, --parse Parser tree for input
|
75
|
+
-t, --timeout TIMEOUT Set timeout in seconds
|
76
|
+
--profile Profile Ruby code
|
77
|
+
--profiler TYPE Profiler output type (text (default) or html)
|
78
|
+
HELP
|
66
79
|
|
67
80
|
RubyProf.start if options[:profile]
|
68
81
|
|
69
82
|
if options[:parse]
|
70
|
-
pp
|
83
|
+
pp Template::Parser.parse(options[:input]).to_raw
|
71
84
|
else
|
72
|
-
Template.evaluate(
|
85
|
+
print Template.evaluate(
|
86
|
+
options[:input],
|
87
|
+
output: $stdout,
|
88
|
+
error: $stderr,
|
89
|
+
timeout: options[:timeout]
|
90
|
+
)
|
73
91
|
end
|
74
92
|
|
75
93
|
if options[:profile]
|
76
94
|
result = RubyProf.stop
|
95
|
+
|
77
96
|
if options[:profiler] == "text"
|
78
97
|
printer = RubyProf::FlatPrinter.new(result)
|
79
98
|
printer.print($stdout)
|
@@ -8,9 +8,9 @@ class Template
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def evaluate(**args)
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
output = args.fetch(:output)
|
12
|
+
@parts.each { |part| output.print(part.evaluate(**args)) }
|
13
|
+
::Code::Object::Nothing.new
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/template/version.rb
CHANGED
data/lib/template.rb
CHANGED
@@ -1,54 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Template
|
4
|
-
|
5
|
-
GLOBALS = %i[io context object].freeze
|
4
|
+
GLOBALS = %i[output error context object].freeze
|
6
5
|
DEFAULT_TIMEOUT = 0
|
7
6
|
|
8
|
-
def initialize(
|
7
|
+
def initialize(
|
8
|
+
input,
|
9
|
+
output: StringIO.new,
|
10
|
+
error: StringIO.new,
|
11
|
+
timeout: DEFAULT_TIMEOUT
|
12
|
+
)
|
9
13
|
@input = input
|
10
|
-
@
|
11
|
-
|
12
|
-
@io = io
|
14
|
+
@output = output
|
15
|
+
@error = error
|
13
16
|
@timeout = timeout || DEFAULT_TIMEOUT
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
@context = ::Code::Object::Context.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.parse(input, timeout: DEFAULT_TIMEOUT)
|
21
|
+
Timeout.timeout(timeout) { Parser.parse(input).to_raw }
|
18
22
|
end
|
19
23
|
|
20
24
|
def self.evaluate(
|
21
25
|
input,
|
22
|
-
|
23
|
-
|
24
|
-
timeout: DEFAULT_TIMEOUT
|
25
|
-
ruby: {}
|
26
|
+
output: StringIO.new,
|
27
|
+
error: StringIO.new,
|
28
|
+
timeout: DEFAULT_TIMEOUT
|
26
29
|
)
|
27
|
-
new(input,
|
30
|
+
new(input, output:, error:, timeout:).evaluate
|
28
31
|
end
|
29
32
|
|
30
|
-
def evaluate
|
33
|
+
def evaluate
|
31
34
|
Timeout.timeout(timeout) do
|
32
|
-
|
33
|
-
|
34
|
-
::Code::Object::Context.new
|
35
|
-
else
|
36
|
-
::Code.evaluate(context, timeout:, io:, ruby:).code_to_context
|
37
|
-
end
|
38
|
-
|
39
|
-
unless context.is_a?(::Code::Object::Context)
|
40
|
-
raise(Error::IncompatibleContext)
|
41
|
-
end
|
42
|
-
|
43
|
-
context = context.merge(ruby)
|
44
|
-
|
45
|
-
::Template::Node::Template.new(parsed).evaluate(context:, io:)
|
35
|
+
parsed = Template.parse(input)
|
36
|
+
Node::Template.new(parsed).evaluate(context:, output:, error:)
|
46
37
|
|
47
|
-
|
38
|
+
output.is_a?(StringIO) ? output.string : ""
|
48
39
|
end
|
49
40
|
end
|
50
41
|
|
51
42
|
private
|
52
43
|
|
53
|
-
attr_reader :input, :
|
44
|
+
attr_reader :input, :timeout, :output, :error, :context
|
54
45
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/template_spec.rb
CHANGED
@@ -4,10 +4,10 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
RSpec.describe Code do
|
6
6
|
[
|
7
|
-
["
|
8
|
-
].each do |input,
|
9
|
-
it "#{input}
|
10
|
-
expect(Template.evaluate(input
|
7
|
+
["{name = :Dorian nothing}Hello {name}", "Hello Dorian"]
|
8
|
+
].each do |input, expected|
|
9
|
+
it "#{input} == #{expected}" do
|
10
|
+
expect(Template.evaluate(input)).to eq(expected)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/yarn.lock
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code-ruby
|
@@ -60,13 +60,17 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".github/dependabot.yml"
|
64
|
+
- ".github/workflows/ci.yml"
|
63
65
|
- ".rspec"
|
64
66
|
- ".ruby-version"
|
65
67
|
- ".tool-versions"
|
66
68
|
- Gemfile
|
67
69
|
- Gemfile.lock
|
68
70
|
- README.md
|
71
|
+
- bin/rspec
|
69
72
|
- bin/template
|
73
|
+
- bin/test
|
70
74
|
- lib/template-ruby.rb
|
71
75
|
- lib/template.rb
|
72
76
|
- lib/template/node.rb
|
@@ -80,6 +84,7 @@ files:
|
|
80
84
|
- spec/spec_helper.rb
|
81
85
|
- spec/template_spec.rb
|
82
86
|
- template-ruby.gemspec
|
87
|
+
- yarn.lock
|
83
88
|
homepage: https://github.com/dorianmariecom/template-ruby
|
84
89
|
licenses:
|
85
90
|
- MIT
|