Greetings! I like the idea of application templates in Rails but having everything in one file is a big mess so I decided to divide it into smaller chunks. Since I haven''t been able to figure out any "standard" or "better" way how to do it, here is my solution - the sub_template method - just put it to your template.rb and use it (you just have to specify the ''-m'' option with full path and do not to use some remote repository). Btw - is there some better/cleaner way how to do it? Example -------------------------------------------- if template.starts_with?(''../'') or template.starts_with?(''./'') raise "Please specify the ''-m'' parameter with full path." end def sub_template(name) code = File.new(name).readlines.join self.instance_eval(code) end template_root = File.dirname(File.expand_path(template)) sub_template(template_root + ''/db.rb'') --------------------------------------------------- Tested on: Rails 2.3.5 Repository: you can find my template using this technique on http://github.com/HakubJozak/railroad_tie Pre-requisities: - binding of runner contains ''template'' variable (it is there now but it might break in next version) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello, you''ve got partial. Try searching rails partial. On Dec 15, 7:51 pm, Jakub <jakub.ho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Greetings! > > I like the idea of application templates in Rails but having > everything in one file is a big mess so I decided to divide it into > smaller chunks. Since I haven''t been able to figure out any "standard" > or "better" way how to do it, here is my solution - the sub_template > method - just put it to your template.rb and use it (you just have to > specify the ''-m'' option with full path and do not to use some remote > repository). Btw - is there some better/cleaner way how to do it? > > Example > -------------------------------------------- > if template.starts_with?(''../'') or template.starts_with?(''./'') > raise "Please specify the ''-m'' parameter with full path." > end > > def sub_template(name) > code = File.new(name).readlines.join > self.instance_eval(code) > end > > template_root = File.dirname(File.expand_path(template)) > sub_template(template_root + ''/db.rb'') > --------------------------------------------------- > > Tested on: Rails 2.3.5 > Repository: you can find my template using this technique onhttp://github.com/HakubJozak/railroad_tie > > Pre-requisities: > - binding of runner contains ''template'' variable (it is there now but > it might break in next version)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
But I am writing about templates you use when you are creating NEW APPLICATION by calling rails depot -m template.rb not about view templates. Guess partials don''t really help here. On Dec 15, 3:46 pm, Kaid <quadfol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, you''ve got partial. Try searching rails partial. > > On Dec 15, 7:51 pm,Jakub<jakub.ho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Greetings! > > > I like the idea of application templates in Rails but having > > everything in one file is a big mess so I decided to divide it into > > smaller chunks. Since I haven''t been able to figure out any "standard" > > or "better" way how to do it, here is my solution - the sub_template > > method - just put it to your template.rb and use it (you just have to > > specify the ''-m'' option with full path and do not to use some remote > > repository). Btw - is there some better/cleaner way how to do it? > > > Example > > -------------------------------------------- > > if template.starts_with?(''../'') or template.starts_with?(''./'') > > raise "Please specify the ''-m'' parameter with full path." > > end > > > def sub_template(name) > > code = File.new(name).readlines.join > > self.instance_eval(code) > > end > > > template_root = File.dirname(File.expand_path(template)) > > sub_template(template_root + ''/db.rb'') > > --------------------------------------------------- > > > Tested on: Rails 2.3.5 > > Repository: you can find my template using this technique onhttp://github.com/HakubJozak/railroad_tie > > > Pre-requisities: > > - binding of runner contains ''template'' variable (it is there now but > > it might break in next version)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kaid Wong
2009-Dec-16 10:12 UTC
Re: Re: Rails application template divided into sub-templates
Hi, Jakub. Sorry I didn''t read your post carefully :p. On Wed, Dec 16, 2009 at 5:41 PM, Jakub <jakub.hozak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> But I am writing about templates you use when you are creating NEW > APPLICATION by calling > > rails depot -m template.rb > > not about view templates. Guess partials don''t really help here. > > On Dec 15, 3:46 pm, Kaid <quadfol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, you''ve got partial. Try searching rails partial. > > > > On Dec 15, 7:51 pm,Jakub<jakub.ho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Greetings! > > > > > I like the idea of application templates in Rails but having > > > everything in one file is a big mess so I decided to divide it into > > > smaller chunks. Since I haven''t been able to figure out any "standard" > > > or "better" way how to do it, here is my solution - the sub_template > > > method - just put it to your template.rb and use it (you just have to > > > specify the ''-m'' option with full path and do not to use some remote > > > repository). Btw - is there some better/cleaner way how to do it? > > > > > Example > > > -------------------------------------------- > > > if template.starts_with?(''../'') or template.starts_with?(''./'') > > > raise "Please specify the ''-m'' parameter with full path." > > > end > > > > > def sub_template(name) > > > code = File.new(name).readlines.join > > > self.instance_eval(code) > > > end > > > > > template_root = File.dirname(File.expand_path(template)) > > > sub_template(template_root + ''/db.rb'') > > > --------------------------------------------------- > > > > > Tested on: Rails 2.3.5 > > > Repository: you can find my template using this technique onhttp:// > github.com/HakubJozak/railroad_tie > > > > > Pre-requisities: > > > - binding of runner contains ''template'' variable (it is there now but > > > it might break in next version) > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.