Sha256: 91350e2467bd03ef02d935c195bbdea91026102e78a42ed24f7db9c30dc5cb4c

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module MetaTags
  # Contains methods to use in controllers.
  #
  # You can define several instance variables to set meta tags:
  #   @page_title = 'Member Login'
  #   @page_description = 'Member login page.'
  #   @page_keywords = 'Site, Login, Members'
  #
  # Also you can use {#set_meta_tags} method, that have the same parameters
  # as {ViewHelper#set_meta_tags}.
  #
  module ControllerHelper
    # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and
    # <tt>@page_description</tt> instance variables and calls +render+.
    def render(*args, &block)
      meta_tags[:title] = @page_title if defined?(@page_title) && @page_title
      meta_tags[:keywords] = @page_keywords if defined?(@page_keywords) && @page_keywords
      meta_tags[:description] = @page_description if defined?(@page_description) && @page_description

      super
    end

    # Set meta tags for the page.
    #
    # See <tt>MetaTags::ViewHelper#set_meta_tags</tt> for details.
    def set_meta_tags(meta_tags)
      self.meta_tags.update(meta_tags)
    end
    protected :set_meta_tags

    # Get meta tags for the page.
    def meta_tags
      @meta_tags ||= MetaTagsCollection.new
    end
    protected :meta_tags
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
meta-tags-2.22.1 lib/meta_tags/controller_helper.rb
meta-tags-2.22.1.rc1 lib/meta_tags/controller_helper.rb
meta-tags-2.22.0 lib/meta_tags/controller_helper.rb
meta-tags-2.21.0 lib/meta_tags/controller_helper.rb
meta-tags-2.20.0 lib/meta_tags/controller_helper.rb
meta-tags-2.19.0 lib/meta_tags/controller_helper.rb