inline_templates 0.0.1 → 0.0.2

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: 1391230187758595f59ccb744dbb3ccb124aef1d
4
- data.tar.gz: ade328c124f06942ada52b3f6198f5038ec90a9e
3
+ metadata.gz: e4320779b14a6754c8f5f27a94d3b7bf4c273057
4
+ data.tar.gz: 655e669a9c98ea55ef06aa808b4048970aecaf70
5
5
  SHA512:
6
- metadata.gz: 19f7c6edded139cd6b9e8fa0534ea9725bbff35f07e5c526ea901469a947183998845a3bc3e1c77592407a8205b39cbc7002fc11d0bb5fc9af6e5a8e7bd1dde1
7
- data.tar.gz: b8f383aec61fd96b5a25a121c57f7cf70de16597af31735eaeb9cce2d09ee127e09cf4820fd1a5689dd9a30b5898a723a459787252764bf50afdb533f0b7b7a4
6
+ metadata.gz: bef27f4d814a5da7585f5f80e07765550eefcf5374c8151019bc28e56c3b843669b34c125b05b8df2c171dd11affa2c3f1a24ff5cc7c7edf81f5773da99d1d76
7
+ data.tar.gz: cd4cc209772778510e88765dd149a82a507a368c0bd8479d709842528d816f18d17430c145522bdcf09fe35c8a903b0aa67e5140fbada0fb1bfb2e787ff764b3
@@ -10,12 +10,13 @@ module InlineTemplates
10
10
  def __inline_templates_object; @object; end
11
11
 
12
12
  def ~
13
- @buffer.append = @object
13
+ @buffer.instance_variable_get(:@_inlinetemplates_context).output_buffer.append = @object
14
14
  @object
15
15
  end
16
16
 
17
17
  def method_missing(name, *args, &block)
18
18
  args.map! &BufferWrapper.method(:unwrap)
19
+ block = BufferWrapper.create_proxy_proc(block, @buffer) unless block.nil?
19
20
 
20
21
  BufferWrapper.wrap @object.__send__(name, *args, &block), @buffer
21
22
  end
@@ -39,5 +40,18 @@ module InlineTemplates
39
40
  obj
40
41
  end
41
42
  end
43
+
44
+ def self.create_proxy_proc(nested, buffer)
45
+ proc do |*args, &block|
46
+ unless @_inlinetemplates_context.nil?
47
+ ::Kernel.puts "OH! block in context!"
48
+ end
49
+
50
+ args.map! { |arg| BufferWrapper.wrap arg, buffer }
51
+ block = BufferWrapper.create_proxy_proc(block, buffer) unless block.nil?
52
+
53
+ nested.call *args, &block
54
+ end
55
+ end
42
56
  end
43
57
  end
@@ -1,28 +1,28 @@
1
1
  module InlineTemplates
2
2
  class RenderingContext < BlankObject
3
- make_blank :instance_exec, :instance_variable_set
3
+ make_blank :instance_exec, :instance_variable_get, :instance_variable_set
4
4
 
5
5
  def initialize(context, locals, builder)
6
6
  @_inlinetemplates_context = context
7
7
  @_inlinetemplates_locals = locals
8
- @_inlinetemplates_evaluating = true
9
8
  @_inlinetemplates_builder = builder
10
9
 
11
10
  context.instance_variables.each do |var|
12
- instance_variable_set var, context.instance_variable_get(var)
11
+ instance_variable_set var, BufferWrapper.wrap(context.instance_variable_get(var), self)
13
12
  end
14
13
  end
15
14
 
16
15
  def t(obj)
17
- BufferWrapper.wrap obj.to_s, @_inlinetemplates_context.output_buffer
16
+ BufferWrapper.wrap obj.to_s, self
18
17
  end
19
18
 
20
19
  def h(obj)
21
- BufferWrapper.wrap obj.to_s.html_safe, @_inlinetemplates_context.output_buffer
20
+ BufferWrapper.wrap obj.to_s.html_safe, self
22
21
  end
23
22
 
24
23
  def method_missing(name, *args, &block)
25
24
  args.map! &BufferWrapper.method(:unwrap)
25
+ block = BufferWrapper.create_proxy_proc(block, self) unless block.nil?
26
26
 
27
27
  if @_inlinetemplates_locals.include?(name) && args.length == 0
28
28
  result = @_inlinetemplates_locals[name]
@@ -37,7 +37,7 @@ module InlineTemplates
37
37
  super
38
38
  end
39
39
 
40
- BufferWrapper.wrap result, @_inlinetemplates_context.output_buffer
40
+ BufferWrapper.wrap result, self
41
41
  end
42
42
  end
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module InlineTemplates
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -77,8 +77,16 @@ describe InlineTemplates do
77
77
 
78
78
  it 'passes instance variables' do
79
79
  test_rit do
80
- ~ t(@virtual_path)
80
+ ~ @virtual_path
81
81
  end.should == "(inline)"
82
82
  end
83
+
84
+ it 'wraps output of builders' do
85
+ test_rit do
86
+ ~ form_for(:foo, :url => "foo", :authenticity_token => false) do |f|
87
+ ~ f.submit
88
+ end
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
+ end
83
91
  end
84
92
  end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gridasov