Class: Para::SeoTools::Skeleton::PageBuilder
- Inherits:
-
Object
- Object
- Para::SeoTools::Skeleton::PageBuilder
- Defined in:
- lib/para/seo_tools/skeleton/page_builder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #display_name ⇒ Object
- #identifier ⇒ Object
-
#initialize(name, path: nil, resource: nil, **options) ⇒ PageBuilder
constructor
A new instance of PageBuilder.
- #model ⇒ Object
- #path ⇒ Object
- #scope ⇒ Object
- #scope_attributes ⇒ Object
Constructor Details
#initialize(name, path: nil, resource: nil, **options) ⇒ PageBuilder
Returns a new instance of PageBuilder.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 11 def initialize(name, path: nil, resource: nil, **) @name = Array.wrap(name).join(':') @path = path @resource = resource # Fetch locale on page build to allow calling the `page` skeleton # method inside a `I18n.with_locale` block # @locale = .delete(:locale) || I18n.locale @defaults = .delete(:defaults) || {} # Remaining options will be stored as config in a JSONB attribute @config = end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 9 def config @config end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
9 10 11 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 9 def defaults @defaults end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
9 10 11 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 9 def locale @locale end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 9 def name @name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
9 10 11 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 9 def resource @resource end |
Instance Method Details
#display_name ⇒ Object
48 49 50 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 48 def display_name @display_name ||= [name, resource.try(:id)].compact.join(' #').humanize end |
#identifier ⇒ Object
26 27 28 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 26 def identifier @identifier ||= [name, resource.try(:id)].compact.join(':') end |
#model ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 56 def model @model ||= self.class.model_for(self).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 = defaults page.config = config end end |
#path ⇒ Object
52 53 54 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 52 def path @path ||= find_route end |
#scope ⇒ Object
30 31 32 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 30 def scope @scope ||= config[:scope] end |
#scope_attributes ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 34 def scope_attributes scope.each_with_object({}) do |attribute, hash| hash[attribute] = if (value = config[attribute]) value elsif respond_to?(attribute) send(attribute) else raise ScopeAttributeUndefined, "Your Skeleton page is scoped " + "with the '#{ attribute }' attribute but you did not pass it " + "as a parameter of the #page : #{ inspect }" end end end |