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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.