phlex 0.4.0 → 0.5.1

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +21 -1
  3. data/Gemfile +26 -13
  4. data/README.md +1 -1
  5. data/SECURITY.md +1 -1
  6. data/bench.rb +7 -0
  7. data/config/sus.rb +15 -0
  8. data/docs/assets/application.css +6 -0
  9. data/docs/build.rb +2 -0
  10. data/docs/components/callout.rb +1 -1
  11. data/docs/components/code_block.rb +2 -2
  12. data/docs/components/code_span.rb +1 -1
  13. data/docs/components/example.rb +4 -4
  14. data/docs/components/heading.rb +2 -2
  15. data/docs/components/layout.rb +55 -32
  16. data/docs/components/markdown.rb +13 -28
  17. data/docs/components/nav/item.rb +1 -1
  18. data/docs/components/nav.rb +1 -1
  19. data/docs/components/tabs/tab.rb +1 -1
  20. data/docs/components/tabs.rb +1 -1
  21. data/docs/components/title.rb +2 -2
  22. data/docs/pages/application_page.rb +1 -1
  23. data/docs/pages/helpers.rb +5 -5
  24. data/docs/pages/library/collections.rb +4 -22
  25. data/docs/pages/rails/getting_started.rb +7 -3
  26. data/docs/pages/rails/helpers.rb +3 -1
  27. data/docs/pages/rails/layouts.rb +2 -2
  28. data/docs/pages/rails/rendering_views.rb +1 -1
  29. data/docs/pages/templates.rb +6 -6
  30. data/docs/pages/testing/capybara.rb +48 -0
  31. data/docs/pages/testing/getting_started.rb +44 -0
  32. data/docs/pages/testing/nokogiri.rb +83 -0
  33. data/docs/pages/testing/rails.rb +17 -0
  34. data/docs/pages/translations.rb +81 -0
  35. data/docs/pages/views.rb +56 -8
  36. data/fixtures/compiler_test_helpers.rb +19 -0
  37. data/fixtures/content.rb +60 -0
  38. data/fixtures/dummy/app/views/application_view.rb +8 -0
  39. data/fixtures/dummy/app/views/articles/form.rb +1 -1
  40. data/fixtures/dummy/app/views/card.rb +1 -1
  41. data/fixtures/dummy/app/views/comments/comment.rb +1 -1
  42. data/fixtures/dummy/app/views/comments/reaction.rb +1 -1
  43. data/fixtures/dummy/app/views/heading.rb +1 -1
  44. data/fixtures/layout.rb +5 -5
  45. data/fixtures/page.rb +18 -24
  46. data/fixtures/{test_helper.rb → rails_helper.rb} +3 -8
  47. data/fixtures/standard_element.rb +87 -0
  48. data/fixtures/view_helper.rb +1 -1
  49. data/fixtures/void_element.rb +31 -0
  50. data/lib/generators/phlex/collection/templates/collection.rb.erb +2 -1
  51. data/lib/generators/phlex/controller/USAGE +10 -0
  52. data/lib/generators/phlex/controller/controller_generator.rb +54 -0
  53. data/lib/generators/phlex/controller/templates/controller.rb.erb +10 -0
  54. data/lib/generators/phlex/controller/templates/view.rb.erb +14 -0
  55. data/lib/generators/phlex/layout/templates/layout.rb.erb +2 -1
  56. data/lib/generators/phlex/page/templates/page.rb.erb +3 -1
  57. data/lib/generators/phlex/table/templates/table.rb.erb +3 -1
  58. data/lib/generators/phlex/view/templates/view.rb.erb +7 -1
  59. data/lib/generators/phlex/view/view_generator.rb +9 -1
  60. data/lib/install/phlex.rb +10 -1
  61. data/lib/phlex/block.rb +2 -4
  62. data/lib/phlex/buffered.rb +6 -8
  63. data/lib/phlex/callable.rb +9 -0
  64. data/lib/phlex/collection.rb +2 -27
  65. data/lib/phlex/compiler/elements.rb +49 -0
  66. data/lib/phlex/compiler/generators/content.rb +103 -0
  67. data/lib/phlex/compiler/generators/element.rb +61 -0
  68. data/lib/phlex/compiler/nodes/base.rb +19 -0
  69. data/lib/phlex/compiler/nodes/call.rb +9 -0
  70. data/lib/phlex/compiler/nodes/command.rb +13 -0
  71. data/lib/phlex/compiler/nodes/fcall.rb +18 -0
  72. data/lib/phlex/compiler/nodes/method_add_block.rb +33 -0
  73. data/lib/phlex/compiler/nodes/vcall.rb +9 -0
  74. data/lib/phlex/compiler/optimizer.rb +66 -0
  75. data/lib/phlex/compiler/visitors/base.rb +15 -0
  76. data/lib/phlex/compiler/visitors/file.rb +23 -11
  77. data/lib/phlex/compiler/visitors/stable_scope.rb +28 -0
  78. data/lib/phlex/compiler/visitors/statements.rb +36 -0
  79. data/lib/phlex/compiler/visitors/view.rb +19 -0
  80. data/lib/phlex/compiler/visitors/view_method.rb +59 -0
  81. data/lib/phlex/compiler.rb +23 -3
  82. data/lib/phlex/elements.rb +57 -0
  83. data/lib/phlex/helpers.rb +59 -0
  84. data/lib/phlex/html/callbacks.rb +11 -0
  85. data/lib/phlex/html.rb +208 -47
  86. data/lib/phlex/markdown.rb +76 -0
  87. data/lib/phlex/rails/form.rb +67 -0
  88. data/lib/phlex/rails/helpers.rb +39 -2
  89. data/lib/phlex/rails.rb +10 -0
  90. data/lib/phlex/renderable.rb +9 -3
  91. data/lib/phlex/testing/capybara.rb +25 -0
  92. data/lib/phlex/testing/nokogiri.rb +24 -0
  93. data/lib/phlex/testing/rails.rb +19 -0
  94. data/lib/phlex/testing/view_helper.rb +15 -0
  95. data/lib/phlex/translation.rb +23 -0
  96. data/lib/phlex/turbo/frame.rb +21 -0
  97. data/lib/phlex/turbo/stream.rb +18 -0
  98. data/lib/phlex/version.rb +1 -1
  99. data/lib/phlex.rb +23 -24
  100. metadata +62 -14
  101. data/.rspec +0 -1
  102. data/fixtures/compilation/vcall.rb +0 -38
  103. data/lib/phlex/compiler/generators/standard_element.rb +0 -30
  104. data/lib/phlex/compiler/generators/void_element.rb +0 -29
  105. data/lib/phlex/compiler/optimizers/base_optimizer.rb +0 -34
  106. data/lib/phlex/compiler/optimizers/vcall.rb +0 -29
  107. data/lib/phlex/compiler/visitors/base_visitor.rb +0 -19
  108. data/lib/phlex/compiler/visitors/component.rb +0 -28
  109. data/lib/phlex/compiler/visitors/component_method.rb +0 -28
  110. data/lib/phlex/view.rb +0 -229
@@ -16,7 +16,7 @@ module Pages
16
16
 
17
17
  render Example.new do |e|
18
18
  e.tab "hello.rb", <<~RUBY
19
- class Hello < Phlex::View
19
+ class Hello < Phlex::HTML
20
20
  def template
21
21
  h1(class: "text-xl font-bold") { "👋 Hello World!" }
22
22
  end
@@ -34,7 +34,7 @@ module Pages
34
34
 
35
35
  render Example.new do |e|
36
36
  e.tab "hello.rb", <<~RUBY
37
- class Hello < Phlex::View
37
+ class Hello < Phlex::HTML
38
38
  def template
39
39
  div(data: { controller: "hello" }) do
40
40
  # ...
@@ -54,7 +54,7 @@ module Pages
54
54
 
55
55
  render Example.new do |e|
56
56
  e.tab "channel_controls.rb", <<~RUBY
57
- class ChannelControls < Phlex::View
57
+ class ChannelControls < Phlex::HTML
58
58
  def template
59
59
  input(
60
60
  value: "1",
@@ -84,7 +84,7 @@ module Pages
84
84
 
85
85
  render Example.new do |e|
86
86
  e.tab "example.rb", <<~RUBY
87
- class Example < Phlex::View
87
+ class Example < Phlex::HTML
88
88
  def template
89
89
  template_tag do
90
90
  img src: "hidden.jpg", alt: "A hidden image."
@@ -104,7 +104,7 @@ module Pages
104
104
 
105
105
  render Example.new do |e|
106
106
  e.tab "heading.rb", <<~RUBY
107
- class Heading < Phlex::View
107
+ class Heading < Phlex::HTML
108
108
  def template
109
109
  h1 do
110
110
  strong { "Hello " }
@@ -125,7 +125,7 @@ module Pages
125
125
 
126
126
  render Example.new do |e|
127
127
  e.tab "links.rb", <<~RUBY
128
- class Links < Phlex::View
128
+ class Links < Phlex::HTML
129
129
  def template
130
130
  a(href: "/") { "Home" }
131
131
  whitespace
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,81 @@
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 CHANGED
@@ -9,12 +9,12 @@ module Pages
9
9
 
10
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
11
 
12
- You can create a view class by subclassing `Phlex::View` and defining a `template` instance method.
12
+ You can create a view class by subclassing `Phlex::HTML` and defining a `template` instance method.
13
13
  MD
14
14
 
15
15
  render Example.new do |e|
16
16
  e.tab "hello.rb", <<~RUBY
17
- class Hello < Phlex::View
17
+ class Hello < Phlex::HTML
18
18
  def template
19
19
  h1 { "👋 Hello World!" }
20
20
  end
@@ -36,7 +36,7 @@ module Pages
36
36
 
37
37
  render Example.new do |e|
38
38
  e.tab "hello.rb", <<~RUBY
39
- class Hello < Phlex::View
39
+ class Hello < Phlex::HTML
40
40
  def initialize(name:)
41
41
  @name = name
42
42
  end
@@ -58,7 +58,7 @@ module Pages
58
58
 
59
59
  render Example.new do |e|
60
60
  e.tab "example.rb", <<~RUBY
61
- class Example < Phlex::View
61
+ class Example < Phlex::HTML
62
62
  def template
63
63
  render Hello.new(name: "Joel")
64
64
  render Hello.new(name: "Alexandre")
@@ -67,7 +67,7 @@ module Pages
67
67
  RUBY
68
68
 
69
69
  e.tab "hello.rb", <<~RUBY
70
- class Hello < Phlex::View
70
+ class Hello < Phlex::HTML
71
71
  def initialize(name:)
72
72
  @name = name
73
73
  end
@@ -89,7 +89,7 @@ module Pages
89
89
 
90
90
  render Example.new do |e|
91
91
  e.tab "card.rb", <<~RUBY
92
- class Card < Phlex::View
92
+ class Card < Phlex::HTML
93
93
  def template(&content)
94
94
  article(class: "drop-shadow") do
95
95
  yield_content(&content)
@@ -99,7 +99,7 @@ module Pages
99
99
  RUBY
100
100
 
101
101
  e.tab "example.rb", <<~RUBY
102
- class Example < Phlex::View
102
+ class Example < Phlex::HTML
103
103
  def template
104
104
  render Card.new do
105
105
  h1 { "👋 Hello!" }
@@ -123,13 +123,61 @@ module Pages
123
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
124
 
125
125
  ```ruby
126
- class Card < Phlex::View
126
+ class Card < Phlex::HTML
127
127
  def template(&content)
128
128
  article(class: "drop-shadow", &content)
129
129
  end
130
130
  end
131
131
  ```
132
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
133
181
  end
134
182
  end
135
183
  end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,8 @@
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Views
4
4
  module Articles
5
- class Form < Phlex::View
5
+ class Form < ApplicationView
6
6
  include Phlex::Rails::Helpers::FormWith
7
7
 
8
8
  def template
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Views
4
- class Card < Phlex::View
4
+ class Card < ApplicationView
5
5
  def template(&block)
6
6
  article class: "drop-shadow p-5 rounded", &block
7
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Views
4
4
  module Comments
5
- class Comment < Phlex::View
5
+ class Comment < ApplicationView
6
6
  def initialize(name:, body:)
7
7
  @name = name
8
8
  @body = body
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Views
4
4
  module Comments
5
- class Reaction < Phlex::View
5
+ class Reaction < ApplicationView
6
6
  def initialize(emoji:)
7
7
  @emoji = emoji
8
8
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Views
4
- class Heading < Phlex::View
4
+ class Heading < ApplicationView
5
5
  def template(&block)
6
6
  h1(&block)
7
7
  end
data/fixtures/layout.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Example
4
- class LayoutComponent < Phlex::View
4
+ class LayoutComponent < Phlex::HTML
5
5
  def initialize(title: "Example")
6
6
  @title = title
7
7
  end
@@ -9,7 +9,7 @@ module Example
9
9
  def template(&block)
10
10
  html do
11
11
  head do
12
- title @title
12
+ title { @title }
13
13
  meta name: "viewport", content: "width=device-width,initial-scale=1"
14
14
  link href: "/assets/tailwind.css", rel: "stylesheet"
15
15
  end
@@ -17,9 +17,9 @@ module Example
17
17
  body class: "bg-zinc-100" do
18
18
  nav class: "p-5", id: "main_nav" do
19
19
  ul do
20
- li(class: "p-5") { a "Home", href: "/" }
21
- li(class: "p-5") { a "About", href: "/about" }
22
- li(class: "p-5") { a "Contact", href: "/contact" }
20
+ li(class: "p-5") { a(href: "/") { "Home" } }
21
+ li(class: "p-5") { a(href: "/about") { "About" } }
22
+ li(class: "p-5") { a(href: "/contact") { "Contact" } }
23
23
  end
24
24
  end
25
25
 
data/fixtures/page.rb CHANGED
@@ -1,37 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Example
4
- class Page < Phlex::View
4
+ class Page < Phlex::HTML
5
5
  def template
6
6
  render LayoutComponent.new do
7
- h1 "Hi"
7
+ h1 { "Hi" }
8
8
 
9
- 5.times do
10
- div do
11
- 10.times do
12
- a "Test", href: "something", unique: SecureRandom.uuid, data: { value: 1 }
9
+ table id: "test", class: "a b c d e f g" do
10
+ tr do
11
+ td id: "test", class: "a b c d e f g" do
12
+ span { "Hi" }
13
13
  end
14
- end
15
- end
16
14
 
17
- table do
18
- thead do
19
- 10.times do
20
- tr do
21
- th "Hi"
22
- end
15
+ td id: "test", class: "a b c d e f g" do
16
+ span { "Hi" }
17
+ end
18
+
19
+ td id: "test", class: "a b c d e f g" do
20
+ span { "Hi" }
21
+ end
22
+
23
+ td id: "test", class: "a b c d e f g" do
24
+ span { "Hi" }
23
25
  end
24
- end
25
26
 
26
- tbody do
27
- 100.times do
28
- tr class: "a b c d e f g", id: "something" do
29
- 10.times do
30
- td class: "f g h i j k l" do
31
- span "Test"
32
- end
33
- end
34
- end
27
+ td id: "test", class: "a b c d e f g" do
28
+ span { "Hi" }
35
29
  end
36
30
  end
37
31
  end