render_me_pretty 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e4af73e4c239f8f3bff66c3818c43a4e741a09442148c2fa2c56e551f7ac3ed
4
- data.tar.gz: 2699cbcd5a14731255b3d48f510ccba48bbca15bf1bbc82cf965a1ba29ec355e
3
+ metadata.gz: 8c5f4662509ff4efce8bde738342f9f97fc5fd8083cb9639006c515e6eb47bdd
4
+ data.tar.gz: 38b4fdad0e9b9b0c311c10f58e530bf5ef145582fa5982afc7e58f86ab196181
5
5
  SHA512:
6
- metadata.gz: 0dde0c45916b0704ef3610b2d85ed19ec208c38e221b75d7039bcf90deac33e971d7cdb032d8348512de01d8ce6b473f63786898bf6c40dc961e4555823f24ea
7
- data.tar.gz: 297eaf75a2780878ef937e88f264c48ce775c31478d3b185458110b88618fa52c21a2ffa50c95bf3ebbc85af626980e1f854ec5336760cb0d31f1519e7810f5a
6
+ metadata.gz: 0df66e4fd938fd5c8477bd24603f0566838897b798756eda7a4769388d0bc5104d6ed4347c2998b3d3b7918a8c3ef886d35d83e78e04bc78769a20afbd3bcee4
7
+ data.tar.gz: cac5e1a0a9026838e8ae6d5123f19d7c2388794319d56ebd180d222fc5028c6409a602d8e84ecfb8b77f88b50d2bca27161215bc285b1a02c65a4fbb8e869af2
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --require spec_helper
2
+ --format documentation
3
+ --require spec_helper
@@ -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
@@ -1,5 +1,7 @@
1
1
  # Render Me Pretty
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/tongueroo/render_me_pretty.svg?style=svg)](https://circleci.com/gh/tongueroo/render_me_pretty)
4
+
3
5
  Let's say you have an error in your ERB template:
4
6
 
5
7
  ```
@@ -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
- template = Tilt::ERBTemplate.new(@path, trim: '-')
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
- template.render(context)
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, e) :
103
- MainErrorHandler.new(@path, e)
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, exception)
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 = @path.sub(/^\.\//, '')
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(@path).split("\n")
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?(@path)
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("#{@path}:(\\\d+): syntax error")
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
@@ -1,3 +1,3 @@
1
1
  module RenderMePretty
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  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.7.1
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-26 00:00:00.000000000 Z
11
+ date: 2018-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport