Class: WCC::Contentful::Model::MenuButton

Inherits:
WCC::Contentful::Model
  • Object
show all
Defined in:
lib/wcc/contentful/model/menu_button.rb

Direct Known Subclasses

MenuButton

Instance Method Summary collapse

Instance Method Details

#external?Boolean

A menu link is external if ‘external_link` is present and not relative.

Returns:

  • (Boolean)


9
10
11
# File 'lib/wcc/contentful/model/menu_button.rb', line 9

def external?
  external_uri&.scheme.present?
end

#external_uriObject



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

#fragmentObject



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

#hrefObject

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