lono 1.0.2 → 1.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/lono/template.rb +33 -6
- data/lib/lono/version.rb +1 -1
- data/spec/lib/lono/template_spec.rb +46 -0
- data/spec/spec_helper.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf114ffb03f191da26a05fc80c4709f2eca37e0
|
4
|
+
data.tar.gz: 942454c20cf254b21236a8508aa71ccecd371da4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4506033e8b011e45aac50e3f1d65ed28990e531d2ff2a39ee036a8587e67f29fe0c69d9128bc79e0d0bd32e733c01a4a95435dd72da7978349fec80cff1d60b0
|
7
|
+
data.tar.gz: 56d90a0893be4bf743154aca21647ada77b9dfef3668a457e33a7b9a6ecc369e13d4a57ac625bf4193d80d4bc06d26cac77ec1f59890f62c8a17d490d02462a2
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [1.1.0]
|
7
|
+
- useful ERB render error messages
|
8
|
+
|
6
9
|
## [1.0.2]
|
7
10
|
- remove blank lines from yaml output
|
8
11
|
|
data/lib/lono/template.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'json'
|
3
|
-
require
|
3
|
+
require 'base64'
|
4
4
|
|
5
5
|
module Lono
|
6
6
|
class Template
|
@@ -16,7 +16,7 @@ module Lono
|
|
16
16
|
def build
|
17
17
|
instance_eval(&@block)
|
18
18
|
template = IO.read(@source)
|
19
|
-
erb_result(template)
|
19
|
+
erb_result(@source, template)
|
20
20
|
end
|
21
21
|
|
22
22
|
def source(path)
|
@@ -33,7 +33,7 @@ module Lono
|
|
33
33
|
path = "#{@options[:project_root]}/templates/partial/#{path}"
|
34
34
|
template = IO.read(path)
|
35
35
|
variables(vars)
|
36
|
-
result = erb_result(template)
|
36
|
+
result = erb_result(path, template)
|
37
37
|
result = indent(result, options[:indent]) if options[:indent]
|
38
38
|
result
|
39
39
|
end
|
@@ -45,15 +45,42 @@ module Lono
|
|
45
45
|
end.join("\n")
|
46
46
|
end
|
47
47
|
|
48
|
-
def erb_result(template)
|
49
|
-
|
48
|
+
def erb_result(path, template)
|
49
|
+
begin
|
50
|
+
ERB.new(template, nil, "-").result(binding)
|
51
|
+
rescue Exception => e
|
52
|
+
puts e
|
53
|
+
|
54
|
+
# how to know where ERB stopped? - https://www.ruby-forum.com/topic/182051
|
55
|
+
# syntax errors have the (erb):xxx info in e.message
|
56
|
+
# undefined variables have (erb):xxx info in e.backtrac
|
57
|
+
error_info = e.message.split("\n").grep(/\(erb\)/)[0]
|
58
|
+
error_info ||= e.backtrace.grep(/\(erb\)/)[0]
|
59
|
+
raise unless error_info # unable to find the (erb):xxx: error line
|
60
|
+
line = error_info.split(':')[1].to_i
|
61
|
+
puts "Error evaluating ERB template on line #{line.to_s.colorize(:red)} of: #{path.sub(/^\.\//, '')}"
|
62
|
+
|
63
|
+
template_lines = template.split("\n")
|
64
|
+
context = 5 # lines of context
|
65
|
+
top, bottom = [line-context, 0].max, line+context
|
66
|
+
spacing = template_lines.size.to_s.size
|
67
|
+
template_lines[top..bottom].each_with_index do |line_content, index|
|
68
|
+
line_number = top+index+1
|
69
|
+
if line_number == line
|
70
|
+
printf("%#{spacing}d %s\n".colorize(:red), line_number, line_content)
|
71
|
+
else
|
72
|
+
printf("%#{spacing}d %s\n", line_number, line_content)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
exit 1 unless ENV['TEST']
|
76
|
+
end
|
50
77
|
end
|
51
78
|
|
52
79
|
def user_data(path, vars={})
|
53
80
|
path = "#{@options[:project_root]}/templates/user_data/#{path}"
|
54
81
|
template = IO.read(path)
|
55
82
|
variables(vars)
|
56
|
-
result = erb_result(template)
|
83
|
+
result = erb_result(path, template)
|
57
84
|
output = []
|
58
85
|
result.split("\n").each do |line|
|
59
86
|
output += transform(line)
|
data/lib/lono/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path("../../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Lono::Template do
|
4
|
+
let(:template) do
|
5
|
+
block = Proc.new {}
|
6
|
+
template = Lono::Template.new("output_name.yml", block)
|
7
|
+
|
8
|
+
# override the puts and printf methods within the test
|
9
|
+
def template.messages
|
10
|
+
@messages
|
11
|
+
end
|
12
|
+
|
13
|
+
def template.puts(msg)
|
14
|
+
@messages ||= []
|
15
|
+
@messages << msg
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def template.printf(*args)
|
20
|
+
@messages ||= []
|
21
|
+
@messages << args
|
22
|
+
end
|
23
|
+
|
24
|
+
template
|
25
|
+
end
|
26
|
+
|
27
|
+
context "valid erb template" do
|
28
|
+
it "should be able to lono generate" do
|
29
|
+
template.erb_result("path", "template")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "invalid erb template" do
|
34
|
+
it "should print out useful error message about undefined variable" do
|
35
|
+
template.erb_result("path", "variable does not exist\n<% variable %>\nanother line")
|
36
|
+
errors = template.messages.grep(/Error evaluating ERB template on line/)
|
37
|
+
expect(errors).not_to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should print out useful error message about syntax error" do
|
41
|
+
template.erb_result("path", "<%s dsfds ?%>\nanother line")
|
42
|
+
errors = template.messages.grep(/Error evaluating ERB template on line/)
|
43
|
+
expect(errors).not_to be_empty
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- spec/fixtures/cfn.json
|
233
233
|
- spec/lib/lono/dsl_spec.rb
|
234
234
|
- spec/lib/lono/new_spec.rb
|
235
|
+
- spec/lib/lono/template_spec.rb
|
235
236
|
- spec/lib/lono_spec.rb
|
236
237
|
- spec/spec_helper.rb
|
237
238
|
homepage: http://github.com/tongueroo/lono
|
@@ -263,5 +264,6 @@ test_files:
|
|
263
264
|
- spec/fixtures/cfn.json
|
264
265
|
- spec/lib/lono/dsl_spec.rb
|
265
266
|
- spec/lib/lono/new_spec.rb
|
267
|
+
- spec/lib/lono/template_spec.rb
|
266
268
|
- spec/lib/lono_spec.rb
|
267
269
|
- spec/spec_helper.rb
|