Sha256: d31bdfc23e423cf616413c988081e869c34d33d4d0e28e802d98c05c635ef5f4

Contents?: true

Size: 739 Bytes

Versions: 12

Compression:

Stored size: 739 Bytes

Contents

module Coprl::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

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.11 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.10 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.9 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.8 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.7 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.6 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.5 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.4 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.3 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.2 lib/coprl/presenters/dsl/components/link.rb
coprl-3.0.0.beta.1 lib/coprl/presenters/dsl/components/link.rb