On Wed, Aug 29, 2007 at 09:07:28AM -0500, Michael D. Ivey wrote:
> On Aug 29, 2007, at 2:36 AM, Brian Candler wrote:
> > On reflection, it doesn't seem to make much sense to set up
> > autoloading, but
> > then to have to explicitly trigger it. Based on the Merb KISS
> > principle, I
>
> What about
>
> ------------------------------------------------------------------------
> --
> # Uncomment the template handers which your application needs to load
> Merb::Template::Erubis
> # .herb .jerb .erb .rhtml .html.erb .js.erb
> # Merb::Template::Haml # .haml
> # Merb::Template:::Markaby # .mab
> # Merb::Template::XMLBuilder # .rxml .xerb .builder
> ------------------------------------------------------------------------
> --
>
> To me, this is even clearer what you're getting.
I actually wrote that :-)
> The more I look at the autoload, the less it feels like magic.
I could understand the benefit of this approach if the extensions were
pre-registered: e.g.
module Merb
module Template
autoload :Erubis, 'merb/template/erubis'
register_template :Erubis, '.erb', '.rhtml'
end
end
Then, Merb would search for .erb / .rhtml files, and if it found one and
needed to process it, the template handling code would be loaded at that
time.
But as it is, you get a chicken-and-egg situation: the template extensions
aren't registered until the class is used, but the class won't be used until
a template matches one of its extensions. So you have to explicitly 'touch'
the class to get it loaded. In that case, I argue you might as well just
load the class explicitly.
As a side point: the current approach also restricts you to the templating
modules which are defined in lib/merb/template.rb: namely,
module Merb
module Template
autoload :Erubis, 'merb/template/erubis'
autoload :Haml, 'merb/template/haml'
autoload :Markaby, 'merb/template/markaby'
autoload :XMLBuilder, 'merb/template/xml_builder'
end
end
Of course, a plugin can have its own init.rb which sets up autoload for its
own templating class, and then you can explicitly 'touch' the class in
merb_init.rb. But why jump through these hoops?
Regards,
Brian.
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel