Sha256: 5ec048a0d30500cdecc761c87919579cedab2b4a4ffcfe859cfbf61c3c9d0b1b

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Primer
  # :nodoc:
  module ViewHelper
    # DSL to allow components to register a View Helper for shorthand calls.
    #
    # Example:
    #
    # class MyComponent < ViewComponent::Base
    #   include Primer::ViewHelper::DSL
    #   view_helper :my_component
    # end
    module DSL
      extend ActiveSupport::Concern

      class ViewHelperAlreadyDefined < StandardError; end

      included do
        class_attribute :primer_helpers, instance_writer: false, default: {}
      end

      class_methods do
        def view_helper(name)
          raise ViewHelperAlreadyDefined, "#{name} is already defined" if primer_helpers[name].present?

          primer_helpers[name] = self
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
primer_view_components-0.0.23 app/lib/primer/view_helper/dsl.rb
primer_view_components-0.0.22 app/lib/primer/view_helper/dsl.rb