Class: ActiveSeo::SeoMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/active_seo/seo_meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ SeoMeta

Initializer method



6
7
8
9
10
# File 'lib/active_seo/seo_meta.rb', line 6

def initialize(record)
  @record  = record
  @config  = record.class.seo_config
  @context = contextualizer.new(record)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/active_seo/seo_meta.rb', line 3

def config
  @config
end

#contextObject

Returns the value of attribute context.



3
4
5
# File 'lib/active_seo/seo_meta.rb', line 3

def context
  @context
end

#recordObject

Returns the value of attribute record.



3
4
5
# File 'lib/active_seo/seo_meta.rb', line 3

def record
  @record
end

Instance Method Details

#descriptionObject



25
26
27
28
29
30
# File 'lib/active_seo/seo_meta.rb', line 25

def description
  attribute = :seo_description
  defaults  = [:content, :description, :excerpt, :body]

  attribute_fallbacks_for(attribute, defaults, config.description_fallback)
end

#keywordsObject



32
33
34
35
36
37
# File 'lib/active_seo/seo_meta.rb', line 32

def keywords
  text = record.try :seo_keywords
  text = "#{title} #{description}" if generate_keywords?(text)

  helpers.generate_keywords(text)
end

#nofollowObject



43
44
45
# File 'lib/active_seo/seo_meta.rb', line 43

def nofollow
  record.seo_nofollow || false
end

#noindexObject



39
40
41
# File 'lib/active_seo/seo_meta.rb', line 39

def noindex
  record.seo_noindex || false
end

#ogObject



47
48
49
# File 'lib/active_seo/seo_meta.rb', line 47

def og
  @config.opengraph.merge(context.og_meta)
end

#resultObject

Set base seo meta



13
14
15
16
# File 'lib/active_seo/seo_meta.rb', line 13

def result
  data = [:title, :description, :keywords, :noindex, :nofollow, :og, :twitter]
  Hash[data.map { |i| [i, send(i)] }]
end

#titleObject



18
19
20
21
22
23
# File 'lib/active_seo/seo_meta.rb', line 18

def title
  attribute = :seo_title
  defaults  = [:title, :name]

  attribute_fallbacks_for(attribute, defaults, config.title_fallback)
end

#twitterObject



51
52
53
# File 'lib/active_seo/seo_meta.rb', line 51

def twitter
  @config.twitter.merge(context.twitter_meta)
end