Module: Headliner::Helper

Defined in:
lib/headliner/helper.rb

Instance Method Summary collapse

Instance Method Details

#display_title(options) ⇒ 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/headliner/helper.rb', line 16

def display_title(options)
  # Prefix (leading space)
  if options[:prefix]
    prefix = options[:prefix]
  elsif options[:prefix] == false
    prefix = ''
  else
    prefix = ' '
  end

  # Separator
  unless options[:separator].blank?
    separator = options[:separator]
  else
    separator = '|'
  end

  # Suffix (trailing space)
  if options[:suffix]
    suffix = options[:suffix]
  elsif options[:suffix] == false
    suffix = ''
  else
    suffix = ' '
  end

  # Lowercase title?
  if options[:lowercase] == true
    @title = @title.downcase unless @title.blank?
  end

  # Set website/page order
  unless @title.blank?
    if options[:reverse] == true
      # Reverse order => "Page : Website"
      return tag(:title, @title + prefix + separator + suffix + options[:site])
    else
      # Standard order => "Website : Page"
      return tag(:title, options[:site] + prefix + separator + suffix + @title)
    end
  end
  
  # If title is blank, return only website name
  tag :title, options[:site]
end

#save_title(title, headline) ⇒ Object



11
12
13
14
# File 'lib/headliner/helper.rb', line 11

def save_title(title, headline)
  @title = title.gsub(/<\/?[^>]*>/, '')
  headline.blank? ? title : headline
end

#title(options, headline = '') ⇒ Object Also known as: t



3
4
5
6
7
8
9
# File 'lib/headliner/helper.rb', line 3

def title(options, headline='')
  if options.is_a? String
    save_title(options, headline)
  else
    display_title(options)
  end
end