Sha256: dca82fc91efcac354083ad76df88f254415713a5c236c06b47f1cb6955428373

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Primer
  module Forms
    # :nodoc:
    class BaseComponent
      include Primer::ClassNameHelper
      extend ActsAsComponent

      def self.inherited(base)
        base.renders_template(
          File.join("%{base_template_path}", "#{base.name.demodulize.underscore}.html.erb"),
          :render_template
        )
      end

      delegate :required?, :disabled?, :hidden?, to: :@input

      def perform_render(&block)
        return "" unless render?

        @__prf_content_block = block
        compile_and_render_template
      end

      def content
        return @__prf_content if defined?(@__prf_content_evaluated) && @__prf_content_evaluated

        @__prf_content_evaluated = true
        @__prf_content = capture do
          @__prf_content_block.call
        end
      end

      # :nocov:
      def type
        :component
      end
      # :nocov:

      def input?
        false
      end

      def to_component
        self
      end

      def render?
        true
      end

      private

      def compile_and_render_template
        self.class.compile! unless self.class.instance_methods(false).include?(:render_template)
        render_template
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/lib/primer/forms/base_component.rb
openproject-primer_view_components-0.52.2 app/lib/primer/forms/base_component.rb
primer_view_components-0.36.4 app/lib/primer/forms/base_component.rb