vident-phlex 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/lib/tasks/vident/phlex_tasks.rake +4 -0
- data/lib/vident/phlex/engine.rb +20 -0
- data/lib/vident/phlex/html.rb +25 -0
- data/lib/vident/phlex/root_component.rb +51 -0
- data/lib/vident/phlex/version.rb +5 -0
- data/lib/vident/phlex.rb +7 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b3f57652bc326a7ed139dfa36ac6753eeb925a76c895d4a08f05a22e463a846
|
4
|
+
data.tar.gz: 9f221a164fe0ef827595c73aa51339a6b2ca556d6127bedcbefd7e9f2ee6ce6d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d19da664b01409b656e45ae400a1ca7622c8c3653db62347888d887ffc0d014723a7175e8d40a9363c2009f165512713abc3bb2cec94ad5dab3026d7c2fed7c
|
7
|
+
data.tar.gz: 0aee2eaaa771af432cc1330715c52591be9269e3b9a96339c17c7ad62c09333e7b501c77de40d84286ee1ea3c004b86cd5a5b0c764577674e21807f1def1cc01
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Vident::Phlex
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "vident-phlex"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install vident-phlex
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vident
|
4
|
+
module Phlex
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
lib_path = File.expand_path("../../../../lib/", __FILE__)
|
7
|
+
config.autoload_paths << lib_path
|
8
|
+
config.eager_load_paths << lib_path
|
9
|
+
|
10
|
+
config.before_initialize do
|
11
|
+
Rails.autoloaders.each do |autoloader|
|
12
|
+
autoloader.inflector.inflect(
|
13
|
+
"html" => "HTML",
|
14
|
+
"version" => "VERSION"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vident
|
4
|
+
module Phlex
|
5
|
+
class HTML < ::Phlex::HTML
|
6
|
+
include ::Vident::Component
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Phlex uses a DSL to define the document, and those methods could easily clash with our attribute
|
10
|
+
# accessors. Therefore in Phlex components we do not create attribute accessors, and instead use instance
|
11
|
+
# variables directly.
|
12
|
+
def attribute(name, **options)
|
13
|
+
options[:delegates] = false
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Helper to create the main element
|
19
|
+
def parent_element(**options)
|
20
|
+
@parent_element ||= RootComponent.new(**parent_element_attributes(options))
|
21
|
+
end
|
22
|
+
alias_method :root, :parent_element
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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, **options, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Build a tag with the attributes determined by this components properties and stimulus
|
30
|
+
# data attributes.
|
31
|
+
def 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
|
+
data_attrs = tag_data_attributes
|
37
|
+
data_attrs = options[:data].present? ? data_attrs.merge(options[:data]) : data_attrs
|
38
|
+
options = options.merge(id: @id) if @id
|
39
|
+
options.except!(:data)
|
40
|
+
options.merge!(data_attrs.transform_keys { |k| "data-#{k}" })
|
41
|
+
generate_tag(tag_type, **options, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def generate_tag(tag_type, **options, &block)
|
47
|
+
send((tag_type == :template) ? :template_tag : tag_type, **options, &block)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/vident/phlex.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vident-phlex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Ierodiaconou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: vident
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.8.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.8.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: phlex
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.5.0
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.5.0
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: phlex-rails
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.8.1
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.1
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1'
|
93
|
+
description: Vident with Phlex
|
94
|
+
email:
|
95
|
+
- stevegeek@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- lib/tasks/vident/phlex_tasks.rake
|
103
|
+
- lib/vident/phlex.rb
|
104
|
+
- lib/vident/phlex/engine.rb
|
105
|
+
- lib/vident/phlex/html.rb
|
106
|
+
- lib/vident/phlex/root_component.rb
|
107
|
+
- lib/vident/phlex/version.rb
|
108
|
+
homepage: https://github.com/stevegeek/vident-phlex
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/stevegeek/vident-phlex
|
113
|
+
source_code_uri: https://github.com/stevegeek/vident-phlex
|
114
|
+
changelog_uri: https://github.com/stevegeek/vident-phlex/blob/main/CHANGELOG.md
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.4.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Vident with Phlex
|
134
|
+
test_files: []
|