render_me_pretty 0.7.1 → 0.8.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/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/README.md +2 -0
- data/lib/render_me_pretty/erb.rb +17 -4
- data/lib/render_me_pretty/erb/base_handler.rb +9 -4
- data/lib/render_me_pretty/erb/main_error_handler.rb +7 -1
- data/lib/render_me_pretty/erb/syntax_error_handler.rb +10 -1
- data/lib/render_me_pretty/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c5f4662509ff4efce8bde738342f9f97fc5fd8083cb9639006c515e6eb47bdd
|
4
|
+
data.tar.gz: 38b4fdad0e9b9b0c311c10f58e530bf5ef145582fa5982afc7e58f86ab196181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df66e4fd938fd5c8477bd24603f0566838897b798756eda7a4769388d0bc5104d6ed4347c2998b3d3b7918a8c3ef886d35d83e78e04bc78769a20afbd3bcee4
|
7
|
+
data.tar.gz: cac5e1a0a9026838e8ae6d5123f19d7c2388794319d56ebd180d222fc5028c6409a602d8e84ecfb8b77f88b50d2bca27161215bc285b1a02c65a4fbb8e869af2
|
data/.rspec
CHANGED
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
|
+
## [0.8.0]
|
7
|
+
- pull request #1 from tongueroo/layout-support
|
8
|
+
|
6
9
|
## [0.7.1]
|
7
10
|
- trim - mode
|
8
11
|
|
data/README.md
CHANGED
data/lib/render_me_pretty/erb.rb
CHANGED
@@ -51,6 +51,7 @@ module RenderMePretty
|
|
51
51
|
@path = path
|
52
52
|
@init_vars = variables
|
53
53
|
@context = variables.delete(:context)
|
54
|
+
@layout_path = variables.delete(:layout)
|
54
55
|
end
|
55
56
|
|
56
57
|
# Usage:
|
@@ -72,9 +73,21 @@ module RenderMePretty
|
|
72
73
|
context.instance_variable_set('@' + key.to_s, value)
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
+
if @layout_path
|
77
|
+
layout = Tilt::ERBTemplate.new(@layout_path, trim: '-')
|
78
|
+
else
|
79
|
+
# trim mode: https://searchcode.com/codesearch/view/77362792/
|
80
|
+
template = Tilt::ERBTemplate.new(@path, trim: '-')
|
81
|
+
end
|
82
|
+
|
76
83
|
begin
|
77
|
-
|
84
|
+
if @layout_path
|
85
|
+
layout.render(context) do
|
86
|
+
Tilt::ERBTemplate.new(@path, trim: '-').render(context)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
template.render(context)
|
90
|
+
end
|
78
91
|
rescue Exception => e
|
79
92
|
if e.class == SystemExit # allow exit to happen normally
|
80
93
|
raise
|
@@ -99,8 +112,8 @@ module RenderMePretty
|
|
99
112
|
# puts e.backtrace
|
100
113
|
# puts "*" * 30
|
101
114
|
handler = e.is_a?(SyntaxError) ?
|
102
|
-
SyntaxErrorHandler.new(@path,
|
103
|
-
MainErrorHandler.new(@path,
|
115
|
+
SyntaxErrorHandler.new(e, @path, @layout_path) :
|
116
|
+
MainErrorHandler.new(e, @path, @layout_path)
|
104
117
|
io = handler.handle
|
105
118
|
print_result(io)
|
106
119
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class RenderMePretty::Erb
|
2
2
|
class BaseHandler
|
3
|
-
def initialize(path,
|
4
|
-
@path = path
|
3
|
+
def initialize(exception, path, layout_path=nil)
|
5
4
|
@exception = exception
|
5
|
+
@path = path
|
6
|
+
@layout_path = layout_path
|
6
7
|
end
|
7
8
|
|
8
9
|
def handle
|
@@ -16,13 +17,13 @@ class RenderMePretty::Erb
|
|
16
17
|
message = full_message ? ": #{@exception.message}" : ""
|
17
18
|
io.puts "#{@exception.class}#{message}".colorize(:red)
|
18
19
|
|
19
|
-
pretty_path =
|
20
|
+
pretty_path = template_path_with_error.sub(/^\.\//, '')
|
20
21
|
io.puts "Error evaluating ERB template around line #{error_line_number.to_s.colorize(:red)} of: #{pretty_path}:"
|
21
22
|
|
22
23
|
context = 5 # lines of context
|
23
24
|
top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1
|
24
25
|
|
25
|
-
lines = IO.read(
|
26
|
+
lines = IO.read(template_path_with_error).split("\n")
|
26
27
|
spacing = lines.size.to_s.size
|
27
28
|
lines[top..bottom].each_with_index do |line_content, index|
|
28
29
|
current_line_number = top+index+1
|
@@ -37,6 +38,10 @@ class RenderMePretty::Erb
|
|
37
38
|
io
|
38
39
|
end
|
39
40
|
|
41
|
+
def template_path_with_error
|
42
|
+
error_in_layout? ? @layout_path : @path
|
43
|
+
end
|
44
|
+
|
40
45
|
# Method produces a filtered original stack trace that can be appended to
|
41
46
|
# the pretty backtrace output.
|
42
47
|
#
|
@@ -8,9 +8,15 @@ class RenderMePretty::Erb
|
|
8
8
|
def find_line_number
|
9
9
|
lines = @exception.backtrace
|
10
10
|
error_line = lines.select do |line|
|
11
|
-
line.include?(
|
11
|
+
line.include?(template_path_with_error)
|
12
12
|
end.first
|
13
13
|
error_line.split(':')[1].to_i
|
14
14
|
end
|
15
|
+
|
16
|
+
def error_in_layout?
|
17
|
+
# The first line of the backtrace has the template path that errored
|
18
|
+
error_info = @exception.backtrace[0]
|
19
|
+
error_info.include?(@layout_path) if @layout_path
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
@@ -9,7 +9,7 @@ class RenderMePretty::Erb
|
|
9
9
|
#
|
10
10
|
# We will only find the first line number for the error.
|
11
11
|
def find_line_number
|
12
|
-
pattern = Regexp.new("#{
|
12
|
+
pattern = Regexp.new("#{template_path_with_error}:(\\\d+): syntax error")
|
13
13
|
lines = @exception.message.split("\n")
|
14
14
|
found_line = lines.find do |line|
|
15
15
|
line.match(pattern)
|
@@ -17,5 +17,14 @@ class RenderMePretty::Erb
|
|
17
17
|
md = found_line.match(pattern)
|
18
18
|
md[1].to_i # line_number
|
19
19
|
end
|
20
|
+
|
21
|
+
def error_in_layout?
|
22
|
+
# first line has the error info
|
23
|
+
lines = @exception.message.split("\n")
|
24
|
+
error_info = lines.first
|
25
|
+
md = error_info.match(/(.*):(\d+): syntax error/)
|
26
|
+
file = md[1]
|
27
|
+
file == @layout_path
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_me_pretty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|