Module: Sunrise::Controllers::HeadOptions

Defined in:
lib/sunrise/controllers/head_options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Inclusion hook to make #current_user and #logged_in? available as ActionView helper methods.



6
7
8
# File 'lib/sunrise/controllers/head_options.rb', line 6

def self.included(base)
  base.send :helper_method, :head_options if base.respond_to? :helper_method
end

Instance Method Details

#head_options(record, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sunrise/controllers/head_options.rb', line 10

def head_options(record, options = {})
  return if record.nil?
  
  options = { :spliter => Sunrise.title_spliter, :append_title => true }.merge(options)

  header = options[:header] || (record.respond_to?(:header) ? record.header : nil)

  if header && header.has_info?
    @page_keywords ||= header.read(:keywords)
    @page_description ||= header.read(:description)
    @page_title ||= header.read(:title)
  end

  @page_title ||= begin
    view_title = if record.respond_to?(:title)
      record.title
    elsif record.respond_to(:name)
      record.name
    end
    
    page_title = []
   page_title << options[:title] if options.key?(:title)
    page_title << view_title
    page_title << I18n.t("page.title") if options[:append_title]

    page_title.flatten.compact.uniq.join(options[:spliter])
  end
end