Sha256: 615525fe9abd0fa391359b23a28d8ce1bba3aa66250672d69a8b2df3d679abc4

Contents?: true

Size: 779 Bytes

Versions: 20

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::Model::MenuButton < WCC::Contentful::Model
  def external_uri
    @external_url ||= URI(external_link) if external_link.present?
  end

  # A menu link is external if `external_link` is present and not relative.
  def external?
    external_uri&.scheme.present?
  end

  # Gets either the external link or the slug from the referenced page.
  # Example usage: `<%= link_to button.title, button.href %>`
  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

  def fragment
    WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
wcc-contentful-app-1.3.2 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.3.1 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.3.0 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.2.1 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.2.0 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.1.2 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.1.1 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.1.0 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.8 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.7 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.6 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.5 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.4 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.3 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.2 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.1 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.0 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.0.pre.rc3 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.0.pre.rc2 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-app-1.0.0.pre.rc1 lib/wcc/contentful/model/menu_button.rb