Module: AnyView::TiltBase
- Defined in:
- lib/any_view/tilt_base.rb
Overview
Provides capture and concat methods for use inside templates with the Tilt gem.
Defined Under Namespace
Classes: CaptureMethodNotFound, ContentMethodNotFound, Error
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.capture_method_for(template) ⇒ Object
43
44
45
|
# File 'lib/any_view/tilt_base.rb', line 43
def capture_method_for(template)
capture_methods[template]
end
|
.capture_methods ⇒ Object
39
40
41
|
# File 'lib/any_view/tilt_base.rb', line 39
def capture_methods
@capture_methods ||= {}
end
|
.concat_method_for(template) ⇒ Object
47
48
49
|
# File 'lib/any_view/tilt_base.rb', line 47
def concat_method_for(template)
concat_methods[template]
end
|
.concat_methods ⇒ Object
Keeps track of the concatenation methods for each template type. If you have your own template types, then you should add them here
35
36
37
|
# File 'lib/any_view/tilt_base.rb', line 35
def concat_methods
@concat_methods ||= {}
end
|
.included(base) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/any_view/tilt_base.rb', line 25
def self.included(base)
base.class_eval do
attr_writer :template_type unless self.method_defined?(:template_type=)
attr_reader :template_type unless self.method_defined?(:template_type)
end
end
|
Instance Method Details
#_erb_capture(*args, &block) ⇒ Object
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/any_view/tilt_base.rb', line 81
def _erb_capture(*args, &block)
_saved_buffer = _erb_buffer
_set_erb_buffer ''
block.call(*args)
ret = _erb_buffer
_set_erb_buffer _saved_buffer
ret
end
|
#_erb_concat(string) ⇒ Object
106
107
108
|
# File 'lib/any_view/tilt_base.rb', line 106
def _erb_concat(string)
_erb_buffer << string
end
|
#_erubis_capture(*args, &block) ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/any_view/tilt_base.rb', line 92
def _erubis_capture(*args, &block)
_saved_buffer = _erubis_buffer
_set_erubis_buffer = ''
block.call(*args)
ret = _erb_buffer
_set_erubis_buffer _saved_buffer
end
|
#_erubis_concat(string) ⇒ Object
110
111
112
|
# File 'lib/any_view/tilt_base.rb', line 110
def _erubis_concat(string)
_erubis_buffer << string
end
|
#_haml_capture(*args, &block) ⇒ Object
75
76
77
78
79
|
# File 'lib/any_view/tilt_base.rb', line 75
def _haml_capture(*args, &block)
with_haml_buffer(Haml::Buffer.new(nil, :encoding => "UTF-8")) do
capture_haml(*args, &block)
end
end
|
#_haml_concat(string) ⇒ Object
102
103
104
|
# File 'lib/any_view/tilt_base.rb', line 102
def _haml_concat(string)
haml_concat(string)
end
|
#capture_content(*args, &blk) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/any_view/tilt_base.rb', line 60
def capture_content(*args, &blk)
opts = args.
capture_method = AnyView::TiltBase.capture_method_for(template_type)
raise CaptureMethodNotFound, "Capture Method not found for Template Type: #{opts[:template_type].inspect}" unless capture_method
send(capture_method, *args, &blk)
end
|
#concat_content(string, opts = {}) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/any_view/tilt_base.rb', line 68
def concat_content(string, opts = {})
concat_method = AnyView::TiltBase.concat_method_for(template_type)
raise ConcatMethodNotFound, "Concat Method not found for Template Type: #{opts[:template_type].inspect}" unless concat_method
send(concat_method, string)
end
|