jrb 0.1.0 → 0.1.1
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.
- data/lib/jrb/template.rb +4 -3
- data/lib/jrb/version.rb +1 -1
- data/test/action_view_test.rb +5 -0
- data/test/dummy/app/controllers/test_controller.rb +0 -2
- data/test/dummy/app/views/test/capture.html.rb +5 -0
- data/test/dummy/config/routes.rb +1 -1
- data/test/{tilt_test.rb → template_test.rb} +36 -5
- metadata +6 -4
data/lib/jrb/template.rb
CHANGED
@@ -5,6 +5,7 @@ module JRB
|
|
5
5
|
self.default_mime_type = "text/html"
|
6
6
|
|
7
7
|
def prepare
|
8
|
+
@buffer_variable = "@output_buffer" # Rails compatibility with capture()
|
8
9
|
@new_buffer = options.delete(:escape_html) == false ? "''" : "ActiveSupport::SafeBuffer.new"
|
9
10
|
end
|
10
11
|
|
@@ -12,10 +13,10 @@ module JRB
|
|
12
13
|
<<-RUBY
|
13
14
|
#{super}
|
14
15
|
__output_buffer = #{@new_buffer}
|
15
|
-
__old_output_buffer, @
|
16
|
+
__old_output_buffer, #{@buffer_variable} = #{@buffer_variable}, __output_buffer
|
16
17
|
instance_eval do
|
17
18
|
def <<(data)
|
18
|
-
@
|
19
|
+
#{@buffer_variable} << data
|
19
20
|
end
|
20
21
|
alias write <<
|
21
22
|
end
|
@@ -26,7 +27,7 @@ module JRB
|
|
26
27
|
def precompiled_postamble(locals)
|
27
28
|
<<-RUBY
|
28
29
|
ensure
|
29
|
-
@
|
30
|
+
#{@buffer_variable} = __old_output_buffer
|
30
31
|
end
|
31
32
|
__output_buffer << __result unless __result == __output_buffer
|
32
33
|
__output_buffer
|
data/lib/jrb/version.rb
CHANGED
data/test/action_view_test.rb
CHANGED
@@ -13,4 +13,9 @@ class ActionViewTest < ActionController::TestCase
|
|
13
13
|
get :index, :name => "<script>unsafe</script>"
|
14
14
|
assert_equal "<html><head></head><body>Hello <script>unsafe</script>!</body></html>", response.body
|
15
15
|
end
|
16
|
+
|
17
|
+
test "capturing content" do
|
18
|
+
get :capture, :name => "John"
|
19
|
+
assert_equal "<html><head></head><body>Hello John!</body></html>", response.body
|
20
|
+
end
|
16
21
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.expand_path("test_helper", File.dirname(__FILE__))
|
3
3
|
require "tempfile"
|
4
4
|
|
5
|
-
class
|
5
|
+
class TemplateTest < ActiveSupport::TestCase
|
6
6
|
test "registered for .rb files" do
|
7
7
|
assert Tilt.mappings["rb"].include?(JRB::Template)
|
8
8
|
end
|
@@ -42,7 +42,7 @@ class TiltTemplateTest < ActiveSupport::TestCase
|
|
42
42
|
scope.instance_variable_set :@name, '<script>Joe</script>'
|
43
43
|
assert_equal "Hey <script>Joe</script>!", template.render(scope)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
test "value equals output buffer" do
|
47
47
|
template = JRB::Template.new { '__output_buffer << "Hey #{name}!"; __output_buffer' }
|
48
48
|
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
@@ -53,6 +53,37 @@ class TiltTemplateTest < ActiveSupport::TestCase
|
|
53
53
|
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
54
54
|
assert_equal "Hey Jane!", template.render(Object.new, :name => 'Jane')
|
55
55
|
end
|
56
|
+
|
57
|
+
test "defining a method" do
|
58
|
+
template = JRB::Template.new {
|
59
|
+
<<-RUBY
|
60
|
+
def greet(target)
|
61
|
+
write "Hey \#{target}!"
|
62
|
+
end
|
63
|
+
greet(name)
|
64
|
+
RUBY
|
65
|
+
}
|
66
|
+
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
67
|
+
end
|
68
|
+
|
69
|
+
test "defining a class" do
|
70
|
+
template = JRB::Template.new {
|
71
|
+
<<-RUBY
|
72
|
+
class Greeter
|
73
|
+
def initialize(target)
|
74
|
+
@target = target
|
75
|
+
end
|
76
|
+
|
77
|
+
def greet
|
78
|
+
"Hey \#{@target}!"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
write Greeter.new(name).greet
|
82
|
+
RUBY
|
83
|
+
}
|
84
|
+
assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
|
85
|
+
end
|
86
|
+
|
56
87
|
test "passing a block for yield" do
|
57
88
|
template = JRB::Template.new { '"Hey #{yield}!"' }
|
58
89
|
assert_equal "Hey Joe!", template.render { 'Joe' }
|
@@ -89,7 +120,7 @@ class TiltTemplateTest < ActiveSupport::TestCase
|
|
89
120
|
end
|
90
121
|
end
|
91
122
|
|
92
|
-
class
|
123
|
+
class CompiledTemplateTest < ActiveSupport::TestCase
|
93
124
|
class Scope
|
94
125
|
end
|
95
126
|
|
@@ -119,7 +150,7 @@ class CompiledTiltTemplateTest < ActiveSupport::TestCase
|
|
119
150
|
scope.instance_variable_set :@name, 'Jane'
|
120
151
|
assert_equal "Hey Jane!", template.render(scope)
|
121
152
|
end
|
122
|
-
|
153
|
+
|
123
154
|
test "automatic output escaping" do
|
124
155
|
template = JRB::Template.new { '"Hey #{@name}!"' }
|
125
156
|
scope = Scope.new
|
@@ -133,7 +164,7 @@ class CompiledTiltTemplateTest < ActiveSupport::TestCase
|
|
133
164
|
scope.instance_variable_set :@name, '<script>Joe</script>'
|
134
165
|
assert_equal "Hey <script>Joe</script>!", template.render(scope)
|
135
166
|
end
|
136
|
-
|
167
|
+
|
137
168
|
test "value equals output buffer" do
|
138
169
|
template = JRB::Template.new { '__output_buffer << "Hey #{name}!"; __output_buffer' }
|
139
170
|
assert_equal "Hey Joe!", template.render(Scope.new, :name => 'Joe')
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: jrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rolf Timmermans
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-25 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tilt
|
@@ -59,14 +59,15 @@ files:
|
|
59
59
|
- test/dummy/app/controllers/test_controller.rb
|
60
60
|
- test/dummy/app/views/layouts/_header.html.rb
|
61
61
|
- test/dummy/app/views/layouts/test.html.rb
|
62
|
+
- test/dummy/app/views/test/capture.html.rb
|
62
63
|
- test/dummy/app/views/test/index.html.rb
|
63
64
|
- test/dummy/config.ru
|
64
65
|
- test/dummy/config/application.rb
|
65
66
|
- test/dummy/config/boot.rb
|
66
67
|
- test/dummy/config/environment.rb
|
67
68
|
- test/dummy/config/routes.rb
|
69
|
+
- test/template_test.rb
|
68
70
|
- test/test_helper.rb
|
69
|
-
- test/tilt_test.rb
|
70
71
|
homepage: https://github.com/voormedia/jrb
|
71
72
|
licenses: []
|
72
73
|
|
@@ -99,11 +100,12 @@ test_files:
|
|
99
100
|
- test/dummy/app/controllers/test_controller.rb
|
100
101
|
- test/dummy/app/views/layouts/_header.html.rb
|
101
102
|
- test/dummy/app/views/layouts/test.html.rb
|
103
|
+
- test/dummy/app/views/test/capture.html.rb
|
102
104
|
- test/dummy/app/views/test/index.html.rb
|
103
105
|
- test/dummy/config.ru
|
104
106
|
- test/dummy/config/application.rb
|
105
107
|
- test/dummy/config/boot.rb
|
106
108
|
- test/dummy/config/environment.rb
|
107
109
|
- test/dummy/config/routes.rb
|
110
|
+
- test/template_test.rb
|
108
111
|
- test/test_helper.rb
|
109
|
-
- test/tilt_test.rb
|