vident-phlex 0.13.1 → 1.0.0.alpha2
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 +34 -0
- data/README.md +547 -661
- data/lib/vident/phlex/html.rb +49 -6
- data/lib/vident/phlex.rb +0 -2
- metadata +6 -8
- data/lib/vident/phlex/core.rb +0 -29
- data/lib/vident/phlex/root_component.rb +0 -55
data/lib/vident/phlex/html.rb
CHANGED
@@ -2,17 +2,60 @@
|
|
2
2
|
|
3
3
|
module Vident
|
4
4
|
module Phlex
|
5
|
-
class HTML <
|
5
|
+
class HTML < ::Phlex::HTML
|
6
6
|
include ::Vident::Component
|
7
7
|
|
8
|
+
STANDARD_ELEMENTS = [: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
|
9
|
+
VOID_ELEMENTS = [:area, :br, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :col].freeze
|
10
|
+
VALID_TAGS = Set[*(STANDARD_ELEMENTS + VOID_ELEMENTS)].freeze
|
11
|
+
|
8
12
|
class << self
|
9
|
-
|
10
|
-
|
11
|
-
# variables directly.
|
12
|
-
def attribute(name, **options)
|
13
|
-
options[:delegates] = false
|
13
|
+
def inherited(subclass)
|
14
|
+
subclass.component_source_file_path = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
|
14
15
|
super
|
15
16
|
end
|
17
|
+
|
18
|
+
attr_accessor :component_source_file_path
|
19
|
+
|
20
|
+
# Caching support
|
21
|
+
def cache_component_modified_time
|
22
|
+
path = component_source_file_path
|
23
|
+
raise StandardError, "No component source file exists #{path}" unless path && ::File.exist?(path)
|
24
|
+
::File.mtime(path).to_i.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Helper to create the main element
|
29
|
+
def root_element(&block)
|
30
|
+
tag_type = root_element_tag_type
|
31
|
+
check_valid_html_tag!(tag_type)
|
32
|
+
# Evaluate before generating the outer tag options to ensure DSL methods are executed
|
33
|
+
if block_given?
|
34
|
+
content = capture(self, &block).html_safe
|
35
|
+
options = root_element_tag_options
|
36
|
+
if content
|
37
|
+
send(tag_type, **options) { content }
|
38
|
+
else
|
39
|
+
send(tag_type, **options)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
send(tag_type, **root_element_tag_options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def check_valid_html_tag!(tag_name)
|
49
|
+
unless VALID_TAGS.include?(tag_name)
|
50
|
+
raise ArgumentError, "Unsupported HTML tag name #{tag_name}. Valid tags are: #{VALID_TAGS.to_a.join(", ")}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_tag(tag_type, stimulus_data_attributes, options, &block)
|
55
|
+
options[:data] ||= {}
|
56
|
+
options[:data].merge!(stimulus_data_attributes)
|
57
|
+
check_valid_html_tag!(tag_type)
|
58
|
+
send(tag_type, **options, &block)
|
16
59
|
end
|
17
60
|
end
|
18
61
|
end
|
data/lib/vident/phlex.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident-phlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-07-08 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: railties
|
@@ -55,21 +55,21 @@ dependencies:
|
|
55
55
|
requirements:
|
56
56
|
- - "~>"
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 0.
|
58
|
+
version: 1.0.0.alpha2
|
59
59
|
type: :runtime
|
60
60
|
prerelease: false
|
61
61
|
version_requirements: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
63
|
- - "~>"
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
65
|
+
version: 1.0.0.alpha2
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: phlex
|
68
68
|
requirement: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
72
|
+
version: '2.0'
|
73
73
|
- - "<"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3'
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '2.0'
|
83
83
|
- - "<"
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '3'
|
@@ -114,10 +114,8 @@ files:
|
|
114
114
|
- LICENSE.txt
|
115
115
|
- README.md
|
116
116
|
- lib/vident/phlex.rb
|
117
|
-
- lib/vident/phlex/core.rb
|
118
117
|
- lib/vident/phlex/engine.rb
|
119
118
|
- lib/vident/phlex/html.rb
|
120
|
-
- lib/vident/phlex/root_component.rb
|
121
119
|
- lib/vident/phlex/version.rb
|
122
120
|
homepage: https://github.com/stevegeek/vident
|
123
121
|
licenses:
|
data/lib/vident/phlex/core.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Vident
|
4
|
-
module Phlex
|
5
|
-
class Core < ::Phlex::HTML
|
6
|
-
class << self
|
7
|
-
def inherited(subclass)
|
8
|
-
subclass.component_source_file_path = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_accessor :component_source_file_path
|
13
|
-
|
14
|
-
# Caching support
|
15
|
-
def current_component_modified_time
|
16
|
-
path = component_source_file_path
|
17
|
-
raise StandardError, "No component source file exists #{path}" unless path && ::File.exist?(path)
|
18
|
-
::File.mtime(path).to_i.to_s
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Helper to create the main element
|
23
|
-
def parent_element
|
24
|
-
@parent_element ||= ::Vident::Phlex::RootComponent.new(**stimulus_options_for_root_component)
|
25
|
-
end
|
26
|
-
alias_method :root, :parent_element
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Vident
|
4
|
-
module Phlex
|
5
|
-
class RootComponent < ::Phlex::HTML
|
6
|
-
include ::Vident::RootComponent
|
7
|
-
|
8
|
-
if Gem.loaded_specs.has_key? "better_html"
|
9
|
-
begin
|
10
|
-
include ::Vident::BetterHtml::RootComponent
|
11
|
-
rescue
|
12
|
-
raise "if `better_html`` is being used you must install `vident-better_html"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
STANDARD_ELEMENTS = [: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
|
17
|
-
VOID_ELEMENTS = [:area, :br, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :col].freeze
|
18
|
-
|
19
|
-
VALID_TAGS = Set[*(STANDARD_ELEMENTS + VOID_ELEMENTS)].freeze
|
20
|
-
|
21
|
-
# Create a tag for a target with a block containing content
|
22
|
-
def target_tag(tag_name, targets, **options, &block)
|
23
|
-
parsed = parse_targets(Array.wrap(targets))
|
24
|
-
options[:data] ||= {}
|
25
|
-
options[:data].merge!(build_target_data_attributes(parsed))
|
26
|
-
generate_tag(tag_name, nil, **options, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Build a tag with the attributes determined by this components properties and stimulus
|
30
|
-
# data attributes.
|
31
|
-
def view_template(&block)
|
32
|
-
# Generate tag options and render
|
33
|
-
tag_type = @element_tag.presence&.to_sym || :div
|
34
|
-
raise ArgumentError, "Unsupported HTML tag name #{tag_type}" unless VALID_TAGS.include?(tag_type)
|
35
|
-
options = @html_options&.dup || {}
|
36
|
-
block_content = capture(&block) if block # Evaluate before generating the outer tag options to ensure DSL methods are executed
|
37
|
-
data_attrs = tag_data_attributes
|
38
|
-
data_attrs = options[:data].present? ? data_attrs.merge(options[:data]) : data_attrs
|
39
|
-
options = options.merge(id: @id) if @id
|
40
|
-
options.except!(:data)
|
41
|
-
options.merge!(data_attrs.transform_keys { |k| "data-#{k}" })
|
42
|
-
generate_tag(tag_type, block_content, **options)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def generate_tag(tag_type, content, **options, &block)
|
48
|
-
# FIXME: Content was generated by the block, we assume its safe but that might not be true!
|
49
|
-
method_name = (tag_type == :template) ? :template_tag : tag_type
|
50
|
-
block = proc { raw content.html_safe } if !block && content
|
51
|
-
send(method_name, **options, &block)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|