Module: Rad::Controller::Abstract::Render

Defined in:
lib/rad/controller/_abstract/render.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SPECIAL_FORMAT_HANDLERS =
{
  json: lambda{|o| o.to_json},
  xml: lambda{|o| o.to_xml},
  js: lambda{|o| o},
}

Instance Method Summary collapse

Instance Method Details

#_layout(*args) ⇒ Object



8
9
10
11
# File 'lib/rad/controller/_abstract/render.rb', line 8

def _layout *args
  @_layout = *args unless args.empty?
  @_layout
end

#_layout=(layout) ⇒ Object



12
13
14
# File 'lib/rad/controller/_abstract/render.rb', line 12

def _layout= layout
  @_layout = layout
end

#render(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rad/controller/_abstract/render.rb', line 16

def render *args
  options = rad.template.parse_arguments *args

  instance_variables = {
    controller_name: self.class.controller_name
  }

  instance_variable_names.each do |name|
    instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
  end

  instance_variables[:action_name] = options[:action] if options[:action]

  context = self.class.context_class.new(instance_variables, self)

  options.reverse_merge! \
    context: context,
    format: params.format,
    exact_format: true,
    relative_path_resolver: self.class

  content = render_content options
  content = render_layout content, options

  throw :halt, content
end