Trunk Issue: Because of the use of ''autoload'', template handlers other than Erubis are not loaded automatically (Haml, XMLBuilder). Either this should be fixed, or the documentation should be updated to instruct people how to use non-Erb template engines. Apparently the solution is to do something like this in merb_init.rb: ::Merb::AbstractController.register_engine ::Merb::Template::Haml, %w[ haml ] So the question is: * Is this the permanent situation for the future? * Can I update the docs to reflect this requirement? Geoffrey Grosenbach http://peepcode.com
On Tue, Aug 28, 2007 at 08:45:25PM -0700, Geoffrey Grosenbach wrote:> Trunk Issue: Because of the use of ''autoload'', template handlers other > than Erubis are not loaded automatically (Haml, XMLBuilder). Either > this should be fixed, or the documentation should be updated to > instruct people how to use non-Erb template engines. > > Apparently the solution is to do something like this in merb_init.rb: > > ::Merb::AbstractController.register_engine ::Merb::Template::Haml, %w[ haml ]You just need to reference the class in merb_init.rb to trigger the autoload, e.g. Merb::Template::Haml> So the question is: > > * Is this the permanent situation for the future? > * Can I update the docs to reflect this requirement?It''s now documented the merb_init.rb which is installed by merb -g. But I agree, History.txt should have info about upgrading existing projects. Please see: http://merb.devjavu.com/projects/merb/ticket/130 http://merb.devjavu.com/projects/merb/ticket/133
On Wed, Aug 29, 2007 at 06:38:48AM +0100, Brian Candler wrote:> > * Can I update the docs to reflect this requirement? > > It''s now documented the merb_init.rb which is installed by merb -g. But I > agree, History.txt should have info about upgrading existing projects. > > Please see: > http://merb.devjavu.com/projects/merb/ticket/130 > http://merb.devjavu.com/projects/merb/ticket/133While you''re at it, please document the other changed needed to merb_init.rb, which is -conn_options = YAML::load(Erubis::Eruby.new(IO.read("#{DIST_ROOT}/conf/database.yml")).result) +conn_options = YAML::load(Erubis::Eruby.new(IO.read("#{DIST_ROOT}/conf/database.yml")).result(binding)) See http://merb.devjavu.com/projects/merb/ticket/118 Again, this should be correct for newly generated projects.
On Wed, Aug 29, 2007 at 06:38:48AM +0100, Brian Candler wrote:> You just need to reference the class in merb_init.rb to trigger the > autoload, e.g. > > Merb::Template::Haml > > > So the question is: > > > > * Is this the permanent situation for the future?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 think it would be cleaner to just put require ''merb/template/haml'' in merb_init.rb, and get rid of the autoload magic (although there''s only a tiny bit of that, in lib/merb/template.rb) Does anyone else share this opinion? Perhaps examples/skeleton/conf/merb_init.rb should be changed to say -------------------------------------------------------------------------- # Uncomment the template handers which your application needs to load require ''merb/template/erubis'' # .herb .jerb .erb .rhtml .html.erb .js.erb # require ''merb/template/haml'' # .haml # require ''merb/template/markaby'' # .mab # require ''merb/template/xml_builder'' # .rxml .xerb .builder -------------------------------------------------------------------------- and then it doesn''t matter whether the autoload stuff is there or not. Regards, Brian.
On 29/08/2007, at 5:06 PM, Brian Candler wrote:> On Wed, Aug 29, 2007 at 06:38:48AM +0100, Brian Candler wrote: >> You just need to reference the class in merb_init.rb to trigger the >> autoload, e.g. >> >> Merb::Template::Haml >> >>> So the question is: >>> >>> * Is this the permanent situation for the future? > > 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 > think it would be cleaner to just put > > require ''merb/template/haml'' > > in merb_init.rb, and get rid of the autoload magic (although > there''s only a > tiny bit of that, in lib/merb/template.rb) > > Does anyone else share this opinion?I agree with that. Merb''s mantra should be ''less magic''. That said I''m not so sure about requiring vs. having an actual method for loading the template engine. Then in the future the templating code can me moved about without disturbing users. Also requiring like that means the code will be pulled in via a gem right? A method for loading the template classes would allow users to stash Merb in the framework directory without having to change the path used in the require. how about something like: templating :erubis Just a thought :) -- Luke
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, IWhat 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. The more I look at the autoload, the less it feels like magic. Although, Luke''s "templating :erubis" suggestion (possibly using the autoload mechanism in the background) seems even better, now that I see it. It could also be smart enough to know that :erb means :erubis, :rxml means :xmlbuilder, etc: templating :erb, :rxml
Hi, Why not just autoload Haml (or whatever) when it encounters a .haml template? Perhaps it doesn''t do that now but surely this wouldn''t be difficult. ry
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.
On Wed, Aug 29, 2007 at 04:19:50PM +0200, ry dahl wrote:> Why not just autoload Haml (or whatever) when it encounters a .haml template? > Perhaps it doesn''t do that now but surely this wouldn''t be difficult.Merb doesn''t search for filenames ending in .haml unless the Haml extension has been loaded. Old Merb (0.3.7) simply loaded all the template extensions in regardless. Therefore it would always check for .haml, and process it accordingly. Ezra changed this in trunk r401: http://merb.devjavu.com/projects/merb/changeset/401#file18 This doesn''t seem to have been fully thought-through, because not loading the Haml template library means that the code that registers ''.haml'' as a known extension, and associates it with Merb::Template::Haml, is not run. It would make sense if register_engine were called to register .haml outside of Merb::Template::Haml (but register_engine would have to be modified to be passed a symbol, not a class, because referencing the class would cause it to be autoloaded anyway) Regards, Brian.
I''ve posted a little patch for this behavior http://merb.devjavu.com/projects/merb/ticket/152 On 8/29/07, ry dahl <ry at tinyclouds.org> wrote:> Hi, > > Why not just autoload Haml (or whatever) when it encounters a .haml template? > Perhaps it doesn''t do that now but surely this wouldn''t be difficult. > > ry >
On Aug 29, 2007, at 9:13 AM, ry dahl wrote:> I''ve posted a little patch for this behavior > http://merb.devjavu.com/projects/merb/ticket/152 > > On 8/29/07, ry dahl <ry at tinyclouds.org> wrote: >> Hi, >> >> Why not just autoload Haml (or whatever) when it encounters >> a .haml template? >> Perhaps it doesn''t do that now but surely this wouldn''t be difficult. >> >> ry >> > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-develYeah the autoload of template engines was not thought thru enough on my part. I wanted to be able to not load haml, markaby and builder if your app doesnt use them since its just overhead and more dependencies. But the current situation does need to be changed. Whatever people think is best is fine with me. Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)
On Aug 29, 2007, at 1:52 PM, Ezra Zygmuntowicz wrote:> On Aug 29, 2007, at 9:13 AM, ry dahl wrote: > >> I''ve posted a little patch for this behavior >> http://merb.devjavu.com/projects/merb/ticket/152 > > Yeah the autoload of template engines was not thought thru enough on > my part. I wanted to be able to not load haml, markaby and builder if > your app doesnt use them since its just overhead and more > dependencies. > > But the current situation does need to be changed. Whatever people > think is best is fine with me.+1 for #152. It matches the described behavior of "You can use any of these with no extra config" and it also gets the "Don''t load it if it isn''t needed.