phlex 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of phlex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.editorconfig +8 -0
- data/.rubocop.yml +3 -7
- data/Gemfile +2 -1
- data/Procfile.dev +3 -0
- data/Rakefile +3 -5
- data/docs/build.rb +15 -10
- data/docs/components/code_span.rb +9 -0
- data/docs/components/example.rb +1 -1
- data/docs/components/heading.rb +1 -1
- data/docs/components/layout.rb +38 -16
- data/docs/components/markdown.rb +17 -3
- data/docs/components/nav/item.rb +33 -0
- data/docs/components/nav.rb +6 -0
- data/docs/components/tabs/tab.rb +3 -1
- data/docs/components/title.rb +1 -1
- data/docs/page_builder.rb +3 -0
- data/docs/pages/helpers.rb +97 -0
- data/docs/pages/index.rb +6 -17
- data/docs/pages/library/collections.rb +101 -0
- data/docs/pages/rails/getting_started.rb +53 -0
- data/docs/pages/rails/helpers.rb +53 -0
- data/docs/pages/rails/layouts.rb +61 -0
- data/docs/pages/rails/migrating.rb +37 -0
- data/docs/pages/rails/rendering_views.rb +35 -0
- data/docs/pages/templates.rb +51 -149
- data/docs/pages/views.rb +55 -94
- data/fixtures/dummy/app/components/comment_component.html.erb +14 -0
- data/fixtures/dummy/app/components/comment_component.rb +8 -0
- data/fixtures/dummy/app/components/reaction_component.html.erb +3 -0
- data/fixtures/dummy/app/components/reaction_component.rb +7 -0
- data/fixtures/dummy/app/controllers/comments_controller.rb +4 -0
- data/fixtures/dummy/app/views/articles/form.rb +2 -0
- data/fixtures/dummy/app/views/card.rb +3 -1
- data/fixtures/dummy/app/views/comments/comment.rb +25 -0
- data/fixtures/dummy/app/views/comments/index.html.erb +3 -0
- data/fixtures/dummy/app/views/comments/reaction.rb +17 -0
- data/fixtures/dummy/app/views/comments/show.html.erb +3 -0
- data/fixtures/test_helper.rb +3 -0
- data/lib/generators/phlex/collection/USAGE +8 -0
- data/lib/generators/phlex/collection/collection_generator.rb +13 -0
- data/lib/generators/phlex/collection/templates/collection.rb.erb +15 -0
- data/lib/generators/phlex/layout/USAGE +8 -0
- data/lib/generators/phlex/layout/layout_generator.rb +13 -0
- data/lib/generators/phlex/layout/templates/layout.rb.erb +30 -0
- data/lib/generators/phlex/page/USAGE +8 -0
- data/lib/generators/phlex/page/page_generator.rb +13 -0
- data/lib/generators/phlex/page/templates/page.rb.erb +11 -0
- data/lib/generators/phlex/table/USAGE +8 -0
- data/lib/generators/phlex/table/table_generator.rb +14 -0
- data/lib/generators/phlex/table/templates/table.rb.erb +9 -0
- data/lib/phlex/collection.rb +58 -0
- data/lib/phlex/engine.rb +0 -3
- data/lib/phlex/html.rb +7 -13
- data/lib/phlex/rails/helpers.rb +81 -0
- data/lib/phlex/rails/layout.rb +15 -0
- data/lib/phlex/table.rb +104 -0
- data/lib/phlex/version.rb +1 -1
- data/lib/phlex/view.rb +10 -4
- data/lib/phlex.rb +1 -0
- metadata +52 -3
- data/lib/phlex/rails/tag_helpers.rb +0 -29
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module Rails
|
5
|
+
module Helpers
|
6
|
+
module CSPMetaTag
|
7
|
+
def csp_meta_tag(**options)
|
8
|
+
if (output = @_view_context.csp_meta_tag(**options))
|
9
|
+
@_target << output
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module CSRFMetaTags
|
15
|
+
def csrf_meta_tags
|
16
|
+
if (output = @_view_context.csrf_meta_tags)
|
17
|
+
@_target << output
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ActionCableMetaTag
|
23
|
+
def action_cable_meta_tag
|
24
|
+
if (output = @_view_context.action_cable_meta_tag)
|
25
|
+
@_target << output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module FormWith
|
31
|
+
def form_with(*args, **kwargs, &block)
|
32
|
+
raw @_view_context.form_with(*args, **kwargs) { |form|
|
33
|
+
capture do
|
34
|
+
yield(
|
35
|
+
Phlex::Buffered.new(form, buffer: @_target)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module StylesheetLinkTag
|
43
|
+
def stylesheet_link_tag(*sources)
|
44
|
+
if (output = @_view_context.stylesheet_link_tag(*sources))
|
45
|
+
@_target << output
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module FaviconLinkTag
|
51
|
+
def favicon_link_tag(*args)
|
52
|
+
if (output = @_view_context.favicon_link_tag(*args))
|
53
|
+
@_target << output
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module PreloadLinkTag
|
59
|
+
def preload_link_tag(*args)
|
60
|
+
if (output = @_view_context.preload_link_tag(*args))
|
61
|
+
@_target << output
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module JavaScriptIncludeTag
|
67
|
+
def javascript_include_tag(*sources)
|
68
|
+
if (output = @_view_context.javascript_include_tag(*sources))
|
69
|
+
@_target << output
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module ContentFor
|
75
|
+
def content_for(slot, &block)
|
76
|
+
@_view_context.content_for(slot, capture(&block))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module Rails
|
5
|
+
module Layout
|
6
|
+
include Helpers::CSPMetaTag
|
7
|
+
include Helpers::CSRFMetaTags
|
8
|
+
include Helpers::FaviconLinkTag
|
9
|
+
include Helpers::PreloadLinkTag
|
10
|
+
include Helpers::StylesheetLinkTag
|
11
|
+
include Helpers::ActionCableMetaTag
|
12
|
+
include Helpers::JavaScriptIncludeTag
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/phlex/table.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module Table
|
5
|
+
include Collection
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_accessor :header
|
9
|
+
|
10
|
+
def property(header = nil, **attributes, &body)
|
11
|
+
if header.is_a?(String)
|
12
|
+
header_text = header
|
13
|
+
header = -> { head_header(scope: "col") { header_text } }
|
14
|
+
end
|
15
|
+
|
16
|
+
properties << {
|
17
|
+
header: header,
|
18
|
+
body: body,
|
19
|
+
attributes: attributes,
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def properties
|
24
|
+
@properties ||= []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.included(child)
|
29
|
+
child.extend ClassMethods
|
30
|
+
|
31
|
+
child.alias_method :head, :thead
|
32
|
+
child.alias_method :body, :tbody
|
33
|
+
child.alias_method :foot, :tfoot
|
34
|
+
|
35
|
+
child.alias_method :row, :tr
|
36
|
+
|
37
|
+
child.alias_method :header, :th
|
38
|
+
child.alias_method :cell, :td
|
39
|
+
|
40
|
+
child.alias_method :head_row, :row
|
41
|
+
child.alias_method :body_row, :row
|
42
|
+
child.alias_method :foot_row, :row
|
43
|
+
|
44
|
+
child.alias_method :head_header, :header
|
45
|
+
child.alias_method :foot_header, :header
|
46
|
+
|
47
|
+
child.alias_method :head_cell, :cell
|
48
|
+
child.alias_method :body_cell, :cell
|
49
|
+
child.alias_method :foot_cell, :cell
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def properties
|
55
|
+
self.class.properties
|
56
|
+
end
|
57
|
+
|
58
|
+
def collection_template(&block)
|
59
|
+
table do
|
60
|
+
head_template
|
61
|
+
body_template(&block)
|
62
|
+
foot_template
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def item_template
|
67
|
+
row_template
|
68
|
+
end
|
69
|
+
|
70
|
+
def head_template
|
71
|
+
if self.class.properties.any? { |p| p[:header] }
|
72
|
+
head do
|
73
|
+
head_row do
|
74
|
+
self.class.properties.each do |property|
|
75
|
+
case property[:header]
|
76
|
+
when Proc
|
77
|
+
instance_exec(&property[:header])
|
78
|
+
when Symbol
|
79
|
+
send(property[:header])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def body_template
|
88
|
+
body { yield_items }
|
89
|
+
end
|
90
|
+
|
91
|
+
def foot_template
|
92
|
+
end
|
93
|
+
|
94
|
+
def row_template
|
95
|
+
body_row do
|
96
|
+
self.class.properties.each do |property|
|
97
|
+
body_cell(**property[:attributes]) do
|
98
|
+
instance_exec(@item, &property[:body])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/phlex/version.rb
CHANGED
data/lib/phlex/view.rb
CHANGED
@@ -97,8 +97,8 @@ module Phlex
|
|
97
97
|
nil
|
98
98
|
end
|
99
99
|
|
100
|
-
def raw(content)
|
101
|
-
@_target << content
|
100
|
+
def raw(content = nil, &block)
|
101
|
+
@_target << (content || instance_exec(&block))
|
102
102
|
nil
|
103
103
|
end
|
104
104
|
|
@@ -144,7 +144,13 @@ module Phlex
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def classes(*tokens, **conditional_tokens)
|
147
|
-
|
147
|
+
tokens = self.tokens(*tokens, **conditional_tokens)
|
148
|
+
|
149
|
+
if tokens.present?
|
150
|
+
{ class: tokens }
|
151
|
+
else
|
152
|
+
{}
|
153
|
+
end
|
148
154
|
end
|
149
155
|
|
150
156
|
def tokens(*tokens, **conditional_tokens)
|
@@ -159,7 +165,7 @@ module Phlex
|
|
159
165
|
case token
|
160
166
|
when Symbol then tokens << token.name
|
161
167
|
when String then tokens << token
|
162
|
-
when Array then tokens.concat(
|
168
|
+
when Array then tokens.concat(token)
|
163
169
|
else raise ArgumentError,
|
164
170
|
"Conditional classes must be Symbols, Strings, or Arrays of Symbols or Strings."
|
165
171
|
end
|
data/lib/phlex.rb
CHANGED
@@ -6,6 +6,7 @@ require "syntax_tree"
|
|
6
6
|
|
7
7
|
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
|
8
8
|
loader.ignore("#{__dir__}/generators")
|
9
|
+
loader.ignore("#{__dir__}/install")
|
9
10
|
loader.inflector.inflect("html" => "HTML")
|
10
11
|
loader.inflector.inflect("vcall" => "VCall")
|
11
12
|
loader.inflector.inflect("fcall" => "FCall")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: syntax_tree
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: view_component
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
41
55
|
description: A high-performance view framework optimised for developer happiness.
|
42
56
|
email:
|
43
57
|
- joel@drapper.me
|
@@ -52,6 +66,7 @@ files:
|
|
52
66
|
- CONTRIBUTING.md
|
53
67
|
- Gemfile
|
54
68
|
- LICENSE.txt
|
69
|
+
- Procfile.dev
|
55
70
|
- README.md
|
56
71
|
- Rakefile
|
57
72
|
- SECURITY.md
|
@@ -62,26 +77,45 @@ files:
|
|
62
77
|
- docs/build.rb
|
63
78
|
- docs/components/callout.rb
|
64
79
|
- docs/components/code_block.rb
|
80
|
+
- docs/components/code_span.rb
|
65
81
|
- docs/components/example.rb
|
66
82
|
- docs/components/heading.rb
|
67
83
|
- docs/components/layout.rb
|
68
84
|
- docs/components/markdown.rb
|
85
|
+
- docs/components/nav.rb
|
86
|
+
- docs/components/nav/item.rb
|
69
87
|
- docs/components/tabs.rb
|
70
88
|
- docs/components/tabs/tab.rb
|
71
89
|
- docs/components/title.rb
|
72
90
|
- docs/page_builder.rb
|
73
91
|
- docs/pages/application_page.rb
|
92
|
+
- docs/pages/helpers.rb
|
74
93
|
- docs/pages/index.rb
|
94
|
+
- docs/pages/library/collections.rb
|
95
|
+
- docs/pages/rails/getting_started.rb
|
96
|
+
- docs/pages/rails/helpers.rb
|
97
|
+
- docs/pages/rails/layouts.rb
|
98
|
+
- docs/pages/rails/migrating.rb
|
99
|
+
- docs/pages/rails/rendering_views.rb
|
75
100
|
- docs/pages/rails_integration.rb
|
76
101
|
- docs/pages/templates.rb
|
77
102
|
- docs/pages/views.rb
|
78
103
|
- fixtures/compilation/vcall.rb
|
79
104
|
- fixtures/dummy/app/assets/config/manifest.js
|
105
|
+
- fixtures/dummy/app/components/comment_component.html.erb
|
106
|
+
- fixtures/dummy/app/components/comment_component.rb
|
107
|
+
- fixtures/dummy/app/components/reaction_component.html.erb
|
108
|
+
- fixtures/dummy/app/components/reaction_component.rb
|
80
109
|
- fixtures/dummy/app/controllers/articles_controller.rb
|
110
|
+
- fixtures/dummy/app/controllers/comments_controller.rb
|
81
111
|
- fixtures/dummy/app/views/articles/form.rb
|
82
112
|
- fixtures/dummy/app/views/articles/index.html.erb
|
83
113
|
- fixtures/dummy/app/views/articles/new.html.erb
|
84
114
|
- fixtures/dummy/app/views/card.rb
|
115
|
+
- fixtures/dummy/app/views/comments/comment.rb
|
116
|
+
- fixtures/dummy/app/views/comments/index.html.erb
|
117
|
+
- fixtures/dummy/app/views/comments/reaction.rb
|
118
|
+
- fixtures/dummy/app/views/comments/show.html.erb
|
85
119
|
- fixtures/dummy/app/views/heading.rb
|
86
120
|
- fixtures/dummy/config/database.yml
|
87
121
|
- fixtures/dummy/config/routes.rb
|
@@ -93,6 +127,18 @@ files:
|
|
93
127
|
- fixtures/page.rb
|
94
128
|
- fixtures/test_helper.rb
|
95
129
|
- fixtures/view_helper.rb
|
130
|
+
- lib/generators/phlex/collection/USAGE
|
131
|
+
- lib/generators/phlex/collection/collection_generator.rb
|
132
|
+
- lib/generators/phlex/collection/templates/collection.rb.erb
|
133
|
+
- lib/generators/phlex/layout/USAGE
|
134
|
+
- lib/generators/phlex/layout/layout_generator.rb
|
135
|
+
- lib/generators/phlex/layout/templates/layout.rb.erb
|
136
|
+
- lib/generators/phlex/page/USAGE
|
137
|
+
- lib/generators/phlex/page/page_generator.rb
|
138
|
+
- lib/generators/phlex/page/templates/page.rb.erb
|
139
|
+
- lib/generators/phlex/table/USAGE
|
140
|
+
- lib/generators/phlex/table/table_generator.rb
|
141
|
+
- lib/generators/phlex/table/templates/table.rb.erb
|
96
142
|
- lib/generators/phlex/view/USAGE
|
97
143
|
- lib/generators/phlex/view/templates/view.rb.erb
|
98
144
|
- lib/generators/phlex/view/view_generator.rb
|
@@ -101,6 +147,7 @@ files:
|
|
101
147
|
- lib/phlex.rb
|
102
148
|
- lib/phlex/block.rb
|
103
149
|
- lib/phlex/buffered.rb
|
150
|
+
- lib/phlex/collection.rb
|
104
151
|
- lib/phlex/compiler.rb
|
105
152
|
- lib/phlex/compiler/formatter.rb
|
106
153
|
- lib/phlex/compiler/generators/standard_element.rb
|
@@ -114,8 +161,10 @@ files:
|
|
114
161
|
- lib/phlex/configuration.rb
|
115
162
|
- lib/phlex/engine.rb
|
116
163
|
- lib/phlex/html.rb
|
117
|
-
- lib/phlex/rails/
|
164
|
+
- lib/phlex/rails/helpers.rb
|
165
|
+
- lib/phlex/rails/layout.rb
|
118
166
|
- lib/phlex/renderable.rb
|
167
|
+
- lib/phlex/table.rb
|
119
168
|
- lib/phlex/version.rb
|
120
169
|
- lib/phlex/view.rb
|
121
170
|
- lib/tasks/phlex_tasks.rake
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Rails
|
5
|
-
module TagHelpers
|
6
|
-
def form_with(*args, **kwargs, &block)
|
7
|
-
raw @_view_context.form_with(*args, **kwargs) { |form|
|
8
|
-
capture do
|
9
|
-
yield(
|
10
|
-
Phlex::Buffered.new(form, buffer: @_target)
|
11
|
-
)
|
12
|
-
end
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
def csp_meta_tag
|
17
|
-
if (output = @_view_context.csp_meta_tag)
|
18
|
-
@_target << output
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def csrf_meta_tags
|
23
|
-
if (output = @_view_context.csrf_meta_tags)
|
24
|
-
@_target << output
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|