lib/curly/template_handler.rb in curly-templates-2.6.5 vs lib/curly/template_handler.rb in curly-templates-3.0.0
- old
+ new
@@ -11,14 +11,22 @@
# to a number of variables.
#
# template - The ActionView::Template template that should be compiled.
#
# Returns a String containing the Ruby code representing the template.
- def call(template)
- instrument(template) do
- compile(template)
+ if ActionView::VERSION::MAJOR < 6
+ def call(template)
+ instrument(template) do
+ compile_for_actionview5(template)
+ end
end
+ else
+ def call(template, source)
+ instrument(template) do
+ compile(template, source)
+ end
+ end
end
def cache_if_key_is_not_nil(context, presenter)
if key = presenter.cache_key
if presenter.class.respond_to?(:cache_key)
@@ -38,20 +46,24 @@
end
end
private
- def compile(template)
- # Template is empty, so there's no need to initialize a presenter.
- return %("") if template.source.empty?
+ def compile_for_actionview5(template)
+ compile(template, template.source)
+ end
+ def compile(template, source)
+ # Template source is empty, so there's no need to initialize a presenter.
+ return %("") if source.empty?
+
path = template.virtual_path
presenter_class = Curly::Presenter.presenter_for_path(path)
raise Curly::PresenterNotFound.new(path) if presenter_class.nil?
- source = Curly.compile(template.source, presenter_class)
+ compiled_source = Curly.compile(source, presenter_class)
<<-RUBY
if local_assigns.empty?
options = assigns
else
@@ -62,10 +74,10 @@
presenter.setup!
@output_buffer = output_buffer || ActiveSupport::SafeBuffer.new
Curly::TemplateHandler.cache_if_key_is_not_nil(self, presenter) do
- result = #{source}
+ result = #{compiled_source}
safe_concat(result)
end
@output_buffer
RUBY