Module: Refinery::Helpers::MetaHelper

Defined in:
lib/refinery/helpers/meta_helper.rb

Instance Method Summary collapse

Instance Method Details

#browser_title(yield_title = nil) ⇒ Object

This is used to display the title of the current object (normally a page) in the browser’s titlebar.



7
8
9
10
11
12
13
# File 'lib/refinery/helpers/meta_helper.rb', line 7

def browser_title(yield_title=nil)
  [
    (yield_title if yield_title.present?),
    @meta.browser_title.present? ? @meta.browser_title : @meta.path,
    RefinerySetting.find_or_set(:site_name, "Company Name")
  ].compact.join(" - ")
end

#page_title(options = {}) ⇒ Object

you can override the object used for the title by supplying options this object must support custom_title_type if you want custom titles.



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/refinery/helpers/meta_helper.rb', line 17

def page_title(options = {})
  object = options.fetch(:object, @meta)
  options.delete(:object)
  options = RefinerySetting.find_or_set(:page_title, {
    :chain_page_title => false,
    :ancestors => {
      :separator => " | ",
      :class => 'ancestors',
      :tag => 'span'
    },
    :page_title => {
      :class => nil,
      :tag => nil,
      :wrap_if_not_chained => false
    }
  }).merge(options)

  title = []
  objects = (options[:chain_page_title] and object.respond_to?(:ancestors)) ? [object.ancestors, object] : [object]

  objects.flatten.compact.each do |obj|
    obj_title = if obj.respond_to?(:custom_title_type)
      case obj.custom_title_type
        when "text"
          obj.custom_title
        when "image"
          image_fu(obj.custom_title_image, nil, {:alt => obj.title}) rescue obj.title
        else
          obj.title
        end
    else
      obj.title
    end
    title << link_to_if(options[:link], obj_title, obj.url)
  end

  final_title = title.pop
  if (options[:page_title][:wrap_if_not_chained] and title.empty?) and options[:page_title][:tag].present?
    css = " class='#{options[:page_title][:class]}'" if options[:page_title][:class].present?
    final_title = "<#{options[:page_title][:tag]}#{css}>#{final_title}</#{options[:page_title][:tag]}>"
  end

  if title.empty?
    final_title.to_s.html_safe
  else
    tag = "<#{options[:ancestors][:tag]} class='#{options[:ancestors][:class]}'>"
    tag << title.join(options[:ancestors][:separator])
    tag << options[:ancestors][:separator]
    tag << "</#{options[:ancestors][:tag]}>#{final_title}"
    tag.html_safe
  end
end