Module: Railings::LayoutHelper

Defined in:
lib/railings/layout_helper.rb

Instance Method Summary collapse

Instance Method Details

#body(controller, *classes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/railings/layout_helper.rb', line 3

def body controller, *classes
  if @message
    id = @message.element.class.pluralize
  else
    parts = [controller.controller_name]
    parts.insert 0, controller.class.parent.name.downcase unless controller.class.parent == Object
    id = parts.join '-'
  end
  { :class  => classes.push(controller.action_name).join(' '), :id => id }
end

#title(controller) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/railings/layout_helper.rb', line 14

def title controller
  scope   = [
    controller.class.parent == Object ? nil : controller.class.parent.name.downcase,
    controller.controller_name, 
    controller.action_name
  ].compact

  options = { :default => '' }
  controller.instance_variables.each do |name|
    options.merge! name.to_s[1..-1].to_sym => controller.instance_variable_get(name).to_s if 
      controller.instance_variable_get(name).kind_of?(MongoMapper::Document)
  end

  while scope.any?
    t(:title, options.merge!(:scope => scope)).tap do |title|
      return title unless title.blank?
    end
    scope.pop
  end
  t :title, :default => ::Rails.application.class.parent.name.titleize
end