Sha256: 0ee208d7f81e5437fb46c44a517b3d30790a4d3dcd7007058df6bb8740d56d51

Contents?: true

Size: 530 Bytes

Versions: 4

Compression:

Stored size: 530 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::Model::MenuButton < WCC::Contentful::Model
  validate_field :text, :String, :required
  validate_field :icon, :Asset, :optional
  validate_field :external_link, :String, :optional
  validate_field :link, :Link, :optional, link_to: 'page'

  # 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
    link&.try(:slug) || link&.try(:url)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wcc-contentful-0.2.2 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-0.2.1 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-0.2.0 lib/wcc/contentful/model/menu_button.rb
wcc-contentful-0.1.0 lib/wcc/contentful/model/menu_button.rb