Sha256: e2884d07d05647d9958396a2009a782142b31f286ca030e58ac4aa8649cdee40

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module Plutonium
  module Core
    module Definers
      module RendererDefiner
        extend ActiveSupport::Concern
        include Plutonium::Core::Autodiscovery::RendererDiscoverer

        def defined_renderers_for(names)
          (names - renderer_definitions.keys).each do |name|
            define_renderer(name, renderer: autodiscover_renderer(name))
          end
          renderer_definitions.slice(*names)
        end

        private

        def renderer_definitions = @renderer_definitions ||= {}

        def define_renderer(name, renderer: nil, type: nil, **options)
          renderer_definitions[name] = if renderer.present?
            renderer
          elsif type.present? || options.present?
            Plutonium::Core::Fields::Renderers::Factory.for_resource_attribute(context.resource_class, name, type:, **options)
          else
            autodiscover_renderer(name)
          end
        end

        def renderer_defined?(name)
          renderer_definitions.key? name
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
plutonium-0.6.2 lib/plutonium/core/definers/renderer_definer.rb
plutonium-0.6.1 lib/plutonium/core/definers/renderer_definer.rb
plutonium-0.6.0 lib/plutonium/core/definers/renderer_definer.rb
plutonium-0.5.0 lib/plutonium/core/definers/renderer_definer.rb