template-ruby 0.6.0 → 0.6.1

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: e9a4bbcdb1f2f2854cd079871ae335cd91b4104d5aef15824e7b14995677d108
4
- data.tar.gz: ae2ff0751a8bb499a930f60981c9d1cc06d6199eb30a934b7a6f5ae806692db1
3
+ metadata.gz: c2083870212319aa2d41c2e5b7f214fefd09aa04ff4676adc4c47f248047c12b
4
+ data.tar.gz: 8b789135855a027e8b5dccefdeae23e9898a887e57dd9657092f121f2bb2b22b
5
5
  SHA512:
6
- metadata.gz: 8c1e8db664717fbed97f2af4ba995c4c04ae5b130f6f6e1c8046f76cbfafb34992f12adb1148644e9af240454614abbba87c9ada10502ad987fd9166026387e7
7
- data.tar.gz: 9631aaeb911bdce1bdb054979325f6482b408c0f50c3c45fd74002d98782ed1dfe06b70ebd7859b66e3460790d934204e116385734c8741efaebdfa3a8ae02ec
6
+ metadata.gz: 8e520c56de87100229e627eee0d2103a8491481bbc2016a9df82efd828bc81e6f0441e2936764cbbcf02a4acdf48d111afb11667fa1b896a945ec6555f7db02e
7
+ data.tar.gz: 203c7404e3ba7e69583cacc3945d4a7209157bb1a6b21940ba0c6ce60e7edbecb47719164b7c142266faf645cb44da63c2e783cdc583416220e382af3f162ce6
data/bin/template ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require_relative "../lib/template-ruby"
5
+
6
+ options = { timeout: 0, profile: false, profiler: "text" }
7
+
8
+ OptionParser
9
+ .new do |opts|
10
+ opts.banner = "Usage: template [options]"
11
+
12
+ opts.on(
13
+ "-v",
14
+ "--version",
15
+ "Version of template"
16
+ ) do |input|
17
+ puts Template::Version
18
+ exit
19
+ end
20
+
21
+ opts.on(
22
+ "-i INPUT",
23
+ "--input=INPUT",
24
+ "Input in the template language (String or File)"
25
+ ) do |input|
26
+ input = File.read(input) if File.exist?(input)
27
+
28
+ options[:input] = input
29
+ end
30
+
31
+ opts.on(
32
+ "-c CONTEXT",
33
+ "--context=CONTEXT",
34
+ "Context in the code language (String or File)"
35
+ ) do |context|
36
+ context = File.read(context) if File.exist?(context)
37
+
38
+ options[:context] = context
39
+ end
40
+
41
+ opts.on("-p", "--parse", "Get parser results for input") do |parse|
42
+ options[:parse] = parse
43
+ end
44
+
45
+ opts.on(
46
+ "-t TIMEOUT",
47
+ "--timeout=TIMEOUT",
48
+ "Set timeout in seconds"
49
+ ) { |timeout| options[:timeout] = timeout.to_f }
50
+
51
+ opts.on(
52
+ "--profile",
53
+ "Profile Ruby code"
54
+ ) do |timeout|
55
+ require "ruby-prof"
56
+ options[:profile] = true
57
+ end
58
+
59
+ opts.on(
60
+ "--profiler TYPE",
61
+ "Profiler output type (text (default) or html)"
62
+ ) do |profiler|
63
+ require "ruby-prof"
64
+ options[:profile] = true
65
+ options[:profiler] = profiler
66
+ end
67
+ end
68
+ .parse!
69
+
70
+ input = options.fetch(:input, "")
71
+ context = options.fetch(:context, "")
72
+
73
+ if options[:profile]
74
+ RubyProf.start
75
+ end
76
+
77
+ if options[:parse]
78
+ pp ::Template::Parser.parse(input).to_raw
79
+ else
80
+ Template.evaluate(input, context, io: $stdout, timeout: options[:timeout])
81
+ end
82
+
83
+ if options[:profile]
84
+ result = RubyProf.stop
85
+ if options[:profiler] == "text"
86
+ printer = RubyProf::FlatPrinter.new(result)
87
+ printer.print($stdout)
88
+ elsif options[:profiler] == "html"
89
+ printer = RubyProf::GraphHtmlPrinter.new(result)
90
+ printer.print($stdout)
91
+ else
92
+ abort "#{options[:profiler]} not recognized"
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  require_relative "../template"
2
2
 
3
- Template::Version = Gem::Version.new("0.6.0")
3
+ Template::Version = Gem::Version.new("0.6.1")
data/lib/template-ruby.rb CHANGED
@@ -2,7 +2,7 @@ require "stringio"
2
2
  require "timeout"
3
3
  require "zeitwerk"
4
4
  require "code-ruby"
5
- require "template-ruby"
5
+ require "language-ruby"
6
6
 
7
7
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
8
8
  loader.ignore("#{__dir__}/template-ruby.rb")
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.require_paths = ["lib"]
14
14
  s.homepage = "https://github.com/dorianmariefr/template-ruby"
15
15
  s.license = "MIT"
16
+ s.executables = "template"
16
17
 
17
18
  s.add_dependency "zeitwerk", "~> 2"
18
19
  s.add_dependency "code-ruby", "~> 0.6"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -55,13 +55,15 @@ dependencies:
55
55
  description: 'A templating programming language, like "Hello {name}" with {name: "Dorian"}
56
56
  gives "Hello Dorian"'
57
57
  email: dorian@dorianmarie.fr
58
- executables: []
58
+ executables:
59
+ - template
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
62
63
  - ".rspec"
63
64
  - Gemfile
64
65
  - Gemfile.lock
66
+ - bin/template
65
67
  - lib/template-ruby.rb
66
68
  - lib/template.rb
67
69
  - lib/template/node.rb