Sha256: f52a9db9b2eedeffcaa81cf2a3011ed4dfd8206141f9da3632413a0f1f8e6422

Contents?: true

Size: 1.94 KB

Versions: 39

Compression:

Stored size: 1.94 KB

Contents

module Locomotive
  module Steam
    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['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['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'.freeze, SEO::Base)
        ::Liquid::Template.register_tag('seo_title'.freeze, SEO::Title)
        ::Liquid::Template.register_tag('seo_metadata'.freeze, SEO::Metadata)
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/liquid/tags/seo.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/liquid/tags/seo.rb