Module: Erector::Rails::Helpers
- Includes:
- ActionController::UrlWriter
- Defined in:
- lib/erector/rails2/extensions/rails_helpers.rb
Class Method Summary
collapse
Instance Method Summary
collapse
-
#fields_for(record_or_name_or_array, *args, &proc) ⇒ Object
-
#flash ⇒ Object
-
#form_for(record_or_name_or_array, *args, &proc) ⇒ Object
-
#link_to(*args, &block) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
Delegate to non-markup producing helpers via method_missing, returning their result directly.
-
#render(*args, &block) ⇒ Object
-
#respond_to?(name) ⇒ Boolean
Since we delegate method_missing to parent, we need to delegate respond_to? as well.
-
#session ⇒ Object
-
#url_for(*args) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegate to non-markup producing helpers via method_missing, returning their result directly.
125
126
127
128
129
130
131
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 125
def method_missing(name, *args, &block)
if parent.respond_to?(name)
parent.send(name, *args, &block)
else
super
end
end
|
Class Method Details
.def_block_rails_helper(method_name) ⇒ Object
Wrappers for rails helpers that produce markup, concatenating directly to the output buffer if given a block, returning a string otherwise. In the latter case, Erector needs to manually output their result.
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 91
def self.def_block_rails_helper(method_name)
module_eval(<<-METHOD_DEF, __FILE__, __LINE__+1)
def #{method_name}(*args, &block)
if block_given?
parent.#{method_name}(*args, &block)
else
rails_helper_output = parent.#{method_name}(*args, &block)
# i wonder why this is text and not rawtext
text rails_helper_output
end
end
METHOD_DEF
end
|
.def_simple_rails_helper(method_name) ⇒ Object
Wrappers for rails helpers that produce markup. Erector needs to manually emit their result.
13
14
15
16
17
18
19
20
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 13
def self.def_simple_rails_helper(method_name)
module_eval(<<-METHOD_DEF, __FILE__, __LINE__+1)
def #{method_name}(*args, &block)
# i wonder why this is text and not rawtext
text parent.#{method_name}(*args, &block)
end
METHOD_DEF
end
|
Instance Method Details
#fields_for(record_or_name_or_array, *args, &proc) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 154
def fields_for(record_or_name_or_array, *args, &proc)
options = args.
options[:builder] ||= ::Erector::RailsFormBuilder
args.push(options)
parent.fields_for(record_or_name_or_array, *args, &proc)
end
|
#flash ⇒ Object
161
162
163
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 161
def flash
parent.controller.send(:flash)
end
|
147
148
149
150
151
152
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 147
def form_for(record_or_name_or_array, *args, &proc)
options = args.
options[:builder] ||= ::Erector::RailsFormBuilder
args.push(options)
parent.form_for(record_or_name_or_array, *args, &proc)
end
|
#link_to(*args, &block) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 112
def link_to(*args, &block)
if block_given?
parent.link_to(*args, &block)
else
args[0] = CGI.escapeHTML(args[0])
rails_helper_output = parent.link_to(*args, &block)
text rails_helper_output
end
end
|
#render(*args, &block) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 139
def render(*args, &block)
captured = parent.capture do
parent.concat(parent.render(*args, &block))
parent.output_buffer.to_s
end
rawtext(captured)
end
|
#respond_to?(name) ⇒ Boolean
Since we delegate method_missing to parent, we need to delegate respond_to? as well.
135
136
137
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 135
def respond_to?(name)
super || parent.respond_to?(name)
end
|
#session ⇒ Object
165
166
167
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 165
def session
parent.controller.session
end
|
#url_for(*args) ⇒ Object
7
8
9
|
# File 'lib/erector/rails2/extensions/rails_helpers.rb', line 7
def url_for(*args)
parent.url_for(*args)
end
|