Class: Para::SeoTools::Skeleton::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/para/seo_tools/skeleton/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path: nil, resource: nil, **options) ⇒ Page

Returns a new instance of Page.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/para/seo_tools/skeleton/page.rb', line 9

def initialize(name, path: nil, resource: nil, **options)
  @name = name
  @path = path
  @resource = resource
  @options = options

  # Fetch locale on page build to allow calling the `page` skeleton
  # method inside a `I18n.with_locale` block
  #
  @locale = options.fetch(:locale, I18n.locale)
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



7
8
9
# File 'lib/para/seo_tools/skeleton/page.rb', line 7

def locale
  @locale
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/para/seo_tools/skeleton/page.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/para/seo_tools/skeleton/page.rb', line 7

def options
  @options
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/para/seo_tools/skeleton/page.rb', line 7

def resource
  @resource
end

Instance Method Details

#display_nameObject



25
26
27
# File 'lib/para/seo_tools/skeleton/page.rb', line 25

def display_name
  @display_name ||= [name, resource.try(:id)].compact.join(' #').humanize
end

#identifierObject



21
22
23
# File 'lib/para/seo_tools/skeleton/page.rb', line 21

def identifier
  @identifier ||= [name, resource.try(:id)].compact.join(':')
end

#modelObject



33
34
35
36
37
38
39
40
41
# File 'lib/para/seo_tools/skeleton/page.rb', line 33

def model
  @model ||= self.class.model_for(identifier).tap do |page|
    # Override path (i.e.: slug changed)
    page.path = path if path.to_s != page.path
    page.locale = locale
    # Do not override meta tags if already present
    page.defaults = options[:defaults] || {}
  end
end

#pathObject



29
30
31
# File 'lib/para/seo_tools/skeleton/page.rb', line 29

def path
  @path ||= find_route
end

#sitemap_optionsObject



43
44
45
46
47
# File 'lib/para/seo_tools/skeleton/page.rb', line 43

def sitemap_options
  [:priority, :change_frequency].each_with_object({}) do |param, hash|
    hash[param] = options[param] if options.key?(param)
  end
end