vident-phlex 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 731f9c7918cc00ef43f05fc30ad246d168c2a5484d1ed2e56be7133b38ef5898
4
- data.tar.gz: fe49bbf87d991a04eca3f7796d8a8fdb1fc1b6ed04ba69e03d7ae2f8fe8274b0
3
+ metadata.gz: 491b0cefd3a8305411d28a0f622b26d23353110e3c6b14a1f2dcbee1e66778d3
4
+ data.tar.gz: 679f4b3f77509ea345f0c656cd47d401407e38289e786cb799cd415bd1a9d73f
5
5
  SHA512:
6
- metadata.gz: d439e0ba255d7fd23f06669906ca1abdc482dfbc1e097178709760575c129e9ba37e6cafaf1140f4977e19484b9e59a2ca07441555f7467e420a2007378d1f08
7
- data.tar.gz: 6ed48a31f50e9ccb3f19df915c4720cbfc0eb37d47ba3f5c503c41604e64c9038d024e2268cc76a3015e79198668723d9bdc47e74fb864c7ede101cc97f246a8
6
+ metadata.gz: bbb631b7ff3bc67bcdfda2452defaaedaea85ba97ba286ddf71c17a462c0973ef57e21426f5e46b4e22be11d9df359b87678b18a499dbac64cee8f4bc6deda9d
7
+ data.tar.gz: 2014550736235ba4d7f9375af0d8ee463943b7481e13855d63d12b47116c2a79e21073c03fdf0b1b4f8de7565d5a73208016292276ab25a2d522070a20c78224
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Vident::Phlex
2
- Short description and motivation.
2
+
3
+ [Phlex](https://phlex.fun/) powered [Vident](https://github.com/stevegeek/vident) components.
4
+
5
+ ```ruby
6
+ class ApplicationComponent < ::Vident::Phlex::HTML
7
+ end
8
+ ```
9
+
10
+ For more details see [vident](https://github.com/stevegeek/vident).
3
11
 
4
12
  ## Usage
5
13
  How to use my plugin.
@@ -0,0 +1,29 @@
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(**options)
24
+ @parent_element ||= ::Vident::Phlex::RootComponent.new(**parent_element_attributes(options))
25
+ end
26
+ alias_method :root, :parent_element
27
+ end
28
+ end
29
+ end
@@ -2,15 +2,10 @@
2
2
 
3
3
  module Vident
4
4
  module Phlex
5
- class HTML < ::Phlex::HTML
5
+ class HTML < Core
6
6
  include ::Vident::Component
7
7
 
8
8
  class << self
9
- def inherited(subclass)
10
- subclass.component_source_file_path = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
11
- super
12
- end
13
-
14
9
  # Phlex uses a DSL to define the document, and those methods could easily clash with our attribute
15
10
  # accessors. Therefore in Phlex components we do not create attribute accessors, and instead use instance
16
11
  # variables directly.
@@ -18,22 +13,7 @@ module Vident
18
13
  options[:delegates] = false
19
14
  super
20
15
  end
21
-
22
- attr_accessor :component_source_file_path
23
-
24
- # Caching support
25
- def current_component_modified_time
26
- path = component_source_file_path
27
- raise StandardError, "No component source file exists #{path}" unless path && ::File.exist?(path)
28
- ::File.mtime(path).to_i.to_s
29
- end
30
- end
31
-
32
- # Helper to create the main element
33
- def parent_element(**options)
34
- @parent_element ||= RootComponent.new(**parent_element_attributes(options))
35
16
  end
36
- alias_method :root, :parent_element
37
17
  end
38
18
  end
39
19
  end
@@ -23,7 +23,7 @@ module Vident
23
23
  parsed = parse_targets(Array.wrap(targets))
24
24
  options[:data] ||= {}
25
25
  options[:data].merge!(build_target_data_attributes(parsed))
26
- generate_tag(tag_name, **options, &block)
26
+ generate_tag(tag_name, nil, **options, &block)
27
27
  end
28
28
 
29
29
  # Build a tag with the attributes determined by this components properties and stimulus
@@ -33,18 +33,22 @@ module Vident
33
33
  tag_type = @element_tag.presence&.to_sym || :div
34
34
  raise ArgumentError, "Unsupported HTML tag name #{tag_type}" unless VALID_TAGS.include?(tag_type)
35
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
36
37
  data_attrs = tag_data_attributes
37
38
  data_attrs = options[:data].present? ? data_attrs.merge(options[:data]) : data_attrs
38
39
  options = options.merge(id: @id) if @id
39
40
  options.except!(:data)
40
41
  options.merge!(data_attrs.transform_keys { |k| "data-#{k}" })
41
- generate_tag(tag_type, **options, &block)
42
+ generate_tag(tag_type, block_content, **options)
42
43
  end
43
44
 
44
45
  private
45
46
 
46
- def generate_tag(tag_type, **options, &block)
47
- send((tag_type == :template) ? :template_tag : tag_type, **options, &block)
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 { unsafe_raw content } if !block && content
51
+ send(method_name, **options, &block)
48
52
  end
49
53
  end
50
54
  end
@@ -1,5 +1,5 @@
1
1
  module Vident
2
2
  module Phlex
3
- VERSION = "0.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vident-phlex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-11 00:00:00.000000000 Z
11
+ date: 2024-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '7'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,27 @@ dependencies:
29
29
  version: '7'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
32
+ version: '8.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '7'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '8.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '7'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '8.0'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: vident
35
55
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +121,7 @@ files:
101
121
  - Rakefile
102
122
  - lib/tasks/vident/phlex_tasks.rake
103
123
  - lib/vident/phlex.rb
124
+ - lib/vident/phlex/core.rb
104
125
  - lib/vident/phlex/engine.rb
105
126
  - lib/vident/phlex/html.rb
106
127
  - lib/vident/phlex/root_component.rb
@@ -127,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
148
  - !ruby/object:Gem::Version
128
149
  version: '0'
129
150
  requirements: []
130
- rubygems_version: 3.4.10
151
+ rubygems_version: 3.5.3
131
152
  signing_key:
132
153
  specification_version: 4
133
154
  summary: Vident with Phlex