Sha256: a8e6818104a262c7e41597ff3190c505e24b74ad2bddc11795ff98d3878cc429

Contents?: true

Size: 1.81 KB

Versions: 34

Compression:

Stored size: 1.81 KB

Contents

module Locomotive
  module Liquid
    module Tags
      module SEO

        class Base < ::Liquid::Tag

          def render(context)
            %{
              #{self.render_title(context)}
              #{self.render_metadata(context)}
            }
          end

          protected

          def render_title(context)
            title = self.value_for(:seo_title, context)
            title = context.registers[:site].name if title.blank?

            %{
              <title>#{title}</title>
            }
          end

          def render_metadata(context)
            %{
              <meta name="description" content="#{self.value_for(:meta_description, context)}">
              <meta name="keywords" content="#{self.value_for(:meta_keywords, context)}">
            }
          end

          # Removes whitespace and quote charactets from the input
          def sanitized_string(string)
            string ? string.strip.gsub(/"/, '') : ''
          end

          def value_for(attribute, context)
            object = self.metadata_object(context)
            value = object.try(attribute.to_sym).blank? ? context.registers[:site].send(attribute.to_sym) : object.send(attribute.to_sym)
            self.sanitized_string(value)
          end

          def metadata_object(context)
            context['content_entry'] || context['page']
          end
        end

        class Title < Base

          def render(context)
            self.render_title(context)
          end

        end

        class Metadata < Base

          def render(context)
            self.render_metadata(context)
          end

        end

      end

      ::Liquid::Template.register_tag('seo', SEO::Base)
      ::Liquid::Template.register_tag('seo_title', SEO::Title)
      ::Liquid::Template.register_tag('seo_metadata', SEO::Metadata)
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/liquid/tags/seo.rb
locomotivecms-3.0.0.pre.alpha.2 lib/locomotive/previous_liquid/tags/seo.rb
locomotivecms-3.0.0.pre.alpha lib/locomotive/previous_liquid/tags/seo.rb
locomotive_cms-2.5.6 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.5 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.4 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.3 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.2 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.1 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.0 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.0.rc3 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.0.rc2 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.5.0.rc1 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.4.1 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.4.0 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.3.1 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.3.0 lib/locomotive/liquid/tags/seo.rb
locomotive_cms-2.2.3 lib/locomotive/liquid/tags/seo.rb