phlex-rails 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile +2 -1
- data/config.ru +9 -0
- data/lib/generators/phlex/controller/templates/view.rb.erb +0 -2
- data/lib/generators/phlex/layout/templates/layout.rb.erb +0 -1
- data/lib/generators/phlex/page/templates/page.rb.erb +0 -2
- data/lib/install/phlex.rb +0 -12
- data/lib/phlex/rails/form.rb +3 -3
- data/lib/phlex/rails/helpers.rb +31 -22
- data/lib/phlex/rails/html/append_method_added_warning.rb +17 -0
- data/lib/phlex/rails/html/class_methods.rb +13 -0
- data/lib/phlex/rails/html/overrides.rb +112 -0
- data/lib/phlex/rails/layout.rb +1 -0
- data/lib/phlex/rails/version.rb +1 -1
- data/lib/phlex/rails.rb +5 -1
- metadata +9 -40
- data/config/sus.rb +0 -5
- data/fixtures/dummy/app/assets/config/manifest.js +0 -0
- data/fixtures/dummy/app/components/comment_component.html.erb +0 -14
- data/fixtures/dummy/app/components/comment_component.rb +0 -8
- data/fixtures/dummy/app/components/reaction_component.html.erb +0 -3
- data/fixtures/dummy/app/components/reaction_component.rb +0 -7
- data/fixtures/dummy/app/controllers/articles_controller.rb +0 -4
- data/fixtures/dummy/app/controllers/comments_controller.rb +0 -4
- data/fixtures/dummy/app/views/application_view.rb +0 -7
- data/fixtures/dummy/app/views/articles/blog.html.erb +0 -14
- data/fixtures/dummy/app/views/articles/form.rb +0 -15
- data/fixtures/dummy/app/views/articles/index.html.erb +0 -14
- data/fixtures/dummy/app/views/articles/new.html.erb +0 -1
- data/fixtures/dummy/app/views/blog.rb +0 -27
- data/fixtures/dummy/app/views/card.rb +0 -15
- data/fixtures/dummy/app/views/comments/comment.rb +0 -25
- data/fixtures/dummy/app/views/comments/index.html.erb +0 -3
- data/fixtures/dummy/app/views/comments/reaction.rb +0 -17
- data/fixtures/dummy/app/views/comments/show.html.erb +0 -3
- data/fixtures/dummy/app/views/heading.rb +0 -9
- data/fixtures/dummy/config/database.yml +0 -3
- data/fixtures/dummy/config/routes.rb +0 -5
- data/fixtures/dummy/config/storage.yml +0 -3
- data/fixtures/dummy/db/schema.rb +0 -6
- data/fixtures/dummy/log/.gitignore +0 -1
- data/fixtures/dummy/public/favicon.ico +0 -0
- data/fixtures/rails_helper.rb +0 -9
- data/fixtures/view_helper.rb +0 -16
- data/lib/generators/phlex/collection/USAGE +0 -8
- data/lib/generators/phlex/collection/collection_generator.rb +0 -13
- data/lib/generators/phlex/collection/templates/collection.rb.erb +0 -16
- data/lib/generators/phlex/table/USAGE +0 -8
- data/lib/generators/phlex/table/table_generator.rb +0 -14
- data/lib/generators/phlex/table/templates/table.rb.erb +0 -11
- data/lib/phlex/rails/renderable.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 407ff3d219b8d6ec6bbe429422b18125dde3f9cfb73ec756bad2ab4f08953083
|
4
|
+
data.tar.gz: b0e4f337a9626bf67a5e4dfd4172648cf69c264008fde9a5e3c1b456b98d7e72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e29f9f569bc0259d037d7b8a6e3ee8fb267d8210b2faf1e0a952d25275419e27c9621b615aad8be7d3f5531872848a63e46fdeb1a3ec8506e9babc5b27b1af
|
7
|
+
data.tar.gz: 4440057f8e253c7f0f78dbd41e4f92c6a8e4faeeac4cb339fbc26d09bc7bafa72302d2f2bc066b8879579b4dc3c053ba07f301622a8801d9a635a216f0ef2ac3
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,8 +6,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
gem "phlex", github: "joeldrapper/phlex", branch: "main"
|
9
|
-
gem "
|
9
|
+
gem "rspec-rails"
|
10
10
|
gem "combustion"
|
11
11
|
gem "rubocop"
|
12
12
|
gem "solargraph"
|
13
|
+
gem "view_component"
|
13
14
|
gem "appraisal", github: "excid3/appraisal", branch: "fix-bundle-env"
|
data/config.ru
ADDED
@@ -1,8 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module Views
|
3
3
|
class <%= class_name %>::<%= @action.camelize %> < Phlex::HTML
|
4
|
-
include ApplicationView
|
5
|
-
|
6
4
|
def template
|
7
5
|
<%= "# " unless @has_layout %>render Layout.new(title: "<%= class_name.gsub("::", " ").titlecase %> - <%= @action.titlecase %>") do
|
8
6
|
h1 { "<%= class_name %>#<%= @action %>" }
|
data/lib/install/phlex.rb
CHANGED
@@ -15,18 +15,6 @@ unless application_configuration_content.match?(pattern)
|
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
|
-
unless Rails.root.join("app/views/application_view.rb").exist?
|
19
|
-
create_file(Rails.root.join("app/views/application_view.rb"), <<~RUBY)
|
20
|
-
# frozen_string_literal: true
|
21
|
-
|
22
|
-
module Views
|
23
|
-
module ApplicationView
|
24
|
-
include Rails.application.routes.url_helpers
|
25
|
-
end
|
26
|
-
end
|
27
|
-
RUBY
|
28
|
-
end
|
29
|
-
|
30
18
|
tailwind_config_path = Rails.root.join("config/tailwind.config.js")
|
31
19
|
|
32
20
|
if tailwind_config_path.exist?
|
data/lib/phlex/rails/form.rb
CHANGED
@@ -29,7 +29,7 @@ module Phlex
|
|
29
29
|
input(
|
30
30
|
name: "authenticity_token",
|
31
31
|
type: "hidden",
|
32
|
-
value:
|
32
|
+
value: helpers.form_authenticity_token
|
33
33
|
)
|
34
34
|
end
|
35
35
|
|
@@ -42,11 +42,11 @@ module Phlex
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def url
|
45
|
-
|
45
|
+
helpers.url_for(@model)
|
46
46
|
end
|
47
47
|
|
48
48
|
def field_name(*field)
|
49
|
-
|
49
|
+
helpers.field_name(ActiveModel::Naming.param_key(@model.class), *field)
|
50
50
|
end
|
51
51
|
|
52
52
|
input_field :url_field, type: "url"
|
data/lib/phlex/rails/helpers.rb
CHANGED
@@ -4,8 +4,8 @@ module Phlex
|
|
4
4
|
module Rails
|
5
5
|
module Helpers
|
6
6
|
module CSPMetaTag
|
7
|
-
def csp_meta_tag(
|
8
|
-
if (output =
|
7
|
+
def csp_meta_tag(...)
|
8
|
+
if (output = helpers.csp_meta_tag(...))
|
9
9
|
@_target << output
|
10
10
|
end
|
11
11
|
end
|
@@ -13,7 +13,7 @@ module Phlex
|
|
13
13
|
|
14
14
|
module CSRFMetaTags
|
15
15
|
def csrf_meta_tags
|
16
|
-
if (output =
|
16
|
+
if (output = helpers.csrf_meta_tags)
|
17
17
|
@_target << output
|
18
18
|
end
|
19
19
|
end
|
@@ -21,7 +21,7 @@ module Phlex
|
|
21
21
|
|
22
22
|
module ActionCableMetaTag
|
23
23
|
def action_cable_meta_tag
|
24
|
-
if (output =
|
24
|
+
if (output = helpers.action_cable_meta_tag)
|
25
25
|
@_target << output
|
26
26
|
end
|
27
27
|
end
|
@@ -63,10 +63,11 @@ module Phlex
|
|
63
63
|
alias_method :week_field, :__output_method__
|
64
64
|
alias_method :weekday_select, :__output_method__
|
65
65
|
alias_method :button, :__output_method__
|
66
|
+
alias_method :rich_text_area, :__output_method__
|
66
67
|
end
|
67
68
|
|
68
69
|
def form_with(*args, **kwargs, &block)
|
69
|
-
@_target <<
|
70
|
+
@_target << helpers.form_with(*args, **kwargs) { |form|
|
70
71
|
capture do
|
71
72
|
yield(
|
72
73
|
BufferedFormWith.new(form, buffer: @_target)
|
@@ -77,64 +78,72 @@ module Phlex
|
|
77
78
|
end
|
78
79
|
|
79
80
|
module StylesheetLinkTag
|
80
|
-
def stylesheet_link_tag(
|
81
|
-
if (output =
|
81
|
+
def stylesheet_link_tag(...)
|
82
|
+
if (output = helpers.stylesheet_link_tag(...))
|
82
83
|
@_target << output
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
88
|
module FaviconLinkTag
|
88
|
-
def favicon_link_tag(
|
89
|
-
if (output =
|
89
|
+
def favicon_link_tag(...)
|
90
|
+
if (output = helpers.favicon_link_tag(...))
|
90
91
|
@_target << output
|
91
92
|
end
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
96
|
module ImageTag
|
96
|
-
def image_tag(
|
97
|
-
if (output =
|
97
|
+
def image_tag(...)
|
98
|
+
if (output = helpers.image_tag(...))
|
98
99
|
@_target << output
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
104
|
module AudioTag
|
104
|
-
def audio_tag(
|
105
|
-
if (output =
|
105
|
+
def audio_tag(...)
|
106
|
+
if (output = helpers.audio_tag(...))
|
106
107
|
@_target << output
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
111
112
|
module VideoTag
|
112
|
-
def video_tag(
|
113
|
-
if (output =
|
113
|
+
def video_tag(...)
|
114
|
+
if (output = helpers.video_tag(...))
|
114
115
|
@_target << output
|
115
116
|
end
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
119
120
|
module PreloadLinkTag
|
120
|
-
def preload_link_tag(
|
121
|
-
if (output =
|
121
|
+
def preload_link_tag(...)
|
122
|
+
if (output = helpers.preload_link_tag(...))
|
122
123
|
@_target << output
|
123
124
|
end
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
module JavaScriptIncludeTag
|
128
|
-
def javascript_include_tag(
|
129
|
-
if (output =
|
129
|
+
def javascript_include_tag(...)
|
130
|
+
if (output = helpers.javascript_include_tag(...))
|
130
131
|
@_target << output
|
131
132
|
end
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
136
|
module JavaScriptImportmapTags
|
136
|
-
def javascript_importmap_tags
|
137
|
-
if (output =
|
137
|
+
def javascript_importmap_tags(...)
|
138
|
+
if (output = helpers.javascript_importmap_tags(...))
|
139
|
+
@_target << output
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
module JavaScriptImportModuleTag
|
145
|
+
def javascript_import_module_tag(...)
|
146
|
+
if (output = helpers.javascript_import_module_tag(...))
|
138
147
|
@_target << output
|
139
148
|
end
|
140
149
|
end
|
@@ -142,7 +151,7 @@ module Phlex
|
|
142
151
|
|
143
152
|
module ContentFor
|
144
153
|
def content_for(slot, &block)
|
145
|
-
|
154
|
+
helpers.content_for(slot, capture(&block))
|
146
155
|
end
|
147
156
|
end
|
148
157
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module Rails
|
5
|
+
module HTML
|
6
|
+
module AppendMethodAddedWarning
|
7
|
+
def method_added(name)
|
8
|
+
if name == :append || name == :safe_append
|
9
|
+
raise Phlex::NameError, "You shouldn't redefine the #{name} method as it's required for safe HTML output."
|
10
|
+
end
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex
|
4
|
+
module Rails
|
5
|
+
module HTML
|
6
|
+
module Overrides
|
7
|
+
def helpers
|
8
|
+
if defined?(ViewComponent::Base) && @_view_context.is_a?(ViewComponent::Base)
|
9
|
+
@_view_context.helpers
|
10
|
+
else
|
11
|
+
@_view_context
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(renderable, *args, **kwargs, &block)
|
16
|
+
return super if renderable.is_a?(Phlex::HTML)
|
17
|
+
return super if renderable.is_a?(Class) && renderable < Phlex::HTML
|
18
|
+
|
19
|
+
@_target << @_view_context.render(renderable, *args, **kwargs, &block)
|
20
|
+
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_in(view_context, &block)
|
25
|
+
if block_given?
|
26
|
+
call(view_context: view_context) do |*args|
|
27
|
+
view_context.with_output_buffer(self) do
|
28
|
+
original_length = @_target.length
|
29
|
+
|
30
|
+
if args.length == 1 && Phlex::HTML === args[0]
|
31
|
+
output = yield(
|
32
|
+
args[0].unbuffered
|
33
|
+
)
|
34
|
+
else
|
35
|
+
output = yield(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
unchanged = (original_length == @_target.length)
|
39
|
+
|
40
|
+
if unchanged
|
41
|
+
if output.is_a?(ActiveSupport::SafeBuffer)
|
42
|
+
unsafe_raw(output)
|
43
|
+
else
|
44
|
+
text(output)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
nil
|
50
|
+
end.html_safe
|
51
|
+
else
|
52
|
+
call(view_context: view_context).html_safe
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def safe_append=(value)
|
57
|
+
return unless value
|
58
|
+
|
59
|
+
@_target << case value
|
60
|
+
when String then value
|
61
|
+
when Symbol then value.name
|
62
|
+
else value.to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def append=(value)
|
67
|
+
return unless value
|
68
|
+
|
69
|
+
if value.html_safe?
|
70
|
+
self.safe_append = value
|
71
|
+
else
|
72
|
+
@_target << case value
|
73
|
+
when String then ERB::Util.html_escape(value)
|
74
|
+
when Symbol then ERB::Util.html_escape(value.name)
|
75
|
+
else ERB::Util.html_escape(value.to_s)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def capture
|
81
|
+
super&.html_safe
|
82
|
+
end
|
83
|
+
|
84
|
+
# Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
|
85
|
+
def set_original_view_context(view_context)
|
86
|
+
end
|
87
|
+
|
88
|
+
private def yield_content(&block)
|
89
|
+
return unless block
|
90
|
+
|
91
|
+
case block.binding.receiver
|
92
|
+
when Phlex::HTML
|
93
|
+
super
|
94
|
+
else
|
95
|
+
@_view_context.with_output_buffer(self) { super }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private def yield_content_with_args(*args, &block)
|
100
|
+
return unless block
|
101
|
+
|
102
|
+
case block.binding.receiver
|
103
|
+
when Phlex::HTML
|
104
|
+
super
|
105
|
+
else
|
106
|
+
@_view_context.with_output_buffer(self) { super }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/phlex/rails/layout.rb
CHANGED
data/lib/phlex/rails/version.rb
CHANGED
data/lib/phlex/rails.rb
CHANGED
@@ -7,8 +7,12 @@ module Phlex::Rails
|
|
7
7
|
Loader = Zeitwerk::Loader.new.tap do |loader|
|
8
8
|
loader.push_dir("#{__dir__}/rails", namespace: Phlex::Rails)
|
9
9
|
loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
|
10
|
+
loader.inflector.inflect("html" => "HTML")
|
10
11
|
loader.setup
|
11
12
|
end
|
12
13
|
|
13
|
-
Phlex::HTML.prepend(Phlex::Rails::
|
14
|
+
Phlex::HTML.prepend(Phlex::Rails::HTML::Overrides)
|
15
|
+
|
16
|
+
Phlex::HTML.extend(Phlex::Rails::HTML::ClassMethods)
|
17
|
+
Phlex::HTML.extend(Phlex::Rails::HTML::AppendMethodAddedWarning)
|
14
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.3.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2'
|
@@ -80,37 +80,7 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- SECURITY.md
|
83
|
-
- config
|
84
|
-
- fixtures/dummy/app/assets/config/manifest.js
|
85
|
-
- fixtures/dummy/app/components/comment_component.html.erb
|
86
|
-
- fixtures/dummy/app/components/comment_component.rb
|
87
|
-
- fixtures/dummy/app/components/reaction_component.html.erb
|
88
|
-
- fixtures/dummy/app/components/reaction_component.rb
|
89
|
-
- fixtures/dummy/app/controllers/articles_controller.rb
|
90
|
-
- fixtures/dummy/app/controllers/comments_controller.rb
|
91
|
-
- fixtures/dummy/app/views/application_view.rb
|
92
|
-
- fixtures/dummy/app/views/articles/blog.html.erb
|
93
|
-
- fixtures/dummy/app/views/articles/form.rb
|
94
|
-
- fixtures/dummy/app/views/articles/index.html.erb
|
95
|
-
- fixtures/dummy/app/views/articles/new.html.erb
|
96
|
-
- fixtures/dummy/app/views/blog.rb
|
97
|
-
- fixtures/dummy/app/views/card.rb
|
98
|
-
- fixtures/dummy/app/views/comments/comment.rb
|
99
|
-
- fixtures/dummy/app/views/comments/index.html.erb
|
100
|
-
- fixtures/dummy/app/views/comments/reaction.rb
|
101
|
-
- fixtures/dummy/app/views/comments/show.html.erb
|
102
|
-
- fixtures/dummy/app/views/heading.rb
|
103
|
-
- fixtures/dummy/config/database.yml
|
104
|
-
- fixtures/dummy/config/routes.rb
|
105
|
-
- fixtures/dummy/config/storage.yml
|
106
|
-
- fixtures/dummy/db/schema.rb
|
107
|
-
- fixtures/dummy/log/.gitignore
|
108
|
-
- fixtures/dummy/public/favicon.ico
|
109
|
-
- fixtures/rails_helper.rb
|
110
|
-
- fixtures/view_helper.rb
|
111
|
-
- lib/generators/phlex/collection/USAGE
|
112
|
-
- lib/generators/phlex/collection/collection_generator.rb
|
113
|
-
- lib/generators/phlex/collection/templates/collection.rb.erb
|
83
|
+
- config.ru
|
114
84
|
- lib/generators/phlex/controller/USAGE
|
115
85
|
- lib/generators/phlex/controller/controller_generator.rb
|
116
86
|
- lib/generators/phlex/controller/templates/controller.rb.erb
|
@@ -121,9 +91,6 @@ files:
|
|
121
91
|
- lib/generators/phlex/page/USAGE
|
122
92
|
- lib/generators/phlex/page/page_generator.rb
|
123
93
|
- lib/generators/phlex/page/templates/page.rb.erb
|
124
|
-
- lib/generators/phlex/table/USAGE
|
125
|
-
- lib/generators/phlex/table/table_generator.rb
|
126
|
-
- lib/generators/phlex/table/templates/table.rb.erb
|
127
94
|
- lib/generators/phlex/view/USAGE
|
128
95
|
- lib/generators/phlex/view/templates/view.rb.erb
|
129
96
|
- lib/generators/phlex/view/view_generator.rb
|
@@ -137,8 +104,10 @@ files:
|
|
137
104
|
- lib/phlex/rails/engine.rb
|
138
105
|
- lib/phlex/rails/form.rb
|
139
106
|
- lib/phlex/rails/helpers.rb
|
107
|
+
- lib/phlex/rails/html/append_method_added_warning.rb
|
108
|
+
- lib/phlex/rails/html/class_methods.rb
|
109
|
+
- lib/phlex/rails/html/overrides.rb
|
140
110
|
- lib/phlex/rails/layout.rb
|
141
|
-
- lib/phlex/rails/renderable.rb
|
142
111
|
- lib/phlex/rails/version.rb
|
143
112
|
- lib/phlex/testing/rails/view_helper.rb
|
144
113
|
- lib/tasks/phlex_tasks.rake
|
@@ -167,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
136
|
- !ruby/object:Gem::Version
|
168
137
|
version: '0'
|
169
138
|
requirements: []
|
170
|
-
rubygems_version: 3.3
|
139
|
+
rubygems_version: 3.4.3
|
171
140
|
signing_key:
|
172
141
|
specification_version: 4
|
173
142
|
summary: A Phlex adapter for Rails
|
data/config/sus.rb
DELETED
File without changes
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<div>
|
2
|
-
<span>
|
3
|
-
<%= @name %>
|
4
|
-
</span>
|
5
|
-
<span>
|
6
|
-
<%= @body %>
|
7
|
-
</span>
|
8
|
-
|
9
|
-
<%= content %>
|
10
|
-
|
11
|
-
<%= render Views::Comments::Reaction.new(emoji: 'hamburger') do |reaction| %>
|
12
|
-
<p>Emoji reaction for a comment from <%= @name %> with body <%= @body %></p>
|
13
|
-
<% end %>
|
14
|
-
</div>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<%= render Views::Blog.new do |v| %>
|
2
|
-
|
3
|
-
hidden
|
4
|
-
|
5
|
-
<% v.with_post do %><%= link_to "First Post", "/posts/1" %><% end %>
|
6
|
-
|
7
|
-
content
|
8
|
-
|
9
|
-
<% v.with_header do %><%= link_to "My blog", "/" %><% end %>
|
10
|
-
|
11
|
-
here
|
12
|
-
|
13
|
-
<% v.with_post do %><%= link_to "Last Post", "/posts/2" %><% end %>
|
14
|
-
<% end %>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<p>Before</p>
|
2
|
-
|
3
|
-
<%= render(Views::Heading.new) { "Hello World!" } %>
|
4
|
-
|
5
|
-
<%= render Views::Card.new do |a| %>
|
6
|
-
<p>Start Card A</p>
|
7
|
-
<%= a.title "Hello from A" %>
|
8
|
-
<%= render Views::Card.new do |b| %>
|
9
|
-
<p>Start Card B</p>
|
10
|
-
<%= b.title "Hello from B" %>
|
11
|
-
<p>End Card B</p>
|
12
|
-
<% end %>
|
13
|
-
<p>End Card A</p>
|
14
|
-
<% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render Views::Articles::Form.new %>
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Views
|
4
|
-
class Blog < ApplicationView
|
5
|
-
def initialize
|
6
|
-
@posts = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def template(&block)
|
10
|
-
capture(&block)
|
11
|
-
|
12
|
-
h3(class: "font-bold") { @header }
|
13
|
-
|
14
|
-
@posts.each do |post|
|
15
|
-
article(class: "drop-shadow p-5 rounded") { post }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def with_header(&block)
|
20
|
-
@header = capture(&block)
|
21
|
-
end
|
22
|
-
|
23
|
-
def with_post(&block)
|
24
|
-
@posts << capture(&block)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Views
|
4
|
-
module Comments
|
5
|
-
class Comment < ApplicationView
|
6
|
-
def initialize(name:, body:)
|
7
|
-
@name = name
|
8
|
-
@body = body
|
9
|
-
end
|
10
|
-
|
11
|
-
def template(&block)
|
12
|
-
div {
|
13
|
-
span { @name }
|
14
|
-
span { @body }
|
15
|
-
|
16
|
-
yield_content(&block)
|
17
|
-
|
18
|
-
render(::ReactionComponent.new(emoji: "hamburger")) do
|
19
|
-
p { "Emoji reaction for a comment from #{@name} with body #{@body}" }
|
20
|
-
end
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/fixtures/dummy/db/schema.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*.log
|
File without changes
|
data/fixtures/rails_helper.rb
DELETED
data/fixtures/view_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ViewHelper
|
4
|
-
def self.extended(parent)
|
5
|
-
parent.class_exec do
|
6
|
-
let(:output) { example.call }
|
7
|
-
let(:example) { view.new }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def view(&block)
|
12
|
-
let :view do
|
13
|
-
Class.new(Phlex::HTML, &block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Generators
|
5
|
-
class CollectionGenerator < ::Rails::Generators::NamedBase
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
7
|
-
|
8
|
-
def create_view
|
9
|
-
template "collection.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
module Views
|
3
|
-
class <%= class_name %> < Phlex::HTML
|
4
|
-
include ApplicationView
|
5
|
-
include Phlex::Collection
|
6
|
-
|
7
|
-
def collection_template(&)
|
8
|
-
ul(&)
|
9
|
-
end
|
10
|
-
|
11
|
-
def item_template
|
12
|
-
li { @item }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
<% end %>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Generators
|
5
|
-
class TableGenerator < ::Rails::Generators::NamedBase
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
7
|
-
class_option :properties, type: :array, default: []
|
8
|
-
|
9
|
-
def create_view
|
10
|
-
template "table.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
module Views
|
3
|
-
class <%= class_name %> < Phlex::HTML
|
4
|
-
include ApplicationView
|
5
|
-
include Phlex::Table
|
6
|
-
|
7
|
-
<% options["properties"].each do |property| %>
|
8
|
-
property "<%= property.humanize %>", &:<%= property.underscore %><% end %>
|
9
|
-
end
|
10
|
-
end
|
11
|
-
<% end %>
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Rails
|
5
|
-
module Renderable
|
6
|
-
def helpers
|
7
|
-
@_view_context
|
8
|
-
end
|
9
|
-
|
10
|
-
def render(renderable, *args, **kwargs, &block)
|
11
|
-
return super if renderable.is_a?(Phlex::HTML)
|
12
|
-
return super if renderable.is_a?(Class) && renderable < Phlex::HTML
|
13
|
-
|
14
|
-
@_target << @_view_context.render(renderable, *args, **kwargs, &block)
|
15
|
-
|
16
|
-
nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def render_in(view_context, &block)
|
20
|
-
if block_given?
|
21
|
-
call(view_context: view_context) do |*args|
|
22
|
-
view_context.with_output_buffer(self) do
|
23
|
-
original_length = @_target.length
|
24
|
-
output = yield(*args)
|
25
|
-
unchanged = (original_length == @_target.length)
|
26
|
-
|
27
|
-
if unchanged
|
28
|
-
if output.is_a?(ActiveSupport::SafeBuffer)
|
29
|
-
unsafe_raw(output)
|
30
|
-
else
|
31
|
-
text(output)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end.html_safe
|
36
|
-
else
|
37
|
-
call(view_context: view_context).html_safe
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def safe_append=(value)
|
42
|
-
return unless value
|
43
|
-
|
44
|
-
@_target << case value
|
45
|
-
when String then value
|
46
|
-
when Symbol then value.name
|
47
|
-
else value.to_s
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def append=(value)
|
52
|
-
return unless value
|
53
|
-
|
54
|
-
if value.html_safe?
|
55
|
-
self.safe_append = value
|
56
|
-
else
|
57
|
-
@_target << case value
|
58
|
-
when String then ERB::Util.html_escape(value)
|
59
|
-
when Symbol then ERB::Util.html_escape(value.name)
|
60
|
-
else ERB::Util.html_escape(value.to_s)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def capture
|
66
|
-
super.html_safe
|
67
|
-
end
|
68
|
-
|
69
|
-
# Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
|
70
|
-
def set_original_view_context(view_context)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|