Module: Plate::MetaHelper

Included in:
View
Defined in:
lib/plate/helpers/meta_helper.rb

Overview

Methods related to the meta-data of a page

Instance Method Summary collapse

Instance Method Details

#description?Boolean

Is there a description available for this page?

Returns:

  • (Boolean)


5
6
7
# File 'lib/plate/helpers/meta_helper.rb', line 5

def description?
  !page.description.to_s.blank?
end

#keywordsObject

Sanitize keywords output into a comma separated list string



10
11
12
# File 'lib/plate/helpers/meta_helper.rb', line 10

def keywords      
  page.keywords.join(", ")
end

#keywords?Boolean

Are there keywords available on this page?

Returns:

  • (Boolean)


15
16
17
# File 'lib/plate/helpers/meta_helper.rb', line 15

def keywords?
  page.keywords.length > 0
end

#meta_description_tagObject

Returns a description meta tag if there is a description available for this page.



21
22
23
# File 'lib/plate/helpers/meta_helper.rb', line 21

def meta_description_tag
  %Q(<meta name="description" content="#{description}">) if description?
end

#meta_keywords_tagObject

Returns a keywords meta tag if there are keywords for this page.



26
27
28
# File 'lib/plate/helpers/meta_helper.rb', line 26

def meta_keywords_tag
  %Q(<meta name="keywords" content="#{keywords}">) if keywords?
end

#meta_tags([tags...], options) ⇒ Object

Output the standard meta tags (keywords and description) to a page. Omits any tags with blank data.

Optionally pass in a list of which tags to display.

Examples:

Show all available meta tags

<%= meta_tags %>

Show only the keywords tag

<%= meta_tags :keywords %>

Show both keywords and description (default)


<%= meta_tags :keywords, :description %>

Parameters:

  • tags (optional, Symbol)

    Pass in any number of symbols to output those tags.

  • options (optional, Hash)

    Customize display options

Options Hash (options):

  • :joiner (String)

    String to use to join together multiple tags.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plate/helpers/meta_helper.rb', line 49

def meta_tags(*args)
  options = args.extract_options!
  options = options.reverse_merge({
    :joiner => "\n"
  })
  
  tags = args.length > 0 ? args : %w( description keywords )
  
  result = []
  
  tags.each do |tag|        
    result << self.send("meta_#{tag}_tag") if self.respond_to?("meta_#{tag}_tag")
  end
  
  result.join(options[:joiner]).strip
end

#title?Boolean

Does this page have a title?

Returns:

  • (Boolean)


67
68
69
# File 'lib/plate/helpers/meta_helper.rb', line 67

def title?
  !page.title.to_s.blank?
end