Class: Para::SeoTools::Skeleton::PageBuilder
- Inherits:
-
Object
- Object
- Para::SeoTools::Skeleton::PageBuilder
- Includes:
- Helpers::DefaultDataMethodsHelper
- 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
Methods included from Helpers::DefaultDataMethodsHelper
#default_data_from_method_for, #default_description_for, #default_image_for, #default_title_for
Constructor Details
#initialize(name, path: nil, resource: nil, **options) ⇒ PageBuilder
Returns a new instance of PageBuilder.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 12 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.
10 11 12 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 10 def config @config end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
10 11 12 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 10 def defaults @defaults end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
10 11 12 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 10 def locale @locale end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 10 def name @name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
10 11 12 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 10 def resource @resource end |
Instance Method Details
#display_name ⇒ Object
49 50 51 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 49 def display_name @display_name ||= [name, resource.try(:id)].compact.join(' #').humanize end |
#identifier ⇒ Object
27 28 29 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 27 def identifier @identifier ||= [name, resource.try(:id)].compact.join(':') end |
#model ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 57 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 = process_defaults page.config = config end end |
#path ⇒ Object
53 54 55 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 53 def path @path ||= find_route end |
#scope ⇒ Object
31 32 33 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 31 def scope @scope ||= config[:scope] end |
#scope_attributes ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/para/seo_tools/skeleton/page_builder.rb', line 35 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 |