class RailsTemplateCache::Template

Attributes

source_file[R]

Public Class Methods

asset_data(path, templates_path = "", prepend_client_path) click to toggle source
# File lib/rails-template-cache/template.rb, line 19
def self.asset_data(path, templates_path = "", prepend_client_path)
  result = []
  case path.to_s
    when /#{templates_path}\/(.*)(\.html)$/
      result = "#{prepend_client_path}#{$1}#{$2}", $2
    when /#{templates_path}\/(.*\.html)(\.\w+)$/
      result = "#{prepend_client_path}#{$1}", $2
    when /#{templates_path}\/(.*)(\.\w+)$/
      result = "#{prepend_client_path}#{$1}.html", $2
  end
  result
end
new(source_file, markup, options = {}) click to toggle source
# File lib/rails-template-cache/template.rb, line 5
def initialize(source_file, markup, options = {})
  silence_warnings do
    @template = Tilt[markup]
    @source_file = source_file
    @opts = options
  end
end

Public Instance Methods

render() click to toggle source
# File lib/rails-template-cache/template.rb, line 13
def render
  # Only render when needed, to avoid caching issues
  rendered_template = @template.new(@source_file).render
  @opts[:compress] ? compress_html(rendered_template) : rendered_template
end

Private Instance Methods

compress_html(html) click to toggle source
# File lib/rails-template-cache/template.rb, line 34
def compress_html(html)
  @compressor ||= HtmlCompressor::Compressor.new
  @compressor.compress(html)
end