What is this init.rb doing in the liquid project?
require 'liquid'
require 'extras/liquid_view'
if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
ActionView::Template
else
ActionView::Base
end.register_template_handler(:liquid, LiquidView)
What is this init.rb file run, is it a one-time thing or on application load?
Is it simply calling the regiser_template_handler method, on either the ActionView::Template or ActionView:Base class?
How 开发者_StackOverflow中文版does it work on either one?
What is this init.rb file run, is it a one-time thing or on application load?
It is run once, when the app loads and plugins/gems are loaded in.
Is it simply calling the regiser_template_handler method, on either the ActionView::Template or ActionView:Base class?
Yes. If ActionView::Template
is defined and responds to register_template_handler
it will call register_template_handler
on it, otherwise it will call it on ActionView::Base
.
How does it work on either one?
I'm not sure exactly what you mean by this? If you mean why is it like this, it's for backwards compatibility. ActionView::Template
is relatively new in rails (introduced around v2.1, I think) so I guess it's so that it will gracefully fallback when used with older versions.
精彩评论