Sha256: 4810ac2d2a8ea2436e276c1282cbc6e0d49d851bbb97ec660b77014dcef7916d

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

module FrontendHelpers
  module MetatagHelper

    def meta_tags
      options = opts
      settings[:site].each do |s, k|
        meta(s, options)
      end
    end

  private ##########

    def settings
      YAML.load_file(File.join(Rails.root, 'config', 'settings.yml')) rescue {}
    end

    def setting(setting)
      ENV["SITE_#{setting.to_s.upcase}"] || settings[:site][setting]
    end

    def meta(name, options)
      if !name.blank? && !setting(name).blank? || options.include?(name) && options[name]
        options[:title] = ( !options[name].blank? ) ? "#{options[name]} #{setting(:title)}" : ""
        desc = (options.include?(name)) ? options[name] : setting(name)
        haml_concat "<meta content='#{setting(name)}' name='#{name.to_s}' />"
      end
    end

    def opts
      {
        title: @meta_title,
        keywords: @meta_keywords,
        description: @meta_description,
        author: @meta_author,
        email: @meta_email,
        copyright: @meta_copyright,
        generator: @meta_generator,
        rating: @meta_rating,
        language: @meta_language,
        distribution: @meta_distribution,
        robots: @robots,
        :"fb:app_id" => @meta_fb_app_id,
        :"og:title" => @meta_og_title,
        :"og:description" => @meta_og_description,
        :"og:url" => request.url,
        :"og:site_name" => @meta_og_site_name,
        :"og:type" => @meta_og_type,
        :"og:image" => @meta_og_image,
        :"og:locality" => @meta_og_locality,
        :"og:region" => @meta_og_region,
        :"og:country_name" => @meta_og_country_name,
        :"og:phone_number" => @meta_og_phone_number
      }
    end
  end
end

ActionView::Base.send :include, FrontendHelpers::MetatagHelper

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
frontend-helpers-0.0.6 lib/frontend-helpers/metatag_helper.rb
frontend-helpers-0.0.5 lib/frontend-helpers/metatag_helper.rb
frontend-helpers-0.0.4 lib/frontend-helpers/metatag_helper.rb