[chef] Re: Re: Re: Re: Re: Re: Re: Re: any plan for partial templates in Chef?


Chronological Thread 
  • From: Bryan Berry < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Re: Re: Re: Re: any plan for partial templates in Chef?
  • Date: Wed, 14 Nov 2012 08:36:58 +0100

this is super exciting!

I do not have any rails experience and I personally find the "_#{partial_name}" pretty intuitive. It says to me that the template doesn't exist independent of its parent. Also, I see partials as becoming an advanced feature that n00bs wouldn't find or need until they are farther along.

I myself am pretty new to the chef codebase and to doing more Ruby than just Chef and having a little trouble parsing this code:

echoing Dan's comment on the lambda, why not just make  partial_resolver  a method inside Chef::Mixin::Template::ChefContext next to your render method ?   Do you need the late binding that the lambda gives you?  

also, why do you have an if statement in the following, do you expect the partial_resolver to be pluggable or somehow converted to nil ? 

+          if @partial_resolver
+            template_location = @partial_resolver.call(partial_name)
+            eruby = Erubis::Eruby.new(IO.read(template_location))
+            output = eruby.evaluate(self)
+          else
+            "foo"
+          end

Sorry if my questions are ignorant, i am a still a total n00b when it comes to understanding complex ruby libs


On Wed, Nov 14, 2012 at 3:29 AM, Daniel DeLeo < " target="_blank"> > wrote:

On Tuesday, November 13, 2012 at 4:26 PM, Andrea Campi wrote:

Just for kicks, I spent an hour tonight trying to figure out how complicated this would be.

This is just a proof of concept, but the spec is green.

It would probably another 1-2 hours to prepare a proper pull request. Unless this is deemed *too* crazy, of course ;)

Attachments:
- 0001-Quick-and-dirty-implementation-of-render-partial-in-.patch
Overall it's the right direction.

Some questions:
* Is there value in having the #render method take either a Hash or String to select which partial to render? Why not just have the method signature be: render(partial_name, variables_as_a_hash=nil)? If variables_as_a_hash was given, you replace the current context variables with a the specified set, otherwise keep them the same.

* Following from the above, is there any need to support running partials from different cookbooks than the template that's being rendered? Or from an on-disk (`local true`) template? This would lead you to a method/option signature like
render("partial_name", :variables => {:foo => "bar"}, :cookbook => "other-cookbook", :local => true, :source => "/var/mytemplates/partial.conf.erb")

* Is there value in the leading underscore in partial names? This will be natural for Rails people, and yet another thing to learn for everyone else. Does it make it easier to look at your cookbooks and figure out what's going on if the partials look different?

About the implementation, using the lambda as the partial finder is clever, but it'd be nice if it could be done with less magic.

-- 
Daniel DeLeo





Archive powered by MHonArc 2.6.16.

§