template-ruby 0.7.3 → 1.0.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +11 -9
  3. data/VERSION +1 -1
  4. data/bin/template +57 -91
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9d26d2cbb19512e90afc42ae4e3a7fb0f31f47f0246d098722fb168973eaef4
4
- data.tar.gz: 9f2d55a307fb6dee1a5e08fb450a4491254da0696dd263fdcb7fe77415e92b48
3
+ metadata.gz: db311323ca45e9d60dcaaed36860dd5279d1d058a0335d237360218bf2bbd11e
4
+ data.tar.gz: 79f2b4493839c39eb10796d440275aebf59ad96f78317e640019bf04ebfb200a
5
5
  SHA512:
6
- metadata.gz: 61fa49d7ba5cb60e7e1831246d2988a8db41c24d82e41df33f9c6ee738bab6c31c9e0463b5619c2e6d3e29c7a9ac6151ca01031d3afb166ed4b74559a14d6ba2
7
- data.tar.gz: 42175618e7b57dd97cd7bf2e183f28b057f73aa6db323b24a9f65bffc508a01db0273a795b6327085137fc835108f8fa642f0cadb4e72569ee6c91cd4668e86c
6
+ metadata.gz: ccdd1827656e53089211967d9db8cea06cab30b7606d4cbb50052353071af3bdfbd6e9a568a7b55d16160407f549cfad05fb219c3c5a6945e173b03eb38fe23d
7
+ data.tar.gz: 19982e2ebfb0d70d0125484bcc7f3532e35099dfaffee0a12c2a3d643ec58b9ab7e53a3fb848d6f7cca43150554339b99e0a0479ddeebe68ab411ea5ec5885ef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- template-ruby (0.7.3)
4
+ template-ruby (1.0.0)
5
5
  code-ruby
6
6
  dorian-arguments
7
7
  language-ruby
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.2.0)
13
+ activesupport (7.2.1)
14
14
  base64
15
15
  bigdecimal
16
16
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -24,10 +24,11 @@ GEM
24
24
  ast (2.4.2)
25
25
  base64 (0.2.0)
26
26
  bigdecimal (3.1.8)
27
- code-ruby (0.15.15)
27
+ code-ruby (0.15.16)
28
28
  activesupport
29
29
  bigdecimal
30
30
  did-you-mean
31
+ dorian-arguments
31
32
  json
32
33
  language-ruby
33
34
  zeitwerk
@@ -36,16 +37,17 @@ GEM
36
37
  did-you-mean (0.1.1)
37
38
  levenshtein (>= 0.2.0)
38
39
  diff-lcs (1.5.1)
39
- dorian-arguments (0.3.0)
40
+ dorian-arguments (0.4.1)
40
41
  activesupport
41
42
  bigdecimal
42
43
  dorian-to_struct
43
- dorian-to_struct (0.5.0)
44
+ dorian-to_struct (0.6.0)
44
45
  drb (2.2.1)
45
46
  i18n (1.14.5)
46
47
  concurrent-ruby (~> 1.0)
47
48
  json (2.7.2)
48
- language-ruby (0.9.2)
49
+ language-ruby (0.9.3)
50
+ dorian-arguments
49
51
  zeitwerk
50
52
  language_server-protocol (3.17.0.3)
51
53
  levenshtein (0.2.2)
@@ -59,7 +61,7 @@ GEM
59
61
  rack (3.1.7)
60
62
  rainbow (3.1.1)
61
63
  regexp_parser (2.9.2)
62
- rexml (3.3.5)
64
+ rexml (3.3.6)
63
65
  strscan
64
66
  rspec (3.13.0)
65
67
  rspec-core (~> 3.13.0)
@@ -93,10 +95,10 @@ GEM
93
95
  rubocop-performance (1.21.1)
94
96
  rubocop (>= 1.48.1, < 2.0)
95
97
  rubocop-ast (>= 1.31.1, < 2.0)
96
- rubocop-rails (2.25.1)
98
+ rubocop-rails (2.26.0)
97
99
  activesupport (>= 4.2.0)
98
100
  rack (>= 1.1)
99
- rubocop (>= 1.33.0, < 2.0)
101
+ rubocop (>= 1.52.0, < 2.0)
100
102
  rubocop-ast (>= 1.31.1, < 2.0)
101
103
  rubocop-rails-omakase (1.0.0)
102
104
  rubocop
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.3
1
+ 1.0.0
data/bin/template CHANGED
@@ -1,105 +1,71 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "optparse"
5
4
  require_relative "../lib/template-ruby"
6
-
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
64
- end
65
- .parse!
66
-
67
- options[:input] = argv.join(" ") if options[:input].empty?
68
-
69
- abort <<~HELP if options[:input].empty?
70
- Usage: template INPUT
71
-
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
79
-
80
- RubyProf.start if options[:profile]
81
-
82
- if options[:parse]
83
- pp Template::Parser.parse(options[:input]).to_raw
5
+ require "dorian/arguments"
6
+
7
+ parsed =
8
+ Dorian::Arguments.parse(
9
+ input: {
10
+ type: :string,
11
+ alias: :i
12
+ },
13
+ parse: {
14
+ type: :boolean,
15
+ alias: :p
16
+ },
17
+ profile: :boolean,
18
+ profiler: :string,
19
+ timeout: {
20
+ type: :integer,
21
+ alias: :t
22
+ },
23
+ version: {
24
+ type: :boolean,
25
+ alias: :v
26
+ },
27
+ help: {
28
+ type: :boolean,
29
+ alias: :h
30
+ }
31
+ )
32
+
33
+ abort Template::Version.to_s if parsed.options.version
34
+ abort parsed.help if parsed.options.help
35
+
36
+ input = parsed.options.input.to_s
37
+ input = File.read(input) if File.exist?(input)
38
+ input += parsed.arguments.join(" ")
39
+ input += parsed.files.map { |file| File.read(file) }.join
40
+
41
+ abort parsed.help if input.empty?
42
+
43
+ profile = parsed.options.profile || !parsed.options.profiler.empty?
44
+ require "ruby-prof" if profile
45
+
46
+ RubyProf.start if profile
47
+
48
+ if parsed.options.parse
49
+ pp Template::Parser.parse(input).to_raw
84
50
  else
85
- print Template.evaluate(
86
- options[:input],
87
- output: $stdout,
88
- error: $stderr,
89
- timeout: options[:timeout]
90
- )
51
+ print(
52
+ Template.evaluate(
53
+ input,
54
+ output: $stdout,
55
+ error: $stderr,
56
+ timeout: parsed.options.timeout
57
+ )
58
+ )
91
59
  end
92
60
 
93
- if options[:profile]
61
+ if profile
94
62
  result = RubyProf.stop
95
63
 
96
- if options[:profiler] == "text"
97
- printer = RubyProf::FlatPrinter.new(result)
98
- printer.print($stdout)
99
- elsif options[:profiler] == "html"
64
+ if parsed.options.profiler == "html"
100
65
  printer = RubyProf::GraphHtmlPrinter.new(result)
101
66
  printer.print($stdout)
102
67
  else
103
- abort "#{options[:profiler]} not recognized"
68
+ printer = RubyProf::FlatPrinter.new(result)
69
+ printer.print($stdout)
104
70
  end
105
71
  end
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.7.3
4
+ version: 1.0.0
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-08-22 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code-ruby