Class: RailsTemplateCacheSenexx::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-template-cache-senexx/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, markup, options = {}) ⇒ Template

Returns a new instance of Template.



5
6
7
8
9
10
11
# File 'lib/rails-template-cache-senexx/template.rb', line 5

def initialize(source_file, markup, options = {})
  silence_warnings do
    @template = Tilt[markup]
    @source_file = source_file
    @opts = options
  end
end

Instance Attribute Details

#source_fileObject (readonly)

Returns the value of attribute source_file.



3
4
5
# File 'lib/rails-template-cache-senexx/template.rb', line 3

def source_file
  @source_file
end

Class Method Details

.asset_data(path, templates_path = "", prepend_client_path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails-template-cache-senexx/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

Instance Method Details

#renderObject



13
14
15
16
17
# File 'lib/rails-template-cache-senexx/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