zrb 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zrb.rb +13 -13
- data/lib/zrb/version.rb +1 -1
- data/test/test_zrb.rb +32 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca74f2e1175ee6aea15e0f2eab11178c0b510a6d
|
4
|
+
data.tar.gz: d894764442ddb832d1a8f078a3ee67dd7557085d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f888660ba7a9d00df41066a320931d8eda2aa8008a633742e4ae069dc721d0de38eea3c64e89809120835fb084b4f27e0bf22edd4417bfc0ffea2ad08130b334
|
7
|
+
data.tar.gz: 9b1ccca72be9290cd7d5f5b9f79446ce46462a7faf4d7e787272360bc73c6d89b23c2c8574587a1b5a4425f32bf43f0c98ff3246f902c1a2bef0b9262bed202a
|
data/lib/zrb.rb
CHANGED
@@ -36,7 +36,7 @@ module ZRB
|
|
36
36
|
while pos < data.size
|
37
37
|
match = data.match(TOKEN, pos)
|
38
38
|
raise SyntaxError, "#{filename}:#{lineno}: parse error" unless match
|
39
|
-
all, text, expr,
|
39
|
+
all, text, expr, _, statement, statement_space = *match
|
40
40
|
pos += all.size
|
41
41
|
|
42
42
|
yield :text, text unless text.empty?
|
@@ -59,8 +59,6 @@ module ZRB
|
|
59
59
|
pos = closing_pos + 1
|
60
60
|
end
|
61
61
|
|
62
|
-
yield :newline if statement_space
|
63
|
-
|
64
62
|
if statement
|
65
63
|
case statement[0]
|
66
64
|
when ?=
|
@@ -73,6 +71,8 @@ module ZRB
|
|
73
71
|
yield :statement, statement
|
74
72
|
end
|
75
73
|
end
|
74
|
+
|
75
|
+
yield :newline if statement_space
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -88,7 +88,7 @@ module ZRB
|
|
88
88
|
|
89
89
|
def ensure_string
|
90
90
|
if @state != :string
|
91
|
-
source << 'buffer
|
91
|
+
source << 'buffer << "'
|
92
92
|
@state = :string
|
93
93
|
end
|
94
94
|
end
|
@@ -106,7 +106,7 @@ module ZRB
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def append_ruby(ruby)
|
109
|
-
source << '"
|
109
|
+
source << '";' if @state == :string
|
110
110
|
source << ruby
|
111
111
|
@state = :ruby
|
112
112
|
end
|
@@ -129,11 +129,15 @@ module ZRB
|
|
129
129
|
when :expression
|
130
130
|
append_expr(value)
|
131
131
|
when :block_expression
|
132
|
-
append_ruby("buffer.
|
132
|
+
append_ruby("buffer.safe_append=#{value};")
|
133
133
|
when :statement
|
134
134
|
append_ruby("#{value};")
|
135
135
|
when :newline
|
136
136
|
append_newline
|
137
|
+
when :comment
|
138
|
+
# no nothing
|
139
|
+
else
|
140
|
+
raise "internal error: unknown parsing type"
|
137
141
|
end
|
138
142
|
end
|
139
143
|
|
@@ -160,17 +164,13 @@ module ZRB
|
|
160
164
|
other.to_s
|
161
165
|
end
|
162
166
|
|
163
|
-
def
|
167
|
+
def safe_append=(other)
|
164
168
|
self << escape(other)
|
165
169
|
end
|
166
170
|
|
167
|
-
def
|
168
|
-
self << other
|
169
|
-
end
|
170
|
-
|
171
|
-
def capture(blk)
|
171
|
+
def capture(blk, *args)
|
172
172
|
start = self.size
|
173
|
-
blk.call
|
173
|
+
blk.call(*args)
|
174
174
|
ensure
|
175
175
|
return self.slice!(start..-1)
|
176
176
|
end
|
data/lib/zrb/version.rb
CHANGED
data/test/test_zrb.rb
CHANGED
@@ -67,6 +67,33 @@ world
|
|
67
67
|
assert_equal "Hello second!", @res2.strip
|
68
68
|
end
|
69
69
|
|
70
|
+
def test_line_numbers
|
71
|
+
t = Template.new { <<-EOF }
|
72
|
+
<? raise if a == 1 ?>
|
73
|
+
hello
|
74
|
+
<? raise if a == 3 ?>
|
75
|
+
<? if a == 6 ?>
|
76
|
+
bar
|
77
|
+
<? raise ?>
|
78
|
+
<? elsif a == 8 ?>
|
79
|
+
<? raise ?>
|
80
|
+
wat
|
81
|
+
<? end ?>
|
82
|
+
hello
|
83
|
+
world
|
84
|
+
<? raise ?>
|
85
|
+
EOF
|
86
|
+
|
87
|
+
[1, 3, 6, 8, 13].each do |lineno|
|
88
|
+
@buffer = Buffer.new
|
89
|
+
exc = assert_raises do
|
90
|
+
t.render(self, :a => lineno)
|
91
|
+
end
|
92
|
+
actual = exc.backtrace[0][/:(\d+)/, 1].to_i
|
93
|
+
assert_equal lineno, actual
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
70
97
|
def test_expr
|
71
98
|
@buffer = Buffer.new
|
72
99
|
t = Template.new { 'Hello #{1 + 1}' }
|
@@ -74,18 +101,18 @@ world
|
|
74
101
|
end
|
75
102
|
|
76
103
|
def form_for(&blk)
|
77
|
-
"<form>#{@form_buffer.capture(blk).strip}</form>"
|
104
|
+
"<form>#{@form_buffer.capture(blk, "/awesome").strip}</form>"
|
78
105
|
end
|
79
106
|
|
80
107
|
def test_block_expr
|
81
108
|
@form_buffer = @buffer = Buffer.new
|
82
|
-
t = Template.new { <<-EOF }
|
83
|
-
<?= form_for do ?>
|
84
|
-
Hello
|
109
|
+
t = Template.new { <<-'EOF' }
|
110
|
+
<?= form_for do |path| ?>
|
111
|
+
Hello #{path}!
|
85
112
|
<? end ?>
|
86
113
|
EOF
|
87
114
|
|
88
|
-
assert_equal "<form>Hello
|
115
|
+
assert_equal "<form>Hello /awesome!</form>", t.render(self).strip
|
89
116
|
end
|
90
117
|
|
91
118
|
def test_html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
58
|
+
rubygems_version: 2.6.8
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Simple template engine
|