template-ruby 0.6.2 → 0.6.4

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: 563310c18f63131c45c4e8fb05a002765c9fe67b5d118d0bbd1683d9ba52fe8c
4
- data.tar.gz: 5d135daf4766e24fbff6ac875050432510f5408e1e105d7834985ff540e0e0f7
3
+ metadata.gz: 577e47841edac1911055ef3ab0d874e4f34dd8e90dc80d26eeb9ab8938cb9089
4
+ data.tar.gz: 746c3a27d41846c09eb0240860d01f288a47d19476c1ae1aacb44b50e1ff33bd
5
5
  SHA512:
6
- metadata.gz: b28803d77e9e60bb4f38377c8f81755f23e3d89bbb9cf35bf779337a3ecf86854db6acfa2f018fd126cbf234b8307640aa1d0567b4747c7df432d4a6aa157a30
7
- data.tar.gz: 48c9939a07e16a0f400970554938296f5e6faa7114226e641814f4442ebc0bd0ee898e0a00a7c5ff5c624495d871806771c1cbf6316b8c517bc0eedc175abfd8
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
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
7
+ ruby "3.3.0"
8
+
5
9
  gem "rspec"
6
10
  gem "ruby-prof"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- template-ruby (0.6.1)
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
- code-ruby (0.6.0)
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.6.3)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Node
3
5
  class CodePart < Node
@@ -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.new(part.inspect)
12
+ raise NotImplementedError, part.inspect
11
13
  end
12
14
  end
13
15
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Node
3
5
  class Template < Node
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Node
3
5
  class TextPart < Node
@@ -5,7 +7,7 @@ class Template
5
7
  @text = text
6
8
  end
7
9
 
8
- def evaluate(**args)
10
+ def evaluate(**_args)
9
11
  ::Code::Object::String.new(@text.to_s)
10
12
  end
11
13
  end
data/lib/template/node.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Node < ::Code::Node
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Parser
3
5
  class Template < Language
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Template
2
4
  class Parser
3
5
  def initialize(input)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../template"
2
4
 
3
- Template::Version = Gem::Version.new("0.6.2")
5
+ Template::Version = Gem::Version.new("0.6.4")
data/lib/template-ruby.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "stringio"
2
4
  require "timeout"
3
5
  require "zeitwerk"
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 = Timeout.timeout(timeout) { ::Template::Parser.parse(@input).to_raw }
10
+ @parsed =
11
+ Timeout.timeout(timeout) { ::Template::Parser.parse(@input).to_raw }
9
12
  @io = io
10
13
  @timeout = timeout || DEFAULT_TIMEOUT
11
- @ruby = Timeout.timeout(timeout) { ::Code::Ruby.to_code(ruby || {}).code_to_context }
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
- raise(Error::IncompatibleContext) unless context.is_a?(::Code::Object::Context)
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
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../lib/template-ruby"
@@ -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)
@@ -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.2
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: 2023-11-24 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: zeitwerk
14
+ name: code-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
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: '2'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: code-ruby
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: language-ruby
42
+ name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
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: '0'
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.4.22
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: []