vident 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/README.md +45 -17
- data/lib/vident/caching.rb +4 -110
- data/lib/vident/capabilities/caching.rb +98 -0
- data/lib/vident/capabilities/child_element_rendering.rb +92 -0
- data/lib/vident/capabilities/class_list_building.rb +23 -0
- data/lib/vident/capabilities/declarable.rb +39 -0
- data/lib/vident/capabilities/identifiable.rb +54 -0
- data/lib/vident/capabilities/inspectable.rb +17 -0
- data/lib/vident/capabilities/root_element_rendering.rb +31 -0
- data/lib/vident/capabilities/stimulus_data_emitting.rb +98 -0
- data/lib/vident/capabilities/stimulus_declaring.rb +79 -0
- data/lib/vident/capabilities/stimulus_draft.rb +51 -0
- data/lib/vident/capabilities/stimulus_mutation.rb +60 -0
- data/lib/vident/capabilities/stimulus_parsing.rb +144 -0
- data/lib/vident/capabilities/tailwind.rb +18 -0
- data/lib/vident/component.rb +14 -76
- data/lib/vident/engine.rb +6 -5
- data/lib/vident/error.rb +16 -0
- data/lib/{vident2 → vident}/internals/action_builder.rb +18 -22
- data/lib/vident/internals/attribute_writer.rb +17 -0
- data/lib/{vident2 → vident}/internals/class_list_builder.rb +5 -22
- data/lib/vident/internals/declaration.rb +13 -0
- data/lib/{vident2 → vident}/internals/declarations.rb +6 -18
- data/lib/{vident2 → vident}/internals/draft.rb +3 -16
- data/lib/{vident2 → vident}/internals/dsl.rb +6 -32
- data/lib/vident/internals/plan.rb +9 -0
- data/lib/vident/internals/registry.rb +37 -0
- data/lib/{vident2 → vident}/internals/resolver.rb +101 -91
- data/lib/{vident2 → vident}/internals/target_builder.rb +1 -7
- data/lib/vident/stable_id.rb +3 -3
- data/lib/{vident2 → vident}/stimulus/action.rb +11 -24
- data/lib/vident/stimulus/base.rb +26 -0
- data/lib/{vident2 → vident}/stimulus/class_map.rb +6 -18
- data/lib/{vident2 → vident}/stimulus/collection.rb +6 -8
- data/lib/vident/stimulus/combinable.rb +30 -0
- data/lib/vident/stimulus/controller.rb +45 -0
- data/lib/vident/stimulus/naming.rb +9 -9
- data/lib/vident/stimulus/null.rb +7 -0
- data/lib/{vident2 → vident}/stimulus/outlet.rb +12 -32
- data/lib/{vident2 → vident}/stimulus/param.rb +5 -11
- data/lib/{vident2 → vident}/stimulus/target.rb +5 -14
- data/lib/vident/stimulus/value.rb +57 -0
- data/lib/vident/stimulus_null.rb +4 -8
- data/lib/vident/tailwind.rb +4 -17
- data/lib/vident/types.rb +28 -0
- data/lib/vident/version.rb +1 -6
- data/lib/vident.rb +46 -36
- data/skills/vident/SKILL.md +122 -19
- data/skills/vident/api-reference.md +259 -115
- data/skills/vident/examples.md +23 -10
- metadata +38 -60
- data/lib/vident/child_element_helper.rb +0 -64
- data/lib/vident/class_list_builder.rb +0 -112
- data/lib/vident/component_attribute_resolver.rb +0 -106
- data/lib/vident/component_class_lists.rb +0 -37
- data/lib/vident/stimulus/primitive.rb +0 -38
- data/lib/vident/stimulus.rb +0 -31
- data/lib/vident/stimulus_action.rb +0 -133
- data/lib/vident/stimulus_action_collection.rb +0 -11
- data/lib/vident/stimulus_attribute_base.rb +0 -67
- data/lib/vident/stimulus_attributes.rb +0 -129
- data/lib/vident/stimulus_builder.rb +0 -136
- data/lib/vident/stimulus_class.rb +0 -59
- data/lib/vident/stimulus_class_collection.rb +0 -11
- data/lib/vident/stimulus_collection_base.rb +0 -51
- data/lib/vident/stimulus_component.rb +0 -75
- data/lib/vident/stimulus_controller.rb +0 -41
- data/lib/vident/stimulus_controller_collection.rb +0 -14
- data/lib/vident/stimulus_data_attribute_builder.rb +0 -32
- data/lib/vident/stimulus_helper.rb +0 -66
- data/lib/vident/stimulus_outlet.rb +0 -90
- data/lib/vident/stimulus_outlet_collection.rb +0 -11
- data/lib/vident/stimulus_param.rb +0 -42
- data/lib/vident/stimulus_param_collection.rb +0 -11
- data/lib/vident/stimulus_target.rb +0 -47
- data/lib/vident/stimulus_target_collection.rb +0 -18
- data/lib/vident/stimulus_value.rb +0 -39
- data/lib/vident/stimulus_value_collection.rb +0 -11
- data/lib/vident2/caching.rb +0 -93
- data/lib/vident2/component.rb +0 -538
- data/lib/vident2/engine.rb +0 -18
- data/lib/vident2/error.rb +0 -30
- data/lib/vident2/internals/attribute_writer.rb +0 -22
- data/lib/vident2/internals/declaration.rb +0 -17
- data/lib/vident2/internals/plan.rb +0 -12
- data/lib/vident2/internals/registry.rb +0 -41
- data/lib/vident2/phlex/html.rb +0 -84
- data/lib/vident2/phlex.rb +0 -9
- data/lib/vident2/stimulus/controller.rb +0 -59
- data/lib/vident2/stimulus/naming.rb +0 -26
- data/lib/vident2/stimulus/null.rb +0 -16
- data/lib/vident2/stimulus/value.rb +0 -77
- data/lib/vident2/tailwind.rb +0 -19
- data/lib/vident2/version.rb +0 -5
- data/lib/vident2/view_component/base.rb +0 -124
- data/lib/vident2/view_component.rb +0 -9
- data/lib/vident2.rb +0 -50
data/lib/vident2/phlex/html.rb
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "set"
|
|
4
|
-
|
|
5
|
-
module Vident2
|
|
6
|
-
module Phlex
|
|
7
|
-
class HTML < ::Phlex::HTML
|
|
8
|
-
include ::Vident2::Component
|
|
9
|
-
|
|
10
|
-
STANDARD_ELEMENTS = %i[
|
|
11
|
-
a abbr address article aside b bdi bdo blockquote body button caption
|
|
12
|
-
cite code colgroup data datalist dd del details dfn dialog div dl dt
|
|
13
|
-
em fieldset figcaption figure footer form g h1 h2 h3 h4 h5 h6 head
|
|
14
|
-
header hgroup html i iframe ins kbd label legend li main map mark
|
|
15
|
-
menuitem meter nav noscript object ol optgroup option output p path
|
|
16
|
-
picture pre progress q rp rt ruby s samp script section select slot
|
|
17
|
-
small span strong style sub summary sup svg table tbody td template_tag
|
|
18
|
-
textarea tfoot th thead time title tr u ul video wbr
|
|
19
|
-
].freeze
|
|
20
|
-
VOID_ELEMENTS = %i[area br embed hr img input link meta param source track col].freeze
|
|
21
|
-
VALID_TAGS = Set[*(STANDARD_ELEMENTS + VOID_ELEMENTS)].freeze
|
|
22
|
-
|
|
23
|
-
class << self
|
|
24
|
-
# Capture the subclass's defining `.rb` path at class-definition
|
|
25
|
-
# time so Caching#cache_component_modified_time can read its mtime.
|
|
26
|
-
# Walks caller_locations to skip the `inherited` frame itself.
|
|
27
|
-
def inherited(subclass)
|
|
28
|
-
loc = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0]
|
|
29
|
-
subclass.component_source_file_path = loc&.path
|
|
30
|
-
super
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
attr_accessor :component_source_file_path
|
|
34
|
-
|
|
35
|
-
def cache_component_modified_time
|
|
36
|
-
path = component_source_file_path
|
|
37
|
-
raise StandardError, "No component source file exists #{path}" unless path && ::File.exist?(path)
|
|
38
|
-
::File.mtime(path).to_i.to_s
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Phlex lifecycle hook: resolve stimulus DSL procs now that
|
|
43
|
-
# `view_context` / `helpers` are wired. Procs declared in the DSL
|
|
44
|
-
# stayed unresolved at `after_initialize`; this is where they run.
|
|
45
|
-
def before_template
|
|
46
|
-
resolve_stimulus_attributes_at_render_time
|
|
47
|
-
super
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Block-capture-first so children initialising inside the block can
|
|
51
|
-
# mutate THIS instance's Draft (outlet-host pattern). After the
|
|
52
|
-
# block returns, we seal the Draft and emit the tag.
|
|
53
|
-
def root_element(**overrides, &block)
|
|
54
|
-
tag_type = root_element_tag_type
|
|
55
|
-
check_valid_html_tag!(tag_type)
|
|
56
|
-
if block
|
|
57
|
-
content = capture(self, &block).html_safe
|
|
58
|
-
options = build_root_element_attributes(overrides)
|
|
59
|
-
send(tag_type, **options) { content }
|
|
60
|
-
else
|
|
61
|
-
options = build_root_element_attributes(overrides)
|
|
62
|
-
send(tag_type, **options)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
|
|
68
|
-
def check_valid_html_tag!(tag_name)
|
|
69
|
-
return if VALID_TAGS.include?(tag_name)
|
|
70
|
-
raise ArgumentError,
|
|
71
|
-
"Unsupported HTML tag name #{tag_name}. Valid tags are: #{VALID_TAGS.to_a.join(", ")}"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Phlex tag DSL emits open-close pairs for non-void tags and
|
|
75
|
-
# self-closing for void tags automatically, so we just forward.
|
|
76
|
-
def generate_child_element(tag_name, stimulus_data_attributes, options, &block)
|
|
77
|
-
check_valid_html_tag!(tag_name)
|
|
78
|
-
options[:data] ||= {}
|
|
79
|
-
options[:data].merge!(stimulus_data_attributes)
|
|
80
|
-
send(tag_name, **options, &block)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
data/lib/vident2/phlex.rb
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "literal"
|
|
4
|
-
require_relative "naming"
|
|
5
|
-
|
|
6
|
-
module Vident2
|
|
7
|
-
module Stimulus
|
|
8
|
-
# `data-controller` fragment. Fields:
|
|
9
|
-
# - `path` : raw underscored path (e.g. `"admin/user_card_component"`)
|
|
10
|
-
# - `name` : dasherized/joined form (e.g. `"admin--user-card-component"`)
|
|
11
|
-
# - `alias_name`: optional Symbol the DSL uses to refer back to this
|
|
12
|
-
# controller from other entries (`action(:save, on: :admin)`).
|
|
13
|
-
class Controller < ::Literal::Data
|
|
14
|
-
prop :path, String
|
|
15
|
-
prop :name, String
|
|
16
|
-
prop :alias_name, _Nilable(Symbol), default: nil
|
|
17
|
-
|
|
18
|
-
# `.parse(path = nil, as: nil, implied:)`
|
|
19
|
-
#
|
|
20
|
-
# No positional arg -> clone the implied controller (for unambiguous
|
|
21
|
-
# "refer to my own controller" use).
|
|
22
|
-
#
|
|
23
|
-
# One positional arg (String | Symbol) -> explicit controller path.
|
|
24
|
-
# `implied:` is unused in that branch but is accepted for uniformity
|
|
25
|
-
# with the other kinds' `.parse` signatures.
|
|
26
|
-
def self.parse(*args, as: nil, implied:, component_id: nil)
|
|
27
|
-
case args.size
|
|
28
|
-
when 0
|
|
29
|
-
new(path: implied.path, name: implied.name, alias_name: as)
|
|
30
|
-
when 1
|
|
31
|
-
raw = args[0]
|
|
32
|
-
path = raw.to_s
|
|
33
|
-
new(path: path, name: Naming.stimulize_path(path), alias_name: as)
|
|
34
|
-
else
|
|
35
|
-
raise ::Vident2::ParseError, "Controller.parse: expected 0 or 1 positional args, got #{args.size}"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def identifier = name
|
|
40
|
-
|
|
41
|
-
def to_s = name
|
|
42
|
-
|
|
43
|
-
def to_data_pair = [:controller, name]
|
|
44
|
-
|
|
45
|
-
def to_h = {controller: name}
|
|
46
|
-
# Ruby's `{**x}` splat calls #to_hash; alias so users can splat the
|
|
47
|
-
# data-attr pair directly into a tag's `data:` option.
|
|
48
|
-
alias_method :to_hash, :to_h
|
|
49
|
-
|
|
50
|
-
# Space-joined. Order preserved, duplicates kept (caller dedups).
|
|
51
|
-
def self.to_data_hash(controllers)
|
|
52
|
-
return {} if controllers.empty?
|
|
53
|
-
joined = controllers.map(&:name).reject(&:empty?).join(" ")
|
|
54
|
-
return {} if joined.empty?
|
|
55
|
-
{controller: joined}
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_support/core_ext/string/inflections"
|
|
4
|
-
|
|
5
|
-
module Vident2
|
|
6
|
-
module Stimulus
|
|
7
|
-
# Pure naming helpers shared across value classes. No state, no
|
|
8
|
-
# inheritance — the v1 `StimulusAttributeBase` tree goes away in V2;
|
|
9
|
-
# each value class is a `Literal::Data` and just calls these module
|
|
10
|
-
# functions directly.
|
|
11
|
-
module Naming
|
|
12
|
-
module_function
|
|
13
|
-
|
|
14
|
-
# `"admin/users"` -> `"admin--users"`. Symbol or String accepted.
|
|
15
|
-
def stimulize_path(path)
|
|
16
|
-
path.to_s.split("/").map(&:dasherize).join("--")
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# `:my_thing` -> `"myThing"`. Used for action method names and
|
|
20
|
-
# target names (not for attribute keys, which dasherize instead).
|
|
21
|
-
def js_name(name)
|
|
22
|
-
name.to_s.camelize(:lower)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Vident2
|
|
4
|
-
module Stimulus
|
|
5
|
-
# Sentinel that serialises to the literal string "null". Use in
|
|
6
|
-
# `value` / `param` positions where the Stimulus side expects a
|
|
7
|
-
# JSON-parsed JS `null` (Object / Array value types).
|
|
8
|
-
#
|
|
9
|
-
# A bare `nil` drops the attribute entirely. Reach for Null only when
|
|
10
|
-
# you need an explicit `"null"` in the emitted HTML.
|
|
11
|
-
Null = Object.new
|
|
12
|
-
def Null.inspect = "Vident2::Stimulus::Null"
|
|
13
|
-
def Null.to_s = "null"
|
|
14
|
-
Null.freeze
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "json"
|
|
4
|
-
require "literal"
|
|
5
|
-
require_relative "naming"
|
|
6
|
-
require_relative "controller"
|
|
7
|
-
require_relative "null"
|
|
8
|
-
|
|
9
|
-
module Vident2
|
|
10
|
-
module Stimulus
|
|
11
|
-
# `data-<ctrl>-<name>-value` fragment. Holds the *serialised* form
|
|
12
|
-
# (always a String post-parse); Array/Hash inputs go through `to_json`,
|
|
13
|
-
# other non-nil inputs through `to_s`. The `Null` sentinel's `to_s`
|
|
14
|
-
# produces `"null"` naturally. Only `nil` drops at the caller —
|
|
15
|
-
# `false`, blank strings, and empty collections emit their serialised
|
|
16
|
-
# form.
|
|
17
|
-
class Value < ::Literal::Data
|
|
18
|
-
prop :controller, Controller
|
|
19
|
-
prop :name, String
|
|
20
|
-
prop :serialized, String
|
|
21
|
-
|
|
22
|
-
# `.parse(*args, implied:)` grammar:
|
|
23
|
-
# (Symbol, raw) -> implied controller, value named `Symbol`
|
|
24
|
-
# (String, Symbol, raw) -> explicit (controller_path, name, raw)
|
|
25
|
-
#
|
|
26
|
-
# The caller (Resolver / mutator) is responsible for filtering out
|
|
27
|
-
# `nil` before reaching here — see `serialize` for the check.
|
|
28
|
-
def self.parse(*args, implied:, component_id: nil)
|
|
29
|
-
case args
|
|
30
|
-
in [Symbol => name_sym, raw]
|
|
31
|
-
new(
|
|
32
|
-
controller: implied,
|
|
33
|
-
name: name_sym.to_s.dasherize,
|
|
34
|
-
serialized: serialize(raw)
|
|
35
|
-
)
|
|
36
|
-
in [String => ctrl_path, Symbol => name_sym, raw]
|
|
37
|
-
new(
|
|
38
|
-
controller: Controller.parse(ctrl_path, implied: implied),
|
|
39
|
-
name: name_sym.to_s.dasherize,
|
|
40
|
-
serialized: serialize(raw)
|
|
41
|
-
)
|
|
42
|
-
else
|
|
43
|
-
raise ::Vident2::ParseError, "Value.parse: invalid arguments #{args.inspect}"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Raw -> String. `Null` sentinel serialises to `"null"` via its
|
|
48
|
-
# own `to_s`. `nil` should have been filtered upstream; raising
|
|
49
|
-
# here catches misrouted callers early.
|
|
50
|
-
def self.serialize(raw)
|
|
51
|
-
raise ::Vident2::ParseError, "Value.serialize: nil is not serializable — filter nil upstream" if raw.nil?
|
|
52
|
-
case raw
|
|
53
|
-
when Array, Hash then raw.to_json
|
|
54
|
-
else raw.to_s
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def to_s = serialized
|
|
59
|
-
|
|
60
|
-
def data_attribute_key = :"#{controller.name}-#{name}-value"
|
|
61
|
-
|
|
62
|
-
def to_data_pair = [data_attribute_key, serialized]
|
|
63
|
-
|
|
64
|
-
def to_h = {data_attribute_key => serialized}
|
|
65
|
-
alias_method :to_hash, :to_h
|
|
66
|
-
|
|
67
|
-
# One entry per Value instance. Later-instance same-key wins on
|
|
68
|
-
# collision (Hash#merge semantics).
|
|
69
|
-
def self.to_data_hash(values)
|
|
70
|
-
values.each_with_object({}) do |v, acc|
|
|
71
|
-
key, str = v.to_data_pair
|
|
72
|
-
acc[key] = str
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
data/lib/vident2/tailwind.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Vident2
|
|
4
|
-
# Thin Tailwind CSS merge integration — exposes a lazy per-thread merger
|
|
5
|
-
# instance so the ClassListBuilder can collapse conflicting utilities
|
|
6
|
-
# when ::TailwindMerge::Merger is available.
|
|
7
|
-
module Tailwind
|
|
8
|
-
def tailwind_merger
|
|
9
|
-
return unless tailwind_merge_available?
|
|
10
|
-
return @tailwind_merger if defined?(@tailwind_merger)
|
|
11
|
-
|
|
12
|
-
@tailwind_merger = Thread.current[:vident2_tailwind_merger] ||= ::TailwindMerge::Merger.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def tailwind_merge_available?
|
|
16
|
-
defined?(::TailwindMerge::Merger) && ::TailwindMerge::Merger.respond_to?(:new)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
data/lib/vident2/version.rb
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "set"
|
|
4
|
-
|
|
5
|
-
module Vident2
|
|
6
|
-
module ViewComponent
|
|
7
|
-
class Base < ::ViewComponent::Base
|
|
8
|
-
include ::Vident2::Component
|
|
9
|
-
|
|
10
|
-
class << self
|
|
11
|
-
def cache_component_modified_time
|
|
12
|
-
cache_sidecar_view_modified_time + cache_rb_component_modified_time
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def cache_sidecar_view_modified_time
|
|
16
|
-
::File.exist?(template_path) ? ::File.mtime(template_path).to_i.to_s : ""
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def cache_rb_component_modified_time
|
|
20
|
-
::File.exist?(component_path) ? ::File.mtime(component_path).to_i.to_s : ""
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def template_path
|
|
24
|
-
extensions = [".html.erb", ".erb", ".html.haml", ".haml", ".html.slim", ".slim"]
|
|
25
|
-
base_path = Rails.root.join(components_base_path, virtual_path)
|
|
26
|
-
|
|
27
|
-
extensions.each do |ext|
|
|
28
|
-
potential_path = "#{base_path}#{ext}"
|
|
29
|
-
return potential_path if File.exist?(potential_path)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
Rails.root.join(components_base_path, "#{virtual_path}.html.erb").to_s
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def component_path
|
|
36
|
-
Rails.root.join(components_base_path, "#{virtual_path}.rb").to_s
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def components_base_path
|
|
40
|
-
::Rails.configuration.view_component.view_component_path || "app/components"
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
SELF_CLOSING_TAGS = Set[*%i[area base br col embed hr img input link meta param source track wbr]].freeze
|
|
45
|
-
|
|
46
|
-
# ViewComponent lifecycle hook: resolve stimulus DSL procs now that
|
|
47
|
-
# `@view_context` is set (so `helpers` works inside them).
|
|
48
|
-
def before_render
|
|
49
|
-
resolve_stimulus_attributes_at_render_time
|
|
50
|
-
super
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Same block-capture-first ordering as the Phlex adapter. Children
|
|
54
|
-
# instantiated inside the block can still mutate this instance's
|
|
55
|
-
# Draft (outlet-host pattern) before we seal.
|
|
56
|
-
def root_element(**overrides, &block)
|
|
57
|
-
tag_type = root_element_tag_type
|
|
58
|
-
child_content = view_context.capture(self, &block) if block
|
|
59
|
-
options = build_root_element_attributes(overrides)
|
|
60
|
-
if SELF_CLOSING_TAGS.include?(tag_type)
|
|
61
|
-
view_context.tag(tag_type, options)
|
|
62
|
-
else
|
|
63
|
-
view_context.content_tag(tag_type, child_content, options)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Inline ERB helpers: emit `data-*="..."` attribute strings for the
|
|
68
|
-
# given stimulus input. Thin wrappers around the plural/singular
|
|
69
|
-
# parsers — Collection#to_h is the splat target used by v1's helpers
|
|
70
|
-
# too. Returns an ActiveSupport::SafeBuffer.
|
|
71
|
-
def as_stimulus_targets(...) = to_data_attribute_string(**stimulus_targets(...).to_h)
|
|
72
|
-
def as_stimulus_target(...) = to_data_attribute_string(**stimulus_target(...).to_h)
|
|
73
|
-
def as_stimulus_actions(...) = to_data_attribute_string(**stimulus_actions(...).to_h)
|
|
74
|
-
def as_stimulus_action(...) = to_data_attribute_string(**stimulus_action(...).to_h)
|
|
75
|
-
def as_stimulus_controllers(...) = to_data_attribute_string(**stimulus_controllers(...).to_h)
|
|
76
|
-
def as_stimulus_controller(...) = to_data_attribute_string(**stimulus_controller(...).to_h)
|
|
77
|
-
def as_stimulus_outlets(...) = to_data_attribute_string(**stimulus_outlets(...).to_h)
|
|
78
|
-
def as_stimulus_outlet(...) = to_data_attribute_string(**stimulus_outlet(...).to_h)
|
|
79
|
-
def as_stimulus_values(...) = to_data_attribute_string(**stimulus_values(...).to_h)
|
|
80
|
-
def as_stimulus_value(...) = to_data_attribute_string(**stimulus_value(...).to_h)
|
|
81
|
-
def as_stimulus_params(...) = to_data_attribute_string(**stimulus_params(...).to_h)
|
|
82
|
-
def as_stimulus_param(...) = to_data_attribute_string(**stimulus_param(...).to_h)
|
|
83
|
-
def as_stimulus_classes(...) = to_data_attribute_string(**stimulus_classes(...).to_h)
|
|
84
|
-
def as_stimulus_class(...) = to_data_attribute_string(**stimulus_class(...).to_h)
|
|
85
|
-
|
|
86
|
-
# Short aliases — same semantics as the singular `as_stimulus_*` above.
|
|
87
|
-
alias_method :as_target, :as_stimulus_target
|
|
88
|
-
alias_method :as_action, :as_stimulus_action
|
|
89
|
-
alias_method :as_controller, :as_stimulus_controller
|
|
90
|
-
alias_method :as_outlet, :as_stimulus_outlet
|
|
91
|
-
alias_method :as_value, :as_stimulus_value
|
|
92
|
-
alias_method :as_param, :as_stimulus_param
|
|
93
|
-
alias_method :as_class, :as_stimulus_class
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
|
|
97
|
-
def generate_child_element(tag_name, stimulus_data_attributes, options, &block)
|
|
98
|
-
options[:data] ||= {}
|
|
99
|
-
options[:data].merge!(stimulus_data_attributes)
|
|
100
|
-
if SELF_CLOSING_TAGS.include?(tag_name.to_sym)
|
|
101
|
-
view_context.tag(tag_name, options)
|
|
102
|
-
elsif block
|
|
103
|
-
view_context.content_tag(tag_name, view_context.capture(&block), options)
|
|
104
|
-
else
|
|
105
|
-
view_context.content_tag(tag_name, nil, options)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def escape_attribute_name_for_html(name)
|
|
110
|
-
name.to_s.gsub(/[^a-zA-Z0-9\-_]/, "").tr("_", "-")
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def escape_attribute_value_for_html(value)
|
|
114
|
-
value.to_s.gsub('"', """).gsub("'", "'")
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def to_data_attribute_string(**attributes)
|
|
118
|
-
attributes.map { |key, value| "data-#{escape_attribute_name_for_html(key)}=\"#{escape_attribute_value_for_html(value)}\"" }
|
|
119
|
-
.join(" ")
|
|
120
|
-
.html_safe
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
data/lib/vident2.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_support"
|
|
4
|
-
require "active_support/concern"
|
|
5
|
-
require "literal"
|
|
6
|
-
|
|
7
|
-
require "vident2/version"
|
|
8
|
-
|
|
9
|
-
# Vident 2.0 — synthesis rearchitecture per doc/reviews/wave-4-synthesis.md.
|
|
10
|
-
# Built side-by-side with Vident 1.x during development; renamed to Vident
|
|
11
|
-
# at release.
|
|
12
|
-
module Vident2
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# V1 still ships alongside V2 — Vident::StableId is aliased as
|
|
16
|
-
# Vident2::StableId in lib/vident2/stable_id.rb so the V2 namespace stays
|
|
17
|
-
# self-referential.
|
|
18
|
-
require "vident"
|
|
19
|
-
|
|
20
|
-
require "vident2/engine" if defined?(Rails::Engine)
|
|
21
|
-
require "vident2/error"
|
|
22
|
-
require "vident2/stable_id"
|
|
23
|
-
|
|
24
|
-
require "vident2/stimulus/naming"
|
|
25
|
-
require "vident2/stimulus/null"
|
|
26
|
-
require "vident2/stimulus/controller"
|
|
27
|
-
require "vident2/stimulus/action"
|
|
28
|
-
require "vident2/stimulus/target"
|
|
29
|
-
require "vident2/stimulus/outlet"
|
|
30
|
-
require "vident2/stimulus/value"
|
|
31
|
-
require "vident2/stimulus/param"
|
|
32
|
-
require "vident2/stimulus/class_map"
|
|
33
|
-
require "vident2/stimulus/collection"
|
|
34
|
-
require "vident2/internals/registry"
|
|
35
|
-
require "vident2/internals/declaration"
|
|
36
|
-
require "vident2/internals/declarations"
|
|
37
|
-
require "vident2/internals/dsl"
|
|
38
|
-
require "vident2/internals/draft"
|
|
39
|
-
require "vident2/internals/plan"
|
|
40
|
-
require "vident2/internals/resolver"
|
|
41
|
-
require "vident2/internals/attribute_writer"
|
|
42
|
-
require "vident2/internals/class_list_builder"
|
|
43
|
-
|
|
44
|
-
require "vident2/tailwind"
|
|
45
|
-
require "vident2/caching"
|
|
46
|
-
|
|
47
|
-
require "vident2/component"
|
|
48
|
-
|
|
49
|
-
require "vident2/phlex"
|
|
50
|
-
require "vident2/view_component"
|