Module: Pancake::Mixins::Render::ClassMethods

Defined in:
lib/pancake/mixins/render.rb

Instance Method Summary collapse

Instance Method Details

#_find_template(name) ⇒ Object

Raises:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pancake/mixins/render.rb', line 36

def _find_template(name)
  renderer = _template_cache[name]
  return renderer if renderer

  renderer_path = unique_paths_for(:views, :invert => true).detect do |path|
    path.last =~ %r[^\/?(#{name})\.\w+$]
  end

  raise TemplateNotFound unless renderer_path
  _template_cache[name] = Template.new(name, self, renderer_path.join)
end

#_find_view_context_class_for(template) ⇒ Object



53
54
55
56
57
58
# File 'lib/pancake/mixins/render.rb', line 53

def _find_view_context_class_for(template)
  _view_context_cache[template] ||= begin
                                      Class.new(self::ViewContext)
                                    end
  _view_context_cache[template]
end

#_renderer_and_view_context_class_for(template) ⇒ Object



60
61
62
# File 'lib/pancake/mixins/render.rb', line 60

def _renderer_and_view_context_class_for(template)
  [_find_template(template), _find_view_context_class_for(template)]
end

#_template_cacheObject



32
33
34
# File 'lib/pancake/mixins/render.rb', line 32

def _template_cache
  @_template_cache ||= {}
end

#_template_name_for(name, opts = {}) ⇒ Object



64
65
66
67
# File 'lib/pancake/mixins/render.rb', line 64

def _template_name_for(name, opts = {})
  opts[:format] ||= :html
  "#{name}.#{opts[:format]}"
end

#_view_context_cacheObject



48
49
50
51
# File 'lib/pancake/mixins/render.rb', line 48

def _view_context_cache
  @_view_context_cache ||= {}
  @_view_context_cache
end

#base_template_nameObject



80
81
82
# File 'lib/pancake/mixins/render.rb', line 80

def base_template_name
  :base
end

#template(name_or_template, opts = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/pancake/mixins/render.rb', line 69

def template(name_or_template, opts = {})
  case name_or_template
  when String, Symbol
    _find_template(_template_name_for(name_or_template, opts))
  when Template
    name_or_template
  else
    nil
  end
end