markdown-expander 0.6.0 → 0.7.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
  SHA1:
3
- metadata.gz: 94078f341de6bb0794aa103efc520773d9766abd
4
- data.tar.gz: 9073385427a5aa7911b7406f83f79615041a6043
3
+ metadata.gz: 61595a9cdbd9373019eccd421e379de6cda1edfb
4
+ data.tar.gz: 858f94a729be5106f0a260a6688503c9ea6fdf34
5
5
  SHA512:
6
- metadata.gz: f1b219b2dce87acce2fa2c117ec632ea84d13de1171b46bb65fc80741aa018b045b22f319b66dda193340c63079fbabc66f2fe2738e8585e3a45b0056d089033
7
- data.tar.gz: f665687f5506bf48af177b4e78910dd7cc56fa005551accdd0cc1e9d9696222c1c2a11ec845aa326f9e089fcfee37c7d5e3914e6e884a6d2a3fe5669daa42d01
6
+ metadata.gz: c5b7813853e5fdf883c7d8c390b804500075f2c75e15a65811682f2a25c85725f76ef29708d1a04fff54c33a4157c93c41cb44622fbed838db5522302b7abf16
7
+ data.tar.gz: 0ac90bf8d84e868cc8821ecaf61c56d3d16ce9ba2a5f6279c2b0b0b94788a02188c5b0207988605bd9f0a0bfede7a5e806c1d7960516380a6529b83257915746
data/README.md CHANGED
@@ -38,7 +38,7 @@ MarkdownExpander::Expander.new(
38
38
  "# Title: {{thing.title}}"
39
39
  ).render(
40
40
  thing: {title: "Hello"}
41
- ).body
41
+ )
42
42
  #=> "# Title: Hello"
43
43
  ```
44
44
 
@@ -55,7 +55,7 @@ TEMPLATE
55
55
 
56
56
  MarkdownExpander::Expander.new(template).render(
57
57
  stuff: [ {title: "First!"}, {title: "Second!"} ]
58
- ).body
58
+ )
59
59
  #=> "# First!\n# Second!\n"
60
60
  ```
61
61
 
@@ -74,6 +74,6 @@ TEMPLATE
74
74
 
75
75
  MarkdownExpander::Expander.new(template).render(
76
76
  animals: [ {name: "dogs"}, {name: "cats"} ]
77
- ).body
77
+ )
78
78
  #=> "# cats are the best!!!!!\n"
79
79
  ```
@@ -39,7 +39,7 @@ MarkdownExpander::Expander.new(
39
39
  "# Title: {{thing.title}}"
40
40
  ).render(
41
41
  thing: {title: "Hello"}
42
- ).body
42
+ )
43
43
  #=> "# Title: Hello"
44
44
  :end:
45
45
  ```
@@ -58,7 +58,7 @@ TEMPLATE
58
58
 
59
59
  MarkdownExpander::Expander.new(template).render(
60
60
  stuff: [ {title: "First!"}, {title: "Second!"} ]
61
- ).body
61
+ )
62
62
  #=> "# First!\n# Second!\n"
63
63
  :end:
64
64
  ```
@@ -79,7 +79,7 @@ TEMPLATE
79
79
 
80
80
  MarkdownExpander::Expander.new(template).render(
81
81
  animals: [ {name: "dogs"}, {name: "cats"} ]
82
- ).body
82
+ )
83
83
  #=> "# cats are the best!!!!!\n"
84
84
  :end:
85
85
  ```
@@ -41,25 +41,38 @@ module MarkdownExpander
41
41
  end
42
42
  end
43
43
  end
44
+ current_line += 1
44
45
  end
45
46
 
46
- errors = []
47
- if node != root
48
- if node.element.class == IfStart
49
- errors << "LINE #{node.line_number}: if statement has no end"
50
- elsif node.element.class == LoopStart
51
- errors << "LINE #{node.line_number}: loop has no end"
52
- end
47
+ parse_error = if node != root
48
+ if node.element.class == IfStart
49
+ MarkdownExpandError.new(node.line_number, "if statement has no end")
50
+ elsif node.element.class == LoopStart
51
+ MarkdownExpandError.new(node.line_number, "loop has no end")
52
+ end
53
+ end
54
+
55
+ if parse_error.nil? == false
56
+ raise parse_error
53
57
  end
54
58
 
55
- if errors.any?
56
- RenderResult.new(nil, errors)
57
- else
58
- begin
59
- RenderResult.new(evaluate_nodes(root, scope), [])
60
- rescue ExpressionDrillDownError => e
61
- RenderResult.new(nil, ["LINE #{e.node.line_number}: expression '#{e.expression}' could not be evaluated"])
62
- end
59
+ begin
60
+ evaluate_nodes(root, scope)
61
+ rescue ExpressionDrillDownError => e
62
+ raise MarkdownExpandError.new(
63
+ e.node.line_number,
64
+ "expression '#{e.expression}' could not be evaluated",
65
+ )
66
+ end
67
+ end
68
+
69
+ class MarkdownExpandError < StandardError
70
+ attr_reader :line_number
71
+ attr_reader :message
72
+
73
+ def initialize line_number, message
74
+ @line_number = line_number
75
+ @message = message
63
76
  end
64
77
  end
65
78
 
@@ -110,15 +123,6 @@ module MarkdownExpander
110
123
  lines.join("")
111
124
  end
112
125
 
113
- class RenderResult
114
- attr_reader :body
115
- attr_reader :errors
116
- def initialize body, errors
117
- @body = body
118
- @errors = errors
119
- end
120
- end
121
-
122
126
  class Node
123
127
  attr_accessor :parent
124
128
  attr_accessor :children
@@ -1,3 +1,3 @@
1
1
  module MarkdownExpander
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown-expander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vos