Sha256: 386d24cc41d34c8852b69113196316684fcff8f2038de964bf45de8cdaf1bc59
Contents?: true
Size: 1.88 KB
Versions: 21
Compression:
Stored size: 1.88 KB
Contents
module RailsConnector # Search Engine Optimization methods module SEO # The methods contained herein are attached to the Obj model class. module ClassMethods # Finds all objects that shall be included in the SEO <tt>sitemap.xml</tt>. # On each exportable none-image object, <tt>included_in_seo_sitemap?</tt> is called. # Overwrite <tt>included_in_seo_sitemap?</tt> in your +ObjExtensions+ to adjust the criteria. def find_all_for_sitemap start = Obj.homepage children = start.toclist grandchildren = children.map(&:toclist).flatten ([start] + children + grandchildren).select(&:included_in_seo_sitemap?) end end # The methods contained herein are included in the Obj model. module InstanceMethods # Returns +true+ by default. Overwrite in your +ObjExtensions+ as you like. def readable_for_googlebots? true end # Default implementation: objects have to be <tt>active?</tt> and at least of one of: permitted for anyone (<tt>permitted_groups = []</tt>), <tt>readable_for_googlebots?</tt>. # Overwrite in your +ObjExtensions+ as you like. def included_in_seo_sitemap? (permitted_groups.empty? || readable_for_googlebots?) && active? end # Returns an html-stripped <tt>Obj#body</tt>, truncated to 300 chars. # Overwrite in your +ObjExtensions+ as you like. For example, point to a CMS field. def seo_description HTML::FullSanitizer.new.sanitize(body.strip.gsub(%r{[\n|\r]}, " ")).mb_chars[0,300] if body end # Returns +nil+ by default. Overwrite in your +ObjExtensions+ as you like. # For example, point to a CMS field of your objects. def seo_keywords nil end end def self.included(receiver) # :nodoc: receiver.extend ClassMethods receiver.send :include, InstanceMethods end end end
Version data entries
21 entries across 21 versions & 1 rubygems