class WCC::Contentful::Model::MenuButton

Public Instance Methods

external?() click to toggle source

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

# File lib/wcc/contentful/model/menu_button.rb, line 9
def external?
  external_uri&.scheme.present?
end
external_uri() click to toggle source
# File lib/wcc/contentful/model/menu_button.rb, line 4
def external_uri
  @external_url ||= URI(external_link) if external_link.present?
end
fragment() click to toggle source
# File lib/wcc/contentful/model/menu_button.rb, line 26
def fragment
  WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link
end
href() click to toggle source

Gets either the external link or the slug from the referenced page. Example usage: `<%= link_to button.title, button.href %>`

# 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 url unless fragment.present?

  url = URI(url || '')
  url.fragment = fragment
  url.to_s
end