Class: Vident::ViewComponent::Base
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Vident::ViewComponent::Base
- Includes:
- Component
- Defined in:
- lib/vident/view_component/base.rb
Constant Summary collapse
- SELF_CLOSING_TAGS =
Set[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
Class Method Summary collapse
- .cache_component_modified_time ⇒ Object
- .cache_rb_component_modified_time ⇒ Object
- .cache_sidecar_view_modified_time ⇒ Object
- .component_path ⇒ Object
- .components_base_path ⇒ Object
- .template_path ⇒ Object
Instance Method Summary collapse
- #as_stimulus_action ⇒ Object
- #as_stimulus_actions ⇒ Object
- #as_stimulus_class ⇒ Object
- #as_stimulus_classes ⇒ Object
- #as_stimulus_controller ⇒ Object
- #as_stimulus_controllers ⇒ Object
- #as_stimulus_outlet ⇒ Object
- #as_stimulus_outlets ⇒ Object
- #as_stimulus_target ⇒ Object
- #as_stimulus_targets ⇒ Object
- #as_stimulus_value ⇒ Object
- #as_stimulus_values ⇒ Object
- #root_element(**overrides, &block) ⇒ Object
Class Method Details
.cache_component_modified_time ⇒ Object
7 8 9 |
# File 'lib/vident/view_component/base.rb', line 7 def cache_component_modified_time cache_sidecar_view_modified_time + cache_rb_component_modified_time end |
.cache_rb_component_modified_time ⇒ Object
15 16 17 |
# File 'lib/vident/view_component/base.rb', line 15 def cache_rb_component_modified_time ::File.exist?(component_path) ? ::File.mtime(component_path).to_i.to_s : "" end |
.cache_sidecar_view_modified_time ⇒ Object
11 12 13 |
# File 'lib/vident/view_component/base.rb', line 11 def cache_sidecar_view_modified_time ::File.exist?(template_path) ? ::File.mtime(template_path).to_i.to_s : "" end |
.component_path ⇒ Object
33 34 35 |
# File 'lib/vident/view_component/base.rb', line 33 def component_path Rails.root.join(components_base_path, "#{virtual_path}.rb").to_s end |
.components_base_path ⇒ Object
37 38 39 |
# File 'lib/vident/view_component/base.rb', line 37 def components_base_path ::Rails.configuration.view_component.view_component_path || "app/components" end |
.template_path ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vident/view_component/base.rb', line 19 def template_path # Check for common ViewComponent template extensions in order of preference extensions = [".html.erb", ".erb", ".html.haml", ".haml", ".html.slim", ".slim"] base_path = Rails.root.join(components_base_path, virtual_path) extensions.each do |ext| potential_path = "#{base_path}#{ext}" return potential_path if File.exist?(potential_path) end # Return the default .html.erb path if no template is found Rails.root.join(components_base_path, "#{virtual_path}.html.erb").to_s end |
Instance Method Details
#as_stimulus_action ⇒ Object
67 68 69 |
# File 'lib/vident/view_component/base.rb', line 67 def as_stimulus_action(...) to_data_attribute_string(**stimulus_action(...)) end |
#as_stimulus_actions ⇒ Object
63 64 65 |
# File 'lib/vident/view_component/base.rb', line 63 def as_stimulus_actions(...) to_data_attribute_string(**stimulus_actions(...)) end |
#as_stimulus_class ⇒ Object
99 100 101 |
# File 'lib/vident/view_component/base.rb', line 99 def as_stimulus_class(...) to_data_attribute_string(**stimulus_class(...)) end |
#as_stimulus_classes ⇒ Object
95 96 97 |
# File 'lib/vident/view_component/base.rb', line 95 def as_stimulus_classes(...) to_data_attribute_string(**stimulus_classes(...)) end |
#as_stimulus_controller ⇒ Object
75 76 77 |
# File 'lib/vident/view_component/base.rb', line 75 def as_stimulus_controller(...) to_data_attribute_string(**stimulus_controller(...)) end |
#as_stimulus_controllers ⇒ Object
71 72 73 |
# File 'lib/vident/view_component/base.rb', line 71 def as_stimulus_controllers(...) to_data_attribute_string(**stimulus_controllers(...)) end |
#as_stimulus_outlet ⇒ Object
83 84 85 |
# File 'lib/vident/view_component/base.rb', line 83 def as_stimulus_outlet(...) to_data_attribute_string(**stimulus_outlet(...)) end |
#as_stimulus_outlets ⇒ Object
79 80 81 |
# File 'lib/vident/view_component/base.rb', line 79 def as_stimulus_outlets(...) to_data_attribute_string(**stimulus_outlets(...)) end |
#as_stimulus_target ⇒ Object
59 60 61 |
# File 'lib/vident/view_component/base.rb', line 59 def as_stimulus_target(...) to_data_attribute_string(**stimulus_target(...)) end |
#as_stimulus_targets ⇒ Object
55 56 57 |
# File 'lib/vident/view_component/base.rb', line 55 def as_stimulus_targets(...) to_data_attribute_string(**stimulus_targets(...)) end |
#as_stimulus_value ⇒ Object
91 92 93 |
# File 'lib/vident/view_component/base.rb', line 91 def as_stimulus_value(...) to_data_attribute_string(**stimulus_value(...)) end |
#as_stimulus_values ⇒ Object
87 88 89 |
# File 'lib/vident/view_component/base.rb', line 87 def as_stimulus_values(...) to_data_attribute_string(**stimulus_values(...)) end |
#root_element(**overrides, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vident/view_component/base.rb', line 44 def root_element(**overrides, &block) tag_type = root_element_tag_type child_content = view_context.capture(self, &block) if block_given? # Evaluate before generating the outer tag options to ensure DSL methods are executed = resolve_root_element_attributes_before_render(overrides) if SELF_CLOSING_TAGS.include?(tag_type) view_context.tag(tag_type, ) else view_context.content_tag(tag_type, child_content, ) end end |