module Plate
# Methods related to the meta-data of a page
module MetaHelper
# Is there a description available for this page?
def description?
!page.description.to_s.blank?
end
# Sanitize keywords output into a comma separated list string
def keywords
page.keywords.join(", ")
end
# Are there keywords available on this page?
def keywords?
page.keywords.length > 0
end
# Returns a description meta tag if there is a description available for
# this page.
def meta_description_tag
%Q() if description?
end
# Returns a keywords meta tag if there are keywords for this page.
def meta_keywords_tag
%Q() if keywords?
end
# 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.
#
# @example Show all available meta tags
# <%= meta_tags %>
#
# @example Show only the keywords tag
# <%= meta_tags :keywords %>
#
# @example Show both keywords and description (default)
#
# <%= meta_tags :keywords, :description %>
#
# @overload meta_tags([tags...], options)
# @param [optional, Symbol] tags Pass in any number of symbols to output those tags.
# @param [optional, Hash] options Customize display options
# @option options [String] :joiner String to use to join together multiple tags.
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
# Does this page have a title?
def title?
!page.title.to_s.blank?
end
end
end