Sha256: 68330b5c7d65e854365ad4e080d8850f66ba264f355a0a0be0dc9d1455ec55a1

Contents?: true

Size: 738 Bytes

Versions: 6

Compression:

Stored size: 738 Bytes

Contents

module Voom::Presenters::DSL::Components
  class Link < Typography

    VALID_TARGETS = %i[self blank].freeze

    attr_accessor :url,
                  :text,
                  :target

    def initialize(parent:, **attribs_, &block)
      super(type: :link, parent: parent, **attribs_, &block)

      @url = attribs_.delete(:url)
      @text = attribs_.delete(:text) { url }
      @target = validate_target(attribs_.delete(:target) { :self })

      expand!
    end

    private

    def validate_target(value)
      target = value&.to_sym

      unless VALID_TARGETS.include?(target)
        raise Errors::ParameterValidation,
              "target must be one of #{VALID_TARGETS.join(', ')}"
      end

      target
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
voom-presenters-2.1.2 lib/voom/presenters/dsl/components/link.rb
voom-presenters-2.1.0 lib/voom/presenters/dsl/components/link.rb
voom-presenters-2.0.3 lib/voom/presenters/dsl/components/link.rb
voom-presenters-2.0.2 lib/voom/presenters/dsl/components/link.rb
voom-presenters-2.0.1 lib/voom/presenters/dsl/components/link.rb
voom-presenters-2.0.0 lib/voom/presenters/dsl/components/link.rb