Module: MetaTagsHelper

Defined in:
app/helpers/meta_tags_helper.rb

Constant Summary collapse

DEFAULT_FIELDS =
%w(author geourl copyright keywords description)

Instance Method Summary collapse

Instance Method Details

#meta_tag(name, content) ⇒ Object



23
24
25
# File 'app/helpers/meta_tags_helper.rb', line 23

def meta_tag(name, content)
  tag 'meta', :name => name, :content => content
end

#meta_tags(resource = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/meta_tags_helper.rb', line 4

def meta_tags(resource=nil)
  current_resource = controller.try(:current_resource)
  resources = [resource, current_resource, @site].compact

  # TODO: check if we actually need this fallback
  # fields = resource.class.try(:meta_fields) || DEFAULT_FIELDS

  DEFAULT_FIELDS.map do |name|
    resource = resources.find do |r|
      r.respond_to?(:"meta_#{name}")
    end

    if resource
      content = meta_value_from(resource.send(:"meta_#{name}"), resource.try(:"default_meta_#{name}"))
      meta_tag(name, content)
    end
  end.join("\n").html_safe
end

#meta_value_from(*args) ⇒ Object



27
28
29
# File 'app/helpers/meta_tags_helper.rb', line 27

def meta_value_from(*args)
  args.detect { |arg| arg.present? }
end