Class: Satis::ApplicationComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ActionView::Helpers::TranslationHelper, Concerns::ContextualTranslations, Turbo::FramesHelper, ViewComponent::Slotable
Defined in:
app/components/satis/application_component.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_view_contextObject

Returns the value of attribute original_view_context.



11
12
13
# File 'app/components/satis/application_component.rb', line 11

def original_view_context
  @original_view_context
end

Class Method Details

.add_helper(name, component) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/satis/application_component.rb', line 24

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

Instance Method Details

#component_nameObject

def original_view_context

@template

end



20
21
22
# File 'app/components/satis/application_component.rb', line 20

def component_name
  self.class.name.sub(/::Component$/, "").sub(/^Satis::/, "").underscore
end