Sha256: 0d33a0e6d555670a83d6cbd809a2703a937d60daafc97a95a34e69da2ce2053a

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Heartml
  module Rails
    module ViewComponentBase
      def self.included(klass)
        klass.remove_method :render_template_for
        klass.extend ClassMethods
        klass.include Heartml
      end

      def render_in(view_context, rendering_mode: :string, &block)
        self.rendering_mode = rendering_mode
        super(view_context, &block)
      end

      def render_template_for(*) = call

      # No escaping required for the rendered HTML
      def maybe_escape_html(input) = input

      module ClassMethods
        def compile(*)
          # no-op
        end

        def compiled? = true

        def inherited(klass)
          super(klass)
          klass.source_location = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
          klass.virtual_path = klass.source_location.gsub(
            %r{(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)}, ""
          )
          Heartml::ServerEffects.included_extras(klass)
          klass.directives.merge! directives
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
heartml-1.0.0.beta18 lib/heartml/rails/view_component_base.rb
heartml-1.0.0.beta17 lib/heartml/rails/view_component_base.rb
heartml-1.0.0.beta16 lib/heartml/rails/view_component_base.rb
heartml-1.0.0.beta15 lib/heartml/rails/view_component_base.rb
heartml-1.0.0.beta14 lib/heartml/rails/view_component_base.rb