Class: WCC::Contentful::Model::MenuButton
- Inherits:
-
WCC::Contentful::Model
- Object
- WCC::Contentful::Model
- WCC::Contentful::Model::MenuButton
- Defined in:
- lib/wcc/contentful/model/menu_button.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#external? ⇒ Boolean
A menu link is external if ‘external_link` is present and not relative.
- #external_uri ⇒ Object
- #fragment ⇒ Object
-
#href ⇒ Object
Gets either the external link or the slug from the referenced page.
Instance Method Details
#external? ⇒ Boolean
A menu link is external if ‘external_link` is present and not relative.
9 10 11 |
# File 'lib/wcc/contentful/model/menu_button.rb', line 9 def external? external_uri&.scheme.present? end |
#external_uri ⇒ Object
4 5 6 |
# File 'lib/wcc/contentful/model/menu_button.rb', line 4 def external_uri @external_url ||= URI(external_link) if external_link.present? end |
#fragment ⇒ Object
29 30 31 |
# File 'lib/wcc/contentful/model/menu_button.rb', line 29 def fragment WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link end |
#href ⇒ Object
Gets either the external link or the slug from the referenced page. Example usage: ‘<%= link_to button.title, button.href %>`
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wcc/contentful/model/menu_button.rb', line 15 def href return external_link if external_link url = (link&.try(:slug) || link&.try(:url)) return if url.blank? && fragment.blank? url = URI(url || '') url = rewrite_to_locale(url, sys.locale) if default_locale && sys.locale != default_locale url.fragment = fragment if fragment.present? url.to_s end |