template-ruby 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/template +94 -0
- data/lib/template/version.rb +1 -1
- data/lib/template-ruby.rb +1 -1
- data/template-ruby.gemspec +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2083870212319aa2d41c2e5b7f214fefd09aa04ff4676adc4c47f248047c12b
|
4
|
+
data.tar.gz: 8b789135855a027e8b5dccefdeae23e9898a887e57dd9657092f121f2bb2b22b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/template/version.rb
CHANGED
data/lib/template-ruby.rb
CHANGED
data/template-ruby.gemspec
CHANGED
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.
|
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
|