inline_templates 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4320779b14a6754c8f5f27a94d3b7bf4c273057
4
- data.tar.gz: 655e669a9c98ea55ef06aa808b4048970aecaf70
3
+ metadata.gz: cdaa377c8da57c63aa268b4173579fe4b50e6f29
4
+ data.tar.gz: a38406882ed495ef4349f39755ee35701ceaad35
5
5
  SHA512:
6
- metadata.gz: bef27f4d814a5da7585f5f80e07765550eefcf5374c8151019bc28e56c3b843669b34c125b05b8df2c171dd11affa2c3f1a24ff5cc7c7edf81f5773da99d1d76
7
- data.tar.gz: cd4cc209772778510e88765dd149a82a507a368c0bd8479d709842528d816f18d17430c145522bdcf09fe35c8a903b0aa67e5140fbada0fb1bfb2e787ff764b3
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.instance_variable_get(:@_inlinetemplates_context).output_buffer.append = @object
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
- nested.call *args, &block
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 @_inlinetemplates_context, name, *args, &block
43
+ result = @_inlinetemplates_builder.build @_inlinetemplates_view, name, *args, &block
35
44
 
36
45
  else
37
46
  super
@@ -1,3 +1,3 @@
1
1
  module InlineTemplates
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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=\"&#x2713;\" /></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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gridasov