inline_templates 0.0.2 → 0.0.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdaa377c8da57c63aa268b4173579fe4b50e6f29
|
4
|
+
data.tar.gz: a38406882ed495ef4349f39755ee35701ceaad35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a33c47e1f38aa055353a7e7d80b55cbba1acff724803d4ed365f1625d79886ce324db3b67bef5363d0997ad5e70847a6dee57578aa184218898f871fe4d4cb
|
7
|
+
data.tar.gz: 1974e3083ba7b0f2c37e2bc44404733b076c234554a03c7a6647902914f2309b3029cb7dd83bcc895c8d2428fa7894f7ca659c60828dcae880985e92d4ad17c8
|
@@ -10,7 +10,7 @@ module InlineTemplates
|
|
10
10
|
def __inline_templates_object; @object; end
|
11
11
|
|
12
12
|
def ~
|
13
|
-
@buffer.
|
13
|
+
@buffer.inlinetemplates_append @object
|
14
14
|
@object
|
15
15
|
end
|
16
16
|
|
@@ -42,6 +42,8 @@ module InlineTemplates
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.create_proxy_proc(nested, buffer)
|
45
|
+
original_self = self
|
46
|
+
|
45
47
|
proc do |*args, &block|
|
46
48
|
unless @_inlinetemplates_context.nil?
|
47
49
|
::Kernel.puts "OH! block in context!"
|
@@ -50,7 +52,11 @@ module InlineTemplates
|
|
50
52
|
args.map! { |arg| BufferWrapper.wrap arg, buffer }
|
51
53
|
block = BufferWrapper.create_proxy_proc(block, buffer) unless block.nil?
|
52
54
|
|
53
|
-
|
55
|
+
if self.equal? original_self
|
56
|
+
nested.call *args, &block
|
57
|
+
else
|
58
|
+
buffer.inlinetemplates_instance_exec self, *args, &nested
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -2,10 +2,11 @@ module InlineTemplates
|
|
2
2
|
class RenderingContext < BlankObject
|
3
3
|
make_blank :instance_exec, :instance_variable_get, :instance_variable_set
|
4
4
|
|
5
|
-
def initialize(context, locals, builder)
|
5
|
+
def initialize(context, locals, builder, view = nil)
|
6
6
|
@_inlinetemplates_context = context
|
7
7
|
@_inlinetemplates_locals = locals
|
8
8
|
@_inlinetemplates_builder = builder
|
9
|
+
@_inlinetemplates_view = view || context
|
9
10
|
|
10
11
|
context.instance_variables.each do |var|
|
11
12
|
instance_variable_set var, BufferWrapper.wrap(context.instance_variable_get(var), self)
|
@@ -19,6 +20,14 @@ module InlineTemplates
|
|
19
20
|
def h(obj)
|
20
21
|
BufferWrapper.wrap obj.to_s.html_safe, self
|
21
22
|
end
|
23
|
+
|
24
|
+
def inlinetemplates_append(obj)
|
25
|
+
@_inlinetemplates_view.output_buffer.append = obj
|
26
|
+
end
|
27
|
+
|
28
|
+
def inlinetemplates_instance_exec(new_self, *args, &block)
|
29
|
+
RenderingContext.new(new_self, @_inlinetemplates_locals, @_inlinetemplates_builder, @_inlinetemplates_view).instance_exec(*args, &block)
|
30
|
+
end
|
22
31
|
|
23
32
|
def method_missing(name, *args, &block)
|
24
33
|
args.map! &BufferWrapper.method(:unwrap)
|
@@ -31,7 +40,7 @@ module InlineTemplates
|
|
31
40
|
result = @_inlinetemplates_context.__send__ name, *args, &block
|
32
41
|
|
33
42
|
elsif @_inlinetemplates_builder.can_build?(name)
|
34
|
-
result = @_inlinetemplates_builder.build @
|
43
|
+
result = @_inlinetemplates_builder.build @_inlinetemplates_view, name, *args, &block
|
35
44
|
|
36
45
|
else
|
37
46
|
super
|
@@ -88,5 +88,36 @@ describe InlineTemplates do
|
|
88
88
|
end
|
89
89
|
end.should == "<form accept-charset=\"UTF-8\" action=\"foo\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div><input name=\"commit\" type=\"submit\" value=\"Save Foo\" /></form>"
|
90
90
|
end
|
91
|
+
|
92
|
+
it 'supports instance_exec of blocks' do
|
93
|
+
test_class = Class.new do
|
94
|
+
def initialize(template, &block)
|
95
|
+
@template = template
|
96
|
+
@buffer = ""
|
97
|
+
instance_exec &block
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_s
|
101
|
+
@buffer.html_safe
|
102
|
+
end
|
103
|
+
|
104
|
+
def foo
|
105
|
+
@buffer << "test"
|
106
|
+
end
|
107
|
+
|
108
|
+
def bar(&block)
|
109
|
+
@buffer << @template.capture('foo', &block)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
test_rit do
|
114
|
+
~ invoke_helper_like_class(test_class) do
|
115
|
+
foo
|
116
|
+
bar do |arg|
|
117
|
+
~ strong(arg)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end.to_s.should == 'test<strong>foo</strong>'
|
121
|
+
end
|
91
122
|
end
|
92
123
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,10 @@ def test_rit(locals = {}, &template)
|
|
18
18
|
|
19
19
|
view = ActionView::Base.new inner_context, assigns, controller, formats
|
20
20
|
|
21
|
+
def view.invoke_helper_like_class(klass, *args, &block)
|
22
|
+
klass.new(self, *args, &block).to_s
|
23
|
+
end
|
24
|
+
|
21
25
|
InlineTemplates.render view, { virtual_path: "(inline)" }, locals, &template
|
22
26
|
end
|
23
27
|
|