Module: Alchemy::Page::PageNaming
- Extended by:
- ActiveSupport::Concern
- Includes:
- NameConversions
- Included in:
- Alchemy::Page
- Defined in:
- app/models/alchemy/page/page_naming.rb
Constant Summary collapse
- RESERVED_URLNAMES =
%w(admin messages new)
Instance Method Summary collapse
-
#external_urlname ⇒ Object
Returns an urlname prefixed with http://, if no protocol is given.
-
#renamed? ⇒ Boolean
Returns true if name or urlname has changed.
-
#slug ⇒ Object
Returns always the last part of a urlname path.
-
#update_urlname! ⇒ Object
Makes a slug of all ancestors urlnames including mine and delimit them be slash.
-
#visible_ancestors ⇒ Object
Returns an array of visible/non-language_root ancestors.
Methods included from NameConversions
#convert_to_humanized_name, #convert_to_urlname
Instance Method Details
#external_urlname ⇒ Object
Returns an urlname prefixed with http://, if no protocol is given
53 54 55 56 |
# File 'app/models/alchemy/page/page_naming.rb', line 53 def external_urlname return urlname if urlname =~ /\A(\/|[a-z]+:\/\/)/ "http://#{urlname}" end |
#renamed? ⇒ Boolean
Returns true if name or urlname has changed.
33 34 35 |
# File 'app/models/alchemy/page/page_naming.rb', line 33 def renamed? name_changed? || urlname_changed? end |
#slug ⇒ Object
Returns always the last part of a urlname path
48 49 50 |
# File 'app/models/alchemy/page/page_naming.rb', line 48 def slug urlname.to_s.split('/').last end |
#update_urlname! ⇒ Object
Makes a slug of all ancestors urlnames including mine and delimit them be slash. So the whole path is stored as urlname in the database.
39 40 41 42 43 44 45 |
# File 'app/models/alchemy/page/page_naming.rb', line 39 def update_urlname! new_urlname = nested_url_name(slug) if urlname != new_urlname legacy_urls.create(urlname: urlname) update_column(:urlname, new_urlname) end end |
#visible_ancestors ⇒ Object
Returns an array of visible/non-language_root ancestors.
59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/alchemy/page/page_naming.rb', line 59 def visible_ancestors return [] unless parent if new_record? parent.visible_ancestors.tap do |base| base.push(parent) if parent.visible? end else ancestors.visible.contentpages.where(language_root: nil).to_a end end |