lib/curly/template_handler.rb in curly-templates-0.2.1 vs lib/curly/template_handler.rb in curly-templates-0.3.0

- old
+ new

@@ -2,33 +2,20 @@ require 'action_view' require 'curly' class Curly::TemplateHandler - # The name of the presenter class for a given view path. - # - # path - The String path of a view. - # - # Examples - # - # Curly::TemplateHandler.presenter_name_for_path("foo/bar") - # #=> "Foo::BarPresenter" - # - # Returns the String name of the matching presenter class. - def self.presenter_name_for_path(path) - "#{path}_presenter".camelize - end - # Handles a Curly template, compiling it to Ruby code. The code will be # evaluated in the context of an ActionView::Base instance, having access # 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 self.call(template) - presenter_class = presenter_name_for_path(template.virtual_path) + path = template.virtual_path + presenter_class = Curly::Presenter.presenter_name_for_path(path) source = Curly.compile(template.source) template_digest = Digest::MD5.hexdigest(template.source) # Template is empty, so there's no need to initialize a presenter. @@ -50,14 +37,20 @@ if key = presenter.cache_key @output_buffer = ActiveSupport::SafeBuffer.new template_digest = #{template_digest.inspect} + if #{presenter_class}.respond_to?(:cache_key) + presenter_key = #{presenter_class}.cache_key + else + presenter_key = nil + end + options = { expires_in: presenter.cache_duration } - cache([template_digest, key], options) do + cache([template_digest, key, presenter_key].compact, options) do safe_concat(view_function.call) end @output_buffer else