Module: Rango::ConventionalRendering

Included in:
RESTController
Defined in:
lib/rango/mixins/conventional_rendering.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.template_dirnameObject



10
11
12
13
14
15
16
17
# File 'lib/rango/mixins/conventional_rendering.rb', line 10

def self.template_dirname
  @@template_dirname
rescue NameError
  name     = self.class.name
  constant = name.gsub("::", "/")
  dirname  = constant.camel_case
  @@template_dirname = dirname
end

.template_dirname=(template_dirname) ⇒ Object



6
7
8
# File 'lib/rango/mixins/conventional_rendering.rb', line 6

def self.template_dirname=(template_dirname)
  @@template_dirname = template_dirname
end

Instance Method Details

#autorender(context = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rango/mixins/conventional_rendering.rb', line 50

def autorender(context = nil)
  if context
    render_relative template_basename, context
  else
    render_relative template_basename
  end
end

#display(object) ⇒ Object



58
59
60
61
62
63
# File 'lib/rango/mixins/conventional_rendering.rb', line 58

def display(object)
  autorender
rescue TemplateInheritance::TemplateNotFound
  callback = self.formats[request.action]
  callback.call
end

#render_relative(template, context = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rango/mixins/conventional_rendering.rb', line 42

def render_relative(template, context = nil)
  if context
    super File.join(template_dirname, template), context
  else
    super File.join(template_dirname, template)
  end
end

#template_basenameObject

Examples:

def template_basename
  case request["router.action"]
  when "show"
    self.class.name.singularize
  when "index"
  else
  end
end


34
35
36
# File 'lib/rango/mixins/conventional_rendering.rb', line 34

def template_basename
  request["router.action"]
end

#template_dirnameObject



19
20
21
# File 'lib/rango/mixins/conventional_rendering.rb', line 19

def template_dirname
  self.class.template_dirname
end

#template_pathObject



38
39
40
# File 'lib/rango/mixins/conventional_rendering.rb', line 38

def template_path
  File.join(template_dirname, template_basename)
end