minimal 0.0.6 → 0.0.7

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.
@@ -3,9 +3,9 @@ class Minimal::Template
3
3
  include ActionView::Template::Handlers::Compilable
4
4
 
5
5
  def compile(template)
6
+ require_dependency template.identifier
6
7
  <<-code
7
8
  @output_buffer = ActiveSupport::SafeBuffer.new
8
- require_dependency "#{template.identifier}"
9
9
  #{template_class_name(template.identifier)}.new(self)._render(local_assigns)
10
10
  code
11
11
  end
@@ -8,10 +8,10 @@ class Minimal::Template
8
8
  link ol option p pre script select span strong table thead tbody tfoot td th tr ul)
9
9
 
10
10
  module Base
11
- attr_reader :view, :buffers, :locals
11
+ attr_accessor :view, :locals
12
12
 
13
13
  def initialize(view = nil)
14
- @view, @buffers, @locals = view, [], {}
14
+ @view, @locals, @_buffer = view, {}, {}
15
15
  end
16
16
 
17
17
  def _render(locals = nil)
@@ -26,24 +26,27 @@ class Minimal::Template
26
26
  end
27
27
 
28
28
  def <<(output)
29
- view.output_buffer << output
29
+ view.output_buffer << output.to_s
30
30
  end
31
31
 
32
32
  def respond_to?(method)
33
- locals.key?(method) || view.instance_variable_defined?("@#{method}") || view.respond_to?(method)
33
+ view.respond_to?(method) || locals.key?(method) || view.instance_variable_defined?("@#{method}")
34
34
  end
35
35
 
36
36
  protected
37
37
 
38
38
  def method_missing(method, *args, &block)
39
- locals.key?(method) ? locals[method] :
39
+ view.respond_to?(method) ? call_view(method, *args, &block) :
40
40
  view.instance_variable_defined?("@#{method}") ? view.instance_variable_get("@#{method}") :
41
- view.respond_to?(method) ? call_view(method, *args, &block) : super
41
+ locals.key?(method) ? locals[method] : super
42
42
  end
43
43
 
44
44
  def call_view(method, *args, &block)
45
- block = lambda { |*a| self << view.with_output_buffer { yield(*a) } } if block
46
- view.send(method, *args, &block).tap { |result| self << result if AUTO_BUFFER =~ method.to_s }
45
+ view.send(method, *args, &block).tap { |result| self << result if auto_buffer?(method) }
46
+ end
47
+
48
+ def auto_buffer?(method)
49
+ @_buffer.key?(method) ? @_buffer[method] : @_buffer[method] = AUTO_BUFFER =~ method.to_s
47
50
  end
48
51
  end
49
52
  include Base
@@ -1,3 +1,3 @@
1
1
  module Minimal
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sven Fuchs