Sha256: 334b17070dfdc1efdf65e175a6f794541369e7cd3caea80ed531e0bd5c011692
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
require 'active_support' require 'action_view' require 'curly' class Curly::TemplateHandler class << self # 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 call(template) instrument(template) do compile(template) end end private def compile(template) # Template is empty, so there's no need to initialize a presenter. return %("") if template.source.empty? path = template.virtual_path presenter_class = Curly::Presenter.presenter_for_path(path) source = Curly.compile(template.source, presenter_class) template_digest = Digest::MD5.hexdigest(template.source) <<-RUBY if local_assigns.empty? options = assigns else options = local_assigns end presenter = #{presenter_class}.new(self, options.with_indifferent_access) view_function = lambda do #{source} end 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, presenter_key].compact, options) do safe_concat(view_function.call) end @output_buffer else view_function.call.html_safe end RUBY end def instrument(template, &block) payload = { path: template.virtual_path } ActiveSupport::Notifications.instrument("compile.curly", payload, &block) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
curly-templates-0.7.0 | lib/curly/template_handler.rb |