Class: RablRails::Library

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rabl-rails/library.rb

Instance Method Summary collapse

Constructor Details

#initializeLibrary

Returns a new instance of Library.



9
10
11
12
# File 'lib/rabl-rails/library.rb', line 9

def initialize
  @cached_templates = ThreadSafe::Cache.new
  @mutex = Monitor.new
end

Instance Method Details

#compile_template_from_path(path, view) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/rabl-rails/library.rb', line 33

def compile_template_from_path(path, view)
  if RablRails.configuration.cache_templates
    synchronized_compile(path, nil, view)
  else
    source = fetch_source(path, view)
    compile(source, view)
  end
end

#compile_template_from_source(source, view) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rabl-rails/library.rb', line 24

def compile_template_from_source(source, view)
  if RablRails.configuration.cache_templates
    path = view.instance_variable_get(:@virtual_path)
    synchronized_compile(path, source, view)
  else
    compile(source, view)
  end
end

#get_rendered_template(source, view, locals = nil) ⇒ Object



18
19
20
21
22
# File 'lib/rabl-rails/library.rb', line 18

def get_rendered_template(source, view, locals = nil)
  compiled_template = compile_template_from_source(source, view)
  format = view.params[:format] ? view.params[:format].to_s.upcase : :JSON
  Renderers.const_get(format).render(compiled_template, view, locals)
end

#reset_cache!Object



14
15
16
# File 'lib/rabl-rails/library.rb', line 14

def reset_cache!
  @cached_templates = ThreadSafe::Cache.new
end