template-ruby 0.6.6 → 0.6.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72b96f298f1e9c119b40155f321d12379b866b17b3d7ab79440282ace987a2b0
4
- data.tar.gz: 6ef450e127b76928322cf25738c11172b825d292165d3b8589371c5d095787bf
3
+ metadata.gz: ec20f7b682a83a2c029fcaf5c5270439a4975f0eb76f18f44656548c5e753799
4
+ data.tar.gz: b3c010695b9257056998fb515f4f52e30f5df1ded3ec27736dc8db5f8c9e3950
5
5
  SHA512:
6
- metadata.gz: 7521e557ee7d88ef6f59d0efb3471aead4bc78380a6e07fbe65a2ed3922068db4bf686946d73d1c8a76b31658e2cec6db90b307733962ef8a324852c02699d23
7
- data.tar.gz: eaf00c79e4c4a8a455a3518dd296b15fc047407d7dd38fd3c81bacb6daa7edb7cef60c1c733e1bce576fb6c1edf658023b274b3e637bd1e722c077cbfcc93398
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
@@ -8,3 +8,4 @@ ruby "3.3.0"
8
8
 
9
9
  gem "rspec"
10
10
  gem "ruby-prof"
11
+ gem "rubocop-rails-omakase"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- template-ruby (0.6.6)
4
+ template-ruby (0.6.7)
5
5
  code-ruby (~> 0)
6
6
  language-ruby (~> 0)
7
7
  zeitwerk (~> 2)
@@ -19,25 +19,40 @@ GEM
19
19
  minitest (>= 5.1)
20
20
  mutex_m
21
21
  tzinfo (~> 2.0)
22
+ ast (2.4.2)
22
23
  base64 (0.2.0)
23
- bigdecimal (3.1.6)
24
- code-ruby (0.13.0)
24
+ bigdecimal (3.1.7)
25
+ code-ruby (0.14.3)
25
26
  activesupport (~> 7)
26
27
  bigdecimal (~> 3)
28
+ did-you-mean (~> 0)
27
29
  json (~> 2)
28
30
  language-ruby (~> 0)
29
31
  zeitwerk (~> 2)
30
32
  concurrent-ruby (1.2.3)
31
33
  connection_pool (2.4.1)
34
+ did-you-mean (0.1.1)
35
+ levenshtein (>= 0.2.0)
32
36
  diff-lcs (1.5.1)
33
37
  drb (2.2.1)
34
38
  i18n (1.14.4)
35
39
  concurrent-ruby (~> 1.0)
36
40
  json (2.7.1)
37
- language-ruby (0.8.0)
41
+ language-ruby (0.8.1)
38
42
  zeitwerk (~> 2)
39
- minitest (5.22.2)
43
+ language_server-protocol (3.17.0.3)
44
+ levenshtein (0.2.2)
45
+ minitest (5.22.3)
40
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)
41
56
  rspec (3.13.0)
42
57
  rspec-core (~> 3.13.0)
43
58
  rspec-expectations (~> 3.13.0)
@@ -51,9 +66,40 @@ GEM
51
66
  diff-lcs (>= 1.2.0, < 2.0)
52
67
  rspec-support (~> 3.13.0)
53
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
54
98
  ruby-prof (1.7.0)
99
+ ruby-progressbar (1.13.0)
55
100
  tzinfo (2.0.6)
56
101
  concurrent-ruby (~> 1.0)
102
+ unicode-display_width (2.5.0)
57
103
  zeitwerk (2.6.13)
58
104
 
59
105
  PLATFORMS
@@ -62,6 +108,7 @@ PLATFORMS
62
108
 
63
109
  DEPENDENCIES
64
110
  rspec
111
+ rubocop-rails-omakase
65
112
  ruby-prof
66
113
  template-ruby!
67
114
 
@@ -69,4 +116,4 @@ RUBY VERSION
69
116
  ruby 3.3.0p0
70
117
 
71
118
  BUNDLED WITH
72
- 2.5.6
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 = { timeout: 0, profile: false, profiler: "text" }
8
-
9
- OptionParser
10
- .new do |opts|
11
- opts.banner = "Usage: template [options]"
12
-
13
- opts.on("-v", "--version", "Version of template") do |_input|
14
- puts Template::Version
15
- exit
16
- end
17
-
18
- opts.on(
19
- "-i INPUT",
20
- "--input=INPUT",
21
- "Input in the template language (String or File)"
22
- ) do |input|
23
- input = File.read(input) if File.exist?(input)
24
-
25
- options[:input] = input
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
- opts.on(
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
- opts.on("-p", "--parse", "Get parser results for input") do |parse|
39
- options[:parse] = parse
40
- end
69
+ abort <<~HELP if options[:input].empty?
70
+ Usage: template INPUT
41
71
 
42
- opts.on(
43
- "-t TIMEOUT",
44
- "--timeout=TIMEOUT",
45
- "Set timeout in seconds"
46
- ) { |timeout| options[:timeout] = timeout.to_f }
47
-
48
- opts.on("--profile", "Profile Ruby code") do |_timeout|
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 ::Template::Parser.parse(input).to_raw
83
+ pp Template::Parser.parse(options[:input]).to_raw
71
84
  else
72
- Template.evaluate(input, context, io: $stdout, timeout: options[:timeout])
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)
data/bin/test ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ bin/rspec
@@ -8,9 +8,9 @@ class Template
8
8
  end
9
9
 
10
10
  def evaluate(**args)
11
- io = args.fetch(:io)
12
-
13
- @parts.each { |part| io.print(part.evaluate(**args)) }
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
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../template"
4
4
 
5
- Template::Version = Gem::Version.new("0.6.6")
5
+ Template::Version = Gem::Version.new("0.6.7")
data/lib/template.rb CHANGED
@@ -1,54 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Template
4
- EMPTY_STRING = ""
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(input, io: ::StringIO.new, timeout: DEFAULT_TIMEOUT, ruby: {})
7
+ def initialize(
8
+ input,
9
+ output: StringIO.new,
10
+ error: StringIO.new,
11
+ timeout: DEFAULT_TIMEOUT
12
+ )
9
13
  @input = input
10
- @parsed =
11
- Timeout.timeout(timeout) { ::Template::Parser.parse(@input).to_raw }
12
- @io = io
14
+ @output = output
15
+ @error = error
13
16
  @timeout = timeout || DEFAULT_TIMEOUT
14
- @ruby =
15
- Timeout.timeout(timeout) do
16
- ::Code::Ruby.to_code(ruby || {}).code_to_context
17
- end
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
- context = "",
23
- io: ::StringIO.new,
24
- timeout: DEFAULT_TIMEOUT,
25
- ruby: {}
26
+ output: StringIO.new,
27
+ error: StringIO.new,
28
+ timeout: DEFAULT_TIMEOUT
26
29
  )
27
- new(input, io:, timeout:, ruby:).evaluate(context)
30
+ new(input, output:, error:, timeout:).evaluate
28
31
  end
29
32
 
30
- def evaluate(context = "")
33
+ def evaluate
31
34
  Timeout.timeout(timeout) do
32
- context =
33
- if context == EMPTY_STRING
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
- io.is_a?(::StringIO) ? io.string : nil
38
+ output.is_a?(StringIO) ? output.string : ""
48
39
  end
49
40
  end
50
41
 
51
42
  private
52
43
 
53
- attr_reader :input, :parsed, :timeout, :io, :ruby
44
+ attr_reader :input, :timeout, :output, :error, :context
54
45
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rspec"
3
4
  require_relative "../lib/template-ruby"
@@ -4,10 +4,10 @@ require "spec_helper"
4
4
 
5
5
  RSpec.describe Code do
6
6
  [
7
- ["Hello {name}", "{name: :Dorian}", "Hello Dorian"]
8
- ].each do |input, context, expected|
9
- it "#{input} (#{context}) == #{expected}" do
10
- expect(Template.evaluate(input, context)).to eq(expected)
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
@@ -0,0 +1,4 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
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.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-03-09 00:00:00.000000000 Z
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