Class: Vident2::Phlex::HTML

Inherits:
Phlex::HTML
  • Object
show all
Includes:
Component
Defined in:
lib/vident2/phlex/html.rb

Constant Summary collapse

STANDARD_ELEMENTS =
%i[
  a abbr address article aside b bdi bdo blockquote body button caption
  cite code colgroup data datalist dd del details dfn dialog div dl dt
  em fieldset figcaption figure footer form g h1 h2 h3 h4 h5 h6 head
  header hgroup html i iframe ins kbd label legend li main map mark
  menuitem meter nav noscript object ol optgroup option output p path
  picture pre progress q rp rt ruby s samp script section select slot
  small span strong style sub summary sup svg table tbody td template_tag
  textarea tfoot th thead time title tr u ul video wbr
].freeze
VOID_ELEMENTS =
%i[area br embed hr img input link meta param source track col].freeze
VALID_TAGS =
Set[*(STANDARD_ELEMENTS + VOID_ELEMENTS)].freeze

Constants included from Component

Component::MUTATOR_METHODS, Component::PLURAL_PARSERS, Component::SINGULAR_NAMES, Component::SINGULAR_PARSERS

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Component

#after_component_initialize, #child_element, #class_list_for_stimulus_classes, #clone, #component_name, #id, #inspect, #outlet_id, #prop_names, #random_id, #resolve_stimulus_attributes_at_render_time, #root, #root_element_attributes, #root_element_classes, #stimulus_identifier, #stimulus_scoped_event, #stimulus_scoped_event_on_window

Methods included from Tailwind

#tailwind_merge_available?, #tailwind_merger

Class Attribute Details

.component_source_file_pathObject

Returns the value of attribute component_source_file_path.



33
34
35
# File 'lib/vident2/phlex/html.rb', line 33

def component_source_file_path
  @component_source_file_path
end

Class Method Details

.cache_component_modified_timeObject

Raises:

  • (StandardError)


35
36
37
38
39
# File 'lib/vident2/phlex/html.rb', line 35

def cache_component_modified_time
  path = component_source_file_path
  raise StandardError, "No component source file exists #{path}" unless path && ::File.exist?(path)
  ::File.mtime(path).to_i.to_s
end

.inherited(subclass) ⇒ Object

Capture the subclass’s defining ‘.rb` path at class-definition time so Caching#cache_component_modified_time can read its mtime. Walks caller_locations to skip the `inherited` frame itself.



27
28
29
30
31
# File 'lib/vident2/phlex/html.rb', line 27

def inherited(subclass)
  loc = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0]
  subclass.component_source_file_path = loc&.path
  super
end

Instance Method Details

#before_templateObject

Phlex lifecycle hook: resolve stimulus DSL procs now that ‘view_context` / `helpers` are wired. Procs declared in the DSL stayed unresolved at `after_initialize`; this is where they run.



45
46
47
48
# File 'lib/vident2/phlex/html.rb', line 45

def before_template
  resolve_stimulus_attributes_at_render_time
  super
end

#root_element(**overrides, &block) ⇒ Object

Block-capture-first so children initialising inside the block can mutate THIS instance’s Draft (outlet-host pattern). After the block returns, we seal the Draft and emit the tag.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vident2/phlex/html.rb', line 53

def root_element(**overrides, &block)
  tag_type = root_element_tag_type
  check_valid_html_tag!(tag_type)
  if block
    content = capture(self, &block).html_safe
    options = build_root_element_attributes(overrides)
    send(tag_type, **options) { content }
  else
    options = build_root_element_attributes(overrides)
    send(tag_type, **options)
  end
end