Sha256: 491d0216bf7147160bc3daf3483076a7722e5b7bb7edb6a9c08d1785884b0bbe

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module PageMeta
  class MetaTag
    attr_reader :name, :content

    def self.build(name, content)
      klass_name = "::PageMeta::MetaTag::#{name.to_s.camelize}"
      klass = const_get(klass_name) rescue MetaTag
      klass.new(name, content)
    end

    def initialize(name, content)
      @name = name.to_s.dasherize
      @content = content
    end

    def render
      helpers.tag(:meta, name: name, content: content) unless content.empty?
    end

    def helpers
      ActionController::Base.helpers
    end

    class MultipleMetaTag < MetaTag
      def render
        return if content.empty?

        helpers.tag(:meta, name: name, content: content) +
        helpers.tag(:meta, itemprop: name, content: content)
      end
    end

    class HttpEquiv < MetaTag
      def render
        return if content.empty?

        helpers.tag(:meta, "http-equiv" => name, content: content)
      end
    end

    class Description < MultipleMetaTag; end
    class Author < MultipleMetaTag; end
    class Keywords < MultipleMetaTag; end

    class Pragma < HttpEquiv; end
    class CacheControl < HttpEquiv; end
    class Imagetoolbar < HttpEquiv; end
    class Expires < HttpEquiv; end
    class Refresh < HttpEquiv; end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
page_meta-0.1.1 lib/page_meta/meta_tag.rb
page_meta-0.1.0 lib/page_meta/meta_tag.rb