[Erector-devel] Partial Templates

Brian Takita brian.takita at gmail.com
Wed Jun 4 00:24:01 EDT 2008


In Tue, Jun 3, 2008 at 9:17 PM, Brian Takita <brian.takita at gmail.com> wrote:
> On Tue, Jun 3, 2008 at 8:19 AM, Alex Chaffee <alex at pivotallabs.com> wrote:
>> I already implemented support for old-fashioned partials via render
>> :partial... It has some gaps but mostly works. Did you look at that?
> I modified the TemplateHandler to call render_partial for the loaded object.
>
> The reason is there is an ambiguity when there is a partial template
> and a normal template with the same names.
> For example if there is both a show.html.rb and _show.html.rb, then
> this ambiguity occurs.
>
> Whats nice about the #render_partial method solution is that we don't
> have to give the partial widget a different class name, like
> ShowPartial. It just reopens the class and defines the method.
>
> In the docs, we could recommend not using partial widgets, because we
> have the OO facilities of Ruby.
I also monkey patched ActionView::Base#render_partial to set
@is_partial_template to true. I also added
ActionView#Base#is_partial_template?
Hopefully this will cause the correct template to be loaded when there
is a template and a partial template with the same base name.
>>
>>
>> On Tue, Jun 3, 2008 at 12:54 AM, Brian Takita <brian.takita at gmail.com>
>> wrote:
>>>
>>> So I checked in an implementation for partials.
>>>
>>> The solution that I came up with is the partial Erector object will
>>> define a #render_partial method.
>>>
>>> So in the case where there is both:
>>> show.html.rb
>>> class Views::User::Show < Erector::Widget do
>>>  def render
>>>    ...
>>>  end
>>> end
>>>
>>> _show.html.rb
>>> class Views::User::Show < Erector::Widget do
>>>  def render_partial
>>>    ...
>>>  end
>>> end
>>>
>>> The Widget#to_s method also can take an argument that is the render method
>>> name.
>>> So, to render using #render_partial, one would call:
>>> Views::User::Show.new.to_s(:render_partial)
>>>
>>> What do you all think?
>>> _______________________________________________
>>> Erector-devel mailing list
>>> Erector-devel at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/erector-devel
>>
>>
>>
>> --
>> Alex Chaffee
>> alexch at gmail.com
>


More information about the Erector-devel mailing list