25 Jun '12, 3pm

Does ERB have recursive template support? - Ruby Forum:

On Wed, Jun 20, 2012 at 3:22 AM, Todd Wei <[email protected]> wrote: > > My code generator will generate Java nested classes. The problem is the > level of nesting can't be determined statically. So, the ideal case is I > define a Java class template in ERB, which accepts binding variables as > input > parameter, and in the template, it can "call" itself with new bindings. > Just like what does recursive function do. > > I'm not sure if i can achieve this with "invoke arbitrary code". For > example, can I invoke the template itself with new bindings in the > template? Could you give me an example? Thanks! If I understood correctly, something like this could work for you: # template.rb this template contains: <%= array.inspect %> <% first = array.shift if first %> <%= first %>, <%= ERB.new(File.read("template.erb"), 0, "", "result_#{array.length}").result(binding) %> <% ...

Full article: http://www.ruby-forum.com/topic/4402948

Tweets

Double Shot #903: It’s only Tuesday? Cinderbloc...

afreshcup.com 26 Jun '12, 10am

Tuesday, June 26, 2012 at 5:28AM It's only Tuesday? Cinderblock - Stripped down template with jQuery for new HTML projects...

Satish Talim: Ruby Study Notes - Best Ruby Guid...

rubylearning.com 27 Jun '12, 12am

is a senior software consultant based in Pune, India with over 30+ years of I.T. experience. His experience lies in develo...