Sha256: 46b57d02e324ffd065e23617115dc835380cc3f9373976bf2201f56010df4179
Contents?: true
Size: 1.29 KB
Versions: 46
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require 'satis/concerns/contextual_translations' module Satis class ApplicationComponent < ViewComponent::Base include ViewComponent::Slotable include ActionView::Helpers::TranslationHelper include Turbo::FramesHelper attr_accessor :original_view_context delegate :add_helper, to: :class include Satis::Concerns::ContextualTranslations # def original_view_context # @template # end def component_name self.class.name.sub(/::Component$/, "").sub(/^Satis::/, "").underscore end def self.add_helper(name, component) if respond_to?(name) Satis.config.logger.warn("Helper #{name} already defined, skipping.") return end define_method(name) do |*args, **kwargs, &block| original_args = args.dup options = args.extract_options! instance = if options.key? :variant variant_component = component.to_s.sub(/::Component$/, "::#{options[:variant].to_s.camelize}::Component").safe_constantize (variant_component || component).new(*original_args, **kwargs) else kwargs[component_name.to_sym] = self component.new(*original_args, **kwargs) end original_view_context.render(instance, &block) end end end end
Version data entries
46 entries across 46 versions & 1 rubygems