macros4cuke 0.1.06 → 0.1.07
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +5 -0
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/template-engine.rb +2 -12
- metadata +1 -1
data/HISTORY.md
CHANGED
@@ -9,7 +9,6 @@ module Macros4Cuke # Module used as a namespace
|
|
9
9
|
class TemplateEngine
|
10
10
|
|
11
11
|
def self.parse(aTextLine)
|
12
|
-
#return [] if aTextLine.empty?
|
13
12
|
scanner = StringScanner.new(aTextLine)
|
14
13
|
result = []
|
15
14
|
|
@@ -17,31 +16,22 @@ class TemplateEngine
|
|
17
16
|
# Scan tag at current position...
|
18
17
|
tag_literal = scanner.scan(/<(?:[^\\<>]|\\.)*>/)
|
19
18
|
result << [:dynamic, tag_literal.gsub(/^<|>$/, '')] unless tag_literal.nil?
|
20
|
-
# TODO: remove next line
|
21
|
-
p tag_literal unless tag_literal.nil?
|
22
19
|
|
23
20
|
# ... or scan plain text at current position
|
24
21
|
text_literal = scanner.scan(/(?:[^\\<>]|\\.)+/)
|
25
22
|
result << [:static, text_literal] unless text_literal.nil?
|
26
|
-
# TODO: remove next line
|
27
|
-
p text_literal unless text_literal.nil?
|
28
23
|
|
29
24
|
if tag_literal.nil? && text_literal.nil?
|
30
25
|
# Unsuccessful scanning: we have improperly balanced chevrons.
|
31
26
|
# We will analyze the opening and closing chevrons...
|
32
|
-
|
33
|
-
no_escaped = aTextLine.gsub(/\\<|\\>/, "--") # First: replace escaped chevron(s)
|
34
|
-
p no_escaped
|
27
|
+
no_escaped = aTextLine.gsub(/\\[<>]/, "--") # First: replace escaped chevron(s)
|
35
28
|
unbalance = 0 # = count of < - count of > (can only be 0 or -temporarily- 1)
|
36
29
|
|
37
30
|
no_escaped.scan(/(.)/) do |match|
|
38
|
-
p match
|
39
31
|
case match[0]
|
40
32
|
when '<'
|
41
|
-
p "found <"
|
42
33
|
unbalance += 1
|
43
34
|
when '>'
|
44
|
-
p 'found >'
|
45
35
|
unbalance -= 1
|
46
36
|
end
|
47
37
|
|
@@ -50,7 +40,7 @@ class TemplateEngine
|
|
50
40
|
end
|
51
41
|
|
52
42
|
raise StandardError, "Missing closing chevron '>'." if unbalance == 1
|
53
|
-
raise StandardError, "
|
43
|
+
raise StandardError, "Cannot parse:\n'#{aTextLine}'"
|
54
44
|
end
|
55
45
|
end
|
56
46
|
|