Class: ViewComponent::Template::InlineCall

Inherits:
ViewComponent::Template show all
Defined in:
lib/view_component/template.rb

Instance Attribute Summary

Attributes inherited from ViewComponent::Template

#details, #path

Instance Method Summary collapse

Methods inherited from ViewComponent::Template

#call_method_name, #default_format?, #inline_call?, #normalized_variant_name, #requires_compiled_superclass?, #safe_method_name

Constructor Details

#initialize(component:, method_name:, defined_on_self:) ⇒ InlineCall

Returns a new instance of InlineCall.



64
65
66
67
68
69
70
71
72
# File 'lib/view_component/template.rb', line 64

def initialize(component:, method_name:, defined_on_self:)
  variant = method_name.to_s.include?("call_") ? method_name.to_s.sub("call_", "").to_sym : nil
  details = ActionView::TemplateDetails.new(nil, nil, DEFAULT_FORMAT, variant)

  super(component: component, details: details)

  @call_method_name = method_name
  @defined_on_self = defined_on_self
end

Instance Method Details

#compile_to_componentObject



78
79
80
# File 'lib/view_component/template.rb', line 78

def compile_to_component
  @component.define_method(safe_method_name, @component.instance_method(@call_method_name))
end

#defined_on_self?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/view_component/template.rb', line 92

def defined_on_self?
  @defined_on_self
end

#safe_method_name_callObject



82
83
84
85
86
87
88
89
90
# File 'lib/view_component/template.rb', line 82

def safe_method_name_call
  m = safe_method_name
  proc do
    __vc_maybe_escape_html(send(m)) do
      Kernel.warn("WARNING: The #{self.class} component rendered HTML-unsafe output. " \
                    "The output will be automatically escaped, but you may want to investigate.")
    end
  end
end

#typeObject



74
75
76
# File 'lib/view_component/template.rb', line 74

def type
  :inline_call
end