Sha256: b394671a1c3d80e8ef9967c4a9e5b9c91e04a9409704bbdc1009b97ea492344c

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].present? ) ? "#{options[name]} #{setting(:title)}" : ""
        desc = (options.include?(name)) ? options[name] : setting(name)
        haml_concat "<meta content='#{desc}' 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.3 lib/frontend-helpers/metatag_helper.rb
frontend-helpers-0.0.2 lib/frontend-helpers/metatag_helper.rb
frontend-helpers-0.0.1.beta.1 lib/frontend-helpers/metatag_helper.rb