phlex 0.5.3 → 1.0.0.rc2

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.

Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -20
  3. data/config/sus.rb +0 -5
  4. data/lib/phlex/buffered.rb +2 -0
  5. data/lib/phlex/collection.rb +2 -0
  6. data/lib/phlex/elements.rb +1 -5
  7. data/lib/phlex/experimental.rb +10 -0
  8. data/lib/phlex/helpers.rb +23 -10
  9. data/lib/phlex/html.rb +72 -86
  10. data/lib/phlex/table.rb +1 -0
  11. data/lib/phlex/turbo/frame.rb +2 -0
  12. data/lib/phlex/turbo/stream.rb +2 -0
  13. data/lib/phlex/version.rb +1 -1
  14. data/lib/phlex.rb +2 -19
  15. metadata +6 -166
  16. data/Procfile.dev +0 -3
  17. data/Rakefile +0 -8
  18. data/config.ru +0 -9
  19. data/docs/assets/application.css +0 -32
  20. data/docs/assets/logo.png +0 -0
  21. data/docs/build.rb +0 -30
  22. data/docs/components/callout.rb +0 -9
  23. data/docs/components/code_block.rb +0 -26
  24. data/docs/components/code_span.rb +0 -9
  25. data/docs/components/example.rb +0 -32
  26. data/docs/components/heading.rb +0 -9
  27. data/docs/components/layout.rb +0 -91
  28. data/docs/components/markdown.rb +0 -25
  29. data/docs/components/nav/item.rb +0 -33
  30. data/docs/components/nav.rb +0 -6
  31. data/docs/components/tabs/tab.rb +0 -28
  32. data/docs/components/tabs.rb +0 -30
  33. data/docs/components/title.rb +0 -9
  34. data/docs/page_builder.rb +0 -39
  35. data/docs/pages/application_page.rb +0 -7
  36. data/docs/pages/helpers.rb +0 -97
  37. data/docs/pages/index.rb +0 -27
  38. data/docs/pages/library/collections.rb +0 -83
  39. data/docs/pages/rails/getting_started.rb +0 -57
  40. data/docs/pages/rails/helpers.rb +0 -55
  41. data/docs/pages/rails/layouts.rb +0 -61
  42. data/docs/pages/rails/migrating.rb +0 -37
  43. data/docs/pages/rails/rendering_views.rb +0 -35
  44. data/docs/pages/rails_integration.rb +0 -58
  45. data/docs/pages/templates.rb +0 -144
  46. data/docs/pages/testing/capybara.rb +0 -48
  47. data/docs/pages/testing/getting_started.rb +0 -44
  48. data/docs/pages/testing/nokogiri.rb +0 -83
  49. data/docs/pages/testing/rails.rb +0 -17
  50. data/docs/pages/translations.rb +0 -81
  51. data/docs/pages/views.rb +0 -184
  52. data/fixtures/compiler_test_helpers.rb +0 -19
  53. data/fixtures/content.rb +0 -60
  54. data/fixtures/dummy/app/assets/config/manifest.js +0 -0
  55. data/fixtures/dummy/app/components/comment_component.html.erb +0 -14
  56. data/fixtures/dummy/app/components/comment_component.rb +0 -8
  57. data/fixtures/dummy/app/components/reaction_component.html.erb +0 -3
  58. data/fixtures/dummy/app/components/reaction_component.rb +0 -7
  59. data/fixtures/dummy/app/controllers/articles_controller.rb +0 -4
  60. data/fixtures/dummy/app/controllers/comments_controller.rb +0 -4
  61. data/fixtures/dummy/app/views/application_view.rb +0 -8
  62. data/fixtures/dummy/app/views/articles/form.rb +0 -15
  63. data/fixtures/dummy/app/views/articles/index.html.erb +0 -14
  64. data/fixtures/dummy/app/views/articles/new.html.erb +0 -1
  65. data/fixtures/dummy/app/views/card.rb +0 -15
  66. data/fixtures/dummy/app/views/comments/comment.rb +0 -25
  67. data/fixtures/dummy/app/views/comments/index.html.erb +0 -3
  68. data/fixtures/dummy/app/views/comments/reaction.rb +0 -17
  69. data/fixtures/dummy/app/views/comments/show.html.erb +0 -3
  70. data/fixtures/dummy/app/views/heading.rb +0 -9
  71. data/fixtures/dummy/config/database.yml +0 -3
  72. data/fixtures/dummy/config/routes.rb +0 -5
  73. data/fixtures/dummy/config/storage.yml +0 -3
  74. data/fixtures/dummy/db/schema.rb +0 -6
  75. data/fixtures/dummy/log/.gitignore +0 -1
  76. data/fixtures/dummy/public/favicon.ico +0 -0
  77. data/fixtures/rails_helper.rb +0 -11
  78. data/fixtures/standard_element.rb +0 -87
  79. data/fixtures/void_element.rb +0 -31
  80. data/lib/generators/phlex/collection/USAGE +0 -8
  81. data/lib/generators/phlex/collection/collection_generator.rb +0 -13
  82. data/lib/generators/phlex/collection/templates/collection.rb.erb +0 -16
  83. data/lib/generators/phlex/controller/USAGE +0 -10
  84. data/lib/generators/phlex/controller/controller_generator.rb +0 -54
  85. data/lib/generators/phlex/controller/templates/controller.rb.erb +0 -10
  86. data/lib/generators/phlex/controller/templates/view.rb.erb +0 -14
  87. data/lib/generators/phlex/layout/USAGE +0 -8
  88. data/lib/generators/phlex/layout/layout_generator.rb +0 -13
  89. data/lib/generators/phlex/layout/templates/layout.rb.erb +0 -31
  90. data/lib/generators/phlex/page/USAGE +0 -8
  91. data/lib/generators/phlex/page/page_generator.rb +0 -13
  92. data/lib/generators/phlex/page/templates/page.rb.erb +0 -13
  93. data/lib/generators/phlex/table/USAGE +0 -8
  94. data/lib/generators/phlex/table/table_generator.rb +0 -14
  95. data/lib/generators/phlex/table/templates/table.rb.erb +0 -11
  96. data/lib/generators/phlex/view/USAGE +0 -8
  97. data/lib/generators/phlex/view/templates/view.rb.erb +0 -14
  98. data/lib/generators/phlex/view/view_generator.rb +0 -21
  99. data/lib/install/phlex.rb +0 -39
  100. data/lib/phlex/block.rb +0 -16
  101. data/lib/phlex/compiler/elements.rb +0 -49
  102. data/lib/phlex/compiler/formatter.rb +0 -91
  103. data/lib/phlex/compiler/generators/content.rb +0 -103
  104. data/lib/phlex/compiler/generators/element.rb +0 -61
  105. data/lib/phlex/compiler/nodes/base.rb +0 -19
  106. data/lib/phlex/compiler/nodes/call.rb +0 -9
  107. data/lib/phlex/compiler/nodes/command.rb +0 -13
  108. data/lib/phlex/compiler/nodes/fcall.rb +0 -18
  109. data/lib/phlex/compiler/nodes/method_add_block.rb +0 -33
  110. data/lib/phlex/compiler/nodes/vcall.rb +0 -9
  111. data/lib/phlex/compiler/optimizer.rb +0 -66
  112. data/lib/phlex/compiler/visitors/base.rb +0 -15
  113. data/lib/phlex/compiler/visitors/file.rb +0 -29
  114. data/lib/phlex/compiler/visitors/stable_scope.rb +0 -28
  115. data/lib/phlex/compiler/visitors/statements.rb +0 -36
  116. data/lib/phlex/compiler/visitors/view.rb +0 -19
  117. data/lib/phlex/compiler/visitors/view_method.rb +0 -59
  118. data/lib/phlex/compiler.rb +0 -70
  119. data/lib/phlex/html/callbacks.rb +0 -11
  120. data/lib/phlex/markdown.rb +0 -76
  121. data/lib/phlex/rails/engine.rb +0 -10
  122. data/lib/phlex/rails/form.rb +0 -67
  123. data/lib/phlex/rails/helpers.rb +0 -118
  124. data/lib/phlex/rails/layout.rb +0 -15
  125. data/lib/phlex/rails.rb +0 -11
  126. data/lib/phlex/renderable.rb +0 -47
  127. data/lib/phlex/testing/capybara.rb +0 -25
  128. data/lib/phlex/testing/nokogiri.rb +0 -24
  129. data/lib/phlex/testing/rails.rb +0 -19
  130. data/lib/phlex/translation.rb +0 -23
  131. data/lib/tasks/phlex_tasks.rake +0 -11
  132. data/package-lock.json +0 -1195
  133. data/package.json +0 -5
  134. data/tailwind.config.js +0 -7
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest"
4
-
5
- module Pages
6
- module Testing
7
- class Capybara < ApplicationPage
8
- def template
9
- render Layout.new(title: "Testing with Capybara") do
10
- render Markdown.new(<<~MD)
11
- # Testing with Capybara
12
-
13
- Require `phlex/testing/capybara` and include `Phlex::Testing::Capybara::ViewHelper` to use [Capybara](http://teamcapybara.github.io/capybara/) matchers.
14
-
15
- The `render` method will return a `Capybara::Node::Simple` and set the `page` attribute to the result.
16
- MD
17
-
18
- render Example.new do |e|
19
- e.tab "test.rb", <<~RUBY
20
- require "phlex/testing/capybara"
21
-
22
- class TestExample < Minitest::Test
23
- include Phlex::Testing::Capybara::ViewHelper
24
-
25
- def test_example
26
- render Example.new("Joel")
27
- assert_select "h1", text: "Hello Joel"
28
- end
29
- end
30
- RUBY
31
-
32
- e.tab "hello.rb", <<~RUBY
33
- class Hello < Phlex::HTML
34
- def initialize(name)
35
- @name = name
36
- end
37
-
38
- def template
39
- h1 { "Hello \#{@name}" }
40
- end
41
- end
42
- RUBY
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pages
4
- module Testing
5
- class GettingStarted < ApplicationPage
6
- def template
7
- render Layout.new(title: "Getting Started Testing Phlex Views") do
8
- render Markdown.new(<<~MD)
9
- # Getting Started
10
-
11
- The `Phlex::Testing::ViewHelper` module defines `render` allowing you to render Phlex views directly in your tests and make assertions against the output.
12
- MD
13
-
14
- render Example.new do |e|
15
- e.tab "test/test_hello.rb", <<~RUBY
16
- require "phlex/testing/view_helper"
17
-
18
- class TestHello < Minitest::Test
19
- include Phlex::Testing::ViewHelper
20
-
21
- def test_hello_output_includes_name
22
- output = render Hello.new("Joel")
23
- assert_equal "<h1>Hello Joel</h1>", output
24
- end
25
- end
26
- RUBY
27
-
28
- e.tab "hello.rb", <<~RUBY
29
- class Hello < Phlex::HTML
30
- def initialize(name)
31
- @name = name
32
- end
33
-
34
- def template
35
- h1 { "Hello \#{@name}" }
36
- end
37
- end
38
- RUBY
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pages
4
- module Testing
5
- class Nokogiri < ApplicationPage
6
- def template
7
- render Layout.new(title: "Testing with Nokogiri") do
8
- render Markdown.new(<<~MD)
9
- # Testing with Nokogiri
10
-
11
- Phlex includes test helpers for working with rendered views as [Nokogiri](https://nokogiri.org) documents and fragments.
12
-
13
- Nokogiri is not a dependency of Phlex, so you’ll need to install that separately to use this helper.
14
-
15
- ## Documents
16
-
17
- If your view represents a whole HTML document, you can require `phlex/testing/nokogiri` and include the `Phlex::Testing::Nokogiri::DocumentHelper` module to render your view as `Nokogiri::Document` using the `render` method.
18
- MD
19
-
20
- render Example.new do |e|
21
- e.tab "test.rb", <<~RUBY
22
- require "phlex/testing/nokogiri"
23
-
24
- class TestExample < Minitest::Test
25
- include Phlex::Testing::Nokogiri::DocumentHelper
26
-
27
- def test_example
28
- output = render Example.new
29
- assert_equal "Hello Joel", output.css("h1").text
30
- end
31
- end
32
- RUBY
33
-
34
- e.tab "hello.rb", <<~RUBY
35
- class Hello < Phlex::HTML
36
- def initialize(name)
37
- @name = name
38
- end
39
-
40
- def template
41
- h1 { "Hello \#{@name}" }
42
- end
43
- end
44
- RUBY
45
- end
46
-
47
- render Markdown.new(<<~MD)
48
- ## Fragments
49
-
50
- If your view represents a fragment (partial), you can require `phlex/testing/nokogiri` and include the `Phlex::Testing::Nokogiri::FragmentHelper` module to render your view as `Nokogiri::Fragment` with the `render` method.
51
- MD
52
-
53
- render Example.new do |e|
54
- e.tab "test.rb", <<~RUBY
55
- require "phlex/testing/nokogiri"
56
-
57
- class TestExample < Minitest::Test
58
- include Phlex::Testing::Nokogiri::FragmentHelper
59
-
60
- def test_example
61
- output = render Example.new("Joel")
62
- assert_equal "Hello Joel", output.css("h1").text
63
- end
64
- end
65
- RUBY
66
-
67
- e.tab "hello.rb", <<~RUBY
68
- class Hello < Phlex::HTML
69
- def initialize(name)
70
- @name = name
71
- end
72
-
73
- def template
74
- h1 { "Hello \#{@name}" }
75
- end
76
- end
77
- RUBY
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pages
4
- module Testing
5
- class Rails < ApplicationPage
6
- def template
7
- render Layout.new(title: "Testing Phlex Views in Rails") do
8
- render Markdown.new(<<~MD)
9
- # Testing Phlex views in Rails
10
-
11
- When you include `Phlex::Testing::Rails::ViewHelper`, views rendered in the test will have a view context, so they can use Rails helpers.
12
- MD
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pages
4
- class Translations < ApplicationPage
5
- def initialize
6
- I18n.backend.store_translations(
7
- "pt-BR", {
8
- hello: "Olá",
9
- views: { feedback: { welcome_message: { hello: "Olá" } } }
10
- }
11
- )
12
- I18n.locale = "pt-BR"
13
- end
14
-
15
- def template
16
- render Layout.new(title: "Translations") do
17
- render Markdown.new(<<~MD)
18
- # Translations
19
-
20
- Phlex has built-in support for translations with the **[I18n Gem](https://github.com/ruby-i18n/i18n)**.
21
-
22
- Just include `Phlex::Translation` in your view and use the `translate` method to access a translation.
23
- MD
24
-
25
- render Example.new do |e|
26
- e.tab "welcome_message.rb", <<~RUBY
27
- class WelcomeMessage < Phlex::HTML
28
- include Phlex::Translation
29
-
30
- def template
31
- h1 { translate("hello") }
32
- end
33
- end
34
- RUBY
35
-
36
- e.tab "pt-PR.yml", <<~YAML, syntax: :yaml
37
- pt-BR:
38
- hello: "Olá"
39
- YAML
40
-
41
- e.execute "WelcomeMessage.new.call"
42
- end
43
-
44
- render Markdown.new(<<~MD)
45
- ## Implicit scoopes
46
-
47
- Start your translate key with a `.` to use the name of the view as an implicit scope.
48
- MD
49
-
50
- render Example.new do |e|
51
- e.tab "welcome_message.rb", <<~RUBY
52
- module Views
53
- module Feedback
54
- class WelcomeMessage < Phlex::HTML
55
- include Phlex::Translation
56
-
57
- def template
58
- h1 { translate(".hello") }
59
- end
60
- end
61
- end
62
- end
63
- RUBY
64
-
65
- e.tab "pt-BR.yml", <<~YAML, syntax: :yaml
66
- pt-BR:
67
- views:
68
- feedback:
69
- welcome_message:
70
- hello: Olá
71
- YAML
72
-
73
- e.execute <<~RUBY
74
- Views::Feedback::WelcomeMessage.translation_path = 'views.feedback.welcome_message'
75
- Views::Feedback::WelcomeMessage.new.call
76
- RUBY
77
- end
78
- end
79
- end
80
- end
81
- end
data/docs/pages/views.rb DELETED
@@ -1,184 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pages
4
- class Views < ApplicationPage
5
- def template
6
- render Layout.new(title: "Phlex Views") do
7
- render Markdown.new(<<~MD)
8
- # Views
9
-
10
- Phlex Views are Ruby objects that represent your app's user interface — from pages and layouts and nav-bars, to headings and buttons and links.
11
-
12
- You can create a view class by subclassing `Phlex::HTML` and defining a `template` instance method.
13
- MD
14
-
15
- render Example.new do |e|
16
- e.tab "hello.rb", <<~RUBY
17
- class Hello < Phlex::HTML
18
- def template
19
- h1 { "👋 Hello World!" }
20
- end
21
- end
22
- RUBY
23
-
24
- e.execute "Hello.new.call"
25
- end
26
-
27
- render Markdown.new(<<~MD)
28
- The `template` method determines what your view will output when its rendered. The above example will output an `<h1>` tag with the content `👋 Hello world!`. Click on the "Output" tab above to see for yourself.
29
-
30
- ## Accepting arguments
31
-
32
- You can define an initializer for your views just like any other Ruby class. Let's make our `Hello` view take a `name` as a keyword argument, save it in an instance variable and render that variable in the template.
33
-
34
- We'll render this view with the arguments `name: "Joel"` and see what it produces.
35
- MD
36
-
37
- render Example.new do |e|
38
- e.tab "hello.rb", <<~RUBY
39
- class Hello < Phlex::HTML
40
- def initialize(name:)
41
- @name = name
42
- end
43
-
44
- def template
45
- h1 { "👋 Hello \#{@name}!" }
46
- end
47
- end
48
- RUBY
49
-
50
- e.execute "Hello.new(name: 'Joel').call"
51
- end
52
-
53
- render Markdown.new(<<~MD)
54
- ## Rendering views
55
-
56
- Views can render other views in their templates using the `render` method. Let's try rendering a couple of instances of this `Hello` view from a new `Example` view and look at the output of the `Example` view.
57
- MD
58
-
59
- render Example.new do |e|
60
- e.tab "example.rb", <<~RUBY
61
- class Example < Phlex::HTML
62
- def template
63
- render Hello.new(name: "Joel")
64
- render Hello.new(name: "Alexandre")
65
- end
66
- end
67
- RUBY
68
-
69
- e.tab "hello.rb", <<~RUBY
70
- class Hello < Phlex::HTML
71
- def initialize(name:)
72
- @name = name
73
- end
74
-
75
- def template
76
- h1 { "👋 Hello \#{@name}!" }
77
- end
78
- end
79
- RUBY
80
-
81
- e.execute "Example.new.call"
82
- end
83
-
84
- render Markdown.new(<<~MD)
85
- ## Passing content blocks
86
-
87
- Views can also yield content blocks, which can be passed in when rendering. Let's make a `Card` component that yields content in an `<article>` element with a `drop-shadow` class on it.
88
- MD
89
-
90
- render Example.new do |e|
91
- e.tab "card.rb", <<~RUBY
92
- class Card < Phlex::HTML
93
- def template(&content)
94
- article(class: "drop-shadow") do
95
- yield_content(&content)
96
- end
97
- end
98
- end
99
- RUBY
100
-
101
- e.tab "example.rb", <<~RUBY
102
- class Example < Phlex::HTML
103
- def template
104
- render Card.new do
105
- h1 { "👋 Hello!" }
106
- end
107
- end
108
- end
109
- RUBY
110
-
111
- e.execute "Example.new.call"
112
- end
113
-
114
- render Markdown.new(<<~MD)
115
- The template in the `Card` view accepts a block argument `&content` and uses the `yield_content` method to yield it in an `<article>` element.
116
-
117
- The `Example` view renders a `Card` and passes it a block with an `<h1>` element.
118
-
119
- Looking at the output of the `Example` view, we can see the `<h1>` element was rendered inside the `<article>` element from the `Card` view.
120
-
121
- ## Delegating content blocks
122
-
123
- Since the block of content was the only thing we need in the `<article>` element, we could have just passed the content block to the element instead.
124
-
125
- ```ruby
126
- class Card < Phlex::HTML
127
- def template(&content)
128
- article(class: "drop-shadow", &content)
129
- end
130
- end
131
- ```
132
- MD
133
-
134
- render Markdown.new(<<~MD)
135
- ## Registering custom elements
136
-
137
- You can register custom elements with the `register_element` macro. The custom element will only be available in the view where it is registered and subclasses of that view.
138
- MD
139
-
140
- render Example.new do |e|
141
- e.tab "example.rb", <<~RUBY
142
- class Example < Phlex::HTML
143
- register_element :trix_editor
144
-
145
- def template
146
- trix_editor input: "content", autofocus: true
147
- end
148
- end
149
- RUBY
150
-
151
- e.execute "Example.new.call"
152
- end
153
-
154
- render Markdown.new(<<~MD)
155
- ## Callbacks
156
-
157
- Prepend the `Phlex::HTML::Callbacks` module, and if you define `#before_rendering_template` and/or `#after_rendering_template` method in your view, they will be called immediately before and after your template is rendered.
158
- MD
159
-
160
- render Example.new do |e|
161
- e.tab "example.rb", <<~RUBY
162
- class Example < Phlex::HTML
163
- prepend Phlex::HTML::Callbacks
164
-
165
- def before_rendering_template
166
- h1 { "Hello" }
167
- end
168
-
169
- def template
170
- h2 { "World" }
171
- end
172
-
173
- def after_rendering_template
174
- h3 { "Bye" }
175
- end
176
- end
177
- RUBY
178
-
179
- e.execute "Example.new.call"
180
- end
181
- end
182
- end
183
- end
184
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CompilerTestHelpers
4
- # @return Array
5
- def compile(view)
6
- @compiler = Phlex::Compiler.new(view)
7
- output = []
8
-
9
- mock(@compiler) do |m|
10
- m.before(:redefine) { output << _1 }
11
- end
12
-
13
- @compiler.call
14
-
15
- output.map! do |method|
16
- Phlex::Compiler::Formatter.format("", SyntaxTree.parse(method))
17
- end
18
- end
19
- end
data/fixtures/content.rb DELETED
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fixtures
4
- module Content
5
- class BareString < Phlex::HTML
6
- def template
7
- h1 { "Hello" }
8
- end
9
- end
10
-
11
- class Symbol < Phlex::HTML
12
- def template
13
- h1 { :hello }
14
- end
15
- end
16
-
17
- class Float < Phlex::HTML
18
- def template
19
- h1 { 1.2 }
20
- end
21
- end
22
-
23
- class Integer < Phlex::HTML
24
- def template
25
- h1 { 1 }
26
- end
27
- end
28
-
29
- class Variable < Phlex::HTML
30
- def template
31
- greeting = "Hello"
32
- h1 { greeting }
33
- end
34
- end
35
-
36
- class InstanceVariable < Phlex::HTML
37
- def template
38
- h1 { @hello }
39
- end
40
- end
41
-
42
- class NestedTags < Phlex::HTML
43
- def template
44
- article {
45
- h1 { "Inside" }
46
- }
47
- end
48
- end
49
-
50
- class NonMutatingNestedContent < Phlex::HTML
51
- def template
52
- div { say_hello }
53
- end
54
-
55
- def say_hello
56
- "Hello"
57
- end
58
- end
59
- end
60
- end
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,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CommentComponent < ViewComponent::Base
4
- def initialize(name:, body:)
5
- @name = name
6
- @body = body
7
- end
8
- end
@@ -1,3 +0,0 @@
1
- <p><%= @emoji %></p>
2
-
3
- <%= content %>
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ReactionComponent < ViewComponent::Base
4
- def initialize(emoji:)
5
- @emoji = emoji
6
- end
7
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ArticlesController < ActionController::Base
4
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CommentsController < ActionController::Base
4
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- class ApplicationView < Phlex::HTML
5
- include Rails.application.routes.url_helpers
6
- include Phlex::Translation
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- module Articles
5
- class Form < ApplicationView
6
- include Phlex::Rails::Helpers::FormWith
7
-
8
- def template
9
- form_with url: "test" do |f|
10
- f.text_field :name
11
- end
12
- end
13
- end
14
- end
15
- 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,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- class Card < ApplicationView
5
- def template(&block)
6
- article class: "drop-shadow p-5 rounded", &block
7
- end
8
-
9
- def title(text)
10
- h3 class: "font-bold" do
11
- text
12
- end
13
- end
14
- end
15
- 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
@@ -1,3 +0,0 @@
1
- <%= render(CommentComponent.new(name: "Matz", body: "hey, folks")) do %>
2
- Hello, World from a ViewComponent!
3
- <% end %>