brainopia (owner)

Revisions

gist: 158650 Download_button fork
public
Public Clone URL: git://gist.github.com/158650.git
Embed All Files: show embed
template1.rb #
1
2
3
4
5
6
7
8
9
10
11
# Rails::TemplateRunner uses instance_eval, so
__FILE__ # => (eval)
 
=begin
I know templates can be loaded from internet
but we need at least some method available in template
to see where templates come from,
eg Rails::TemplateRunner#template_source which
returns path or url to source of this template
=end
 
template2.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
=begin
Why methods like Rails::TemplateRunner#ask?/log/append_file... are protected?
If you change self-scope inside template
you can't easily access these methods anymore
=end
 
Template = self
class SomeClass
  log 'hey' # => undefined method `log' for #<Class:0x1b21ba4>::SomeClass
  Template.log 'hey' # => protected method `log' called for #<Rails::TemplateRunner:0x1b26d5c>
  # so the only solution is left
  Template.send :log, 'hey'
end
template3.rb #
1
2
3
# Wouldn't it be nice to have a new method available in templates which will return
 
application_name = root.split('/').last