Module: FiSeo::ActsAsSeoableInstanceMethods

Defined in:
lib/fi_seo.rb

Instance Method Summary collapse

Instance Method Details

#canonical_urlObject



187
188
189
# File 'lib/fi_seo.rb', line 187

def canonical_url
  FiSeo.initialized_config.default_canonical_url
end

#create_dynamic_seo_recordObject



150
151
152
153
# File 'lib/fi_seo.rb', line 150

def create_dynamic_seo_record
  DynamicSeo.create(seoable_type: self.class.to_s, seoable_id: id, title: self.title_value,
                    description: self.description_value, keywords: self.keywords_value)
end

#description_valueObject



195
196
197
# File 'lib/fi_seo.rb', line 195

def description_value
  self.send(self.class.seoable_fields.second)
end

#facebook_tagsObject



167
168
169
170
171
172
173
174
175
# File 'lib/fi_seo.rb', line 167

def facebook_tags
  {
    title: FiSeo.initialized_config.default_facebook_title,
    type: FiSeo.initialized_config.default_facebook_type,
    url: FiSeo.initialized_config.default_facebook_url,
    image: FiSeo.initialized_config.default_facebook_image,
    description: FiSeo.initialized_config.default_facebook_description
  }
end

#keywords_valueObject



199
200
201
# File 'lib/fi_seo.rb', line 199

def keywords_value
  self.send(self.class.seoable_fields.third)
end

#title_valueObject



191
192
193
# File 'lib/fi_seo.rb', line 191

def title_value
  self.send(self.class.seoable_fields.first)
end

#to_meta_tagsObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/fi_seo.rb', line 114

def to_meta_tags
  row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
  if row.nil?
    {}
  else
    hash = {
      title: row.title,
      description: row.description,
      keywords: row.keywords,
      lowercase: self.class.seoable_options[:lowercase],
      reverse: self.class.seoable_options[:reverse],
      index: self.class.seoable_options[:index],
      noindex: self.class.seoable_options[:noindex],
      follow: self.class.seoable_options[:follow],
      nofollow: self.class.seoable_options[:nofollow],
      noarchive: self.class.seoable_options[:noarchive],
      separator: self.class.seoable_options[:separator].html_safe
    }

    if self.class.seoable_options[:social].present?
      if self.class.seoable_options[:social].include? :facebook
        hash.merge!(og: facebook_tags)
      end
      if self.class.seoable_options[:social].include? :twitter
        hash.merge!(twitter: twitter_tags)
      end
    end
    if self.class.seoable_options[:canonical].present?
      hash.merge!(canonical: canonical_url)
    end
    hash
  end
end

#twitter_tagsObject



177
178
179
180
181
182
183
184
185
# File 'lib/fi_seo.rb', line 177

def twitter_tags
  {
    title: FiSeo.initialized_config.default_twitter_title,
    card: FiSeo.initialized_config.default_twitter_card,
    site: FiSeo.initialized_config.default_twitter_site,
    image: FiSeo.initialized_config.default_twitter_image,
    description: FiSeo.initialized_config.default_twitter_description
  }
end

#update_dynamic_seo_recordObject



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fi_seo.rb', line 155

def update_dynamic_seo_record
  if self.class.seoable_options[:check_for_changes]
    row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
    if row.nil?
      self.create_dynamic_seo_record
    else
      DynamicSeo.where(seoable_type: self.class.to_s).where(seoable_id: self.id)
                .update_all(title: self.title_value, description: self.description_value, keywords: self.keywords_value)
    end
  end
end