Sha256: 8cc6f932b28754958c806305a31b2d792163c6cbd6849e4c8d791b4ad632f121

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

module Enjoy::Seo::Seoable
  extend ActiveSupport::Concern
  LOCALIZED_FIELDS = [:h1, :title, :keywords, :description, :og_title]
  FIELDS = LOCALIZED_FIELDS + [:og_image, :robots]

  included do
    has_one :seo, as: :seoable, autosave: true, class_name: "Enjoy::Seo::Seo"
    accepts_nested_attributes_for :seo

    delegate(*FIELDS, to: :seo)
    delegate(*(FIELDS.map {|f| "#{f}=".to_sym }), to: :seo)

    if Enjoy::Seo.config.localize
      delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations".to_sym }), to: :seo)
      delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations=".to_sym }), to: :seo)
    end

    alias seo_without_build seo
    def seo
      seo_without_build || build_seo
    end


    def default_seo_h1
      if self.respond_to?(:name)
        self.name
      elsif self.respond_to?(:title)
        self.title
      end
    end
    def default_seo_title
      if self.respond_to?(:name)
        self.name
      elsif self.respond_to?(:title)
        self.title
      end
    end
    def default_seo_keywords
      ""
    end
    def default_seo_description
      ""
    end
    def default_seo_og_title
      if self.respond_to?(:name)
        self.name
      elsif self.respond_to?(:title)
        self.title
      end
    end

    def set_default_seo?
      true
    end
  end

  def page_title
    return self.title unless self.title.blank?
    self.name if self.respond_to?(:name)
  end

  def get_og_title
    return self.og_title unless self.og_title.blank?
    self.name if self.respond_to?(:name)
  end

  def og_image_jcrop_options
    {aspectRation: 800.0/600.0}
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enjoy_cms_seo-0.4.1 app/models/concerns/enjoy/seo/seoable.rb
enjoy_cms_seo-0.4.0.3 app/models/concerns/enjoy/seo/seoable.rb
enjoy_cms_seo-0.4.0.2 app/models/concerns/enjoy/seo/seoable.rb
enjoy_cms_seo-0.4.0.1 app/models/concerns/enjoy/seo/seoable.rb
enjoy_cms_seo-0.4.0 app/models/concerns/enjoy/seo/seoable.rb
enjoy_cms_seo-0.4.0.beta3 app/models/concerns/enjoy/seo/seoable.rb