Sha256: 7ccc7e9e4ccdac8050ee1c316b11070d5a27974ad63f2fe7054dc40e8fe7c228
Contents?: true
Size: 1.53 KB
Versions: 2
Compression:
Stored size: 1.53 KB
Contents
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 {InstanceMethods#set_meta_tags} method, that have the same parameters # as {ViewHelper#set_meta_tags}. # module ControllerHelper def self.included(base) base.send :include, InstanceMethods base.alias_method_chain :render, :meta_tags end module InstanceMethods # Processes the <tt>@page_title</tt>, <tt>@page_keywords</tt>, and # <tt>@page_description</tt> instance variables and calls +render+. def render_with_meta_tags(*args, &block) meta_tags = {} meta_tags[:title] = @page_title if @page_title meta_tags[:keywords] = @page_keywords if @page_keywords meta_tags[:description] = @page_description if @page_description set_meta_tags(meta_tags) render_without_meta_tags(*args, &block) end # Set meta tags for the page. # # See <tt>MetaTags.set_meta_tags</tt> for details. def set_meta_tags(meta_tags) meta_tags ||= {} meta_tags[:open_graph] = meta_tags.delete(:og) if meta_tags.key?(:og) self.meta_tags.deep_merge!(meta_tags || {}) end protected :set_meta_tags # Get meta tags for the page. def meta_tags @meta_tags ||= {} end protected :meta_tags end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
meta-tags-1.2.6 | lib/meta_tags/controller_helper.rb |
meta-tags-1.2.5 | lib/meta_tags/controller_helper.rb |