phlex 0.5.3 → 1.0.0.rc1

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 +1 -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 +2 -0
  9. data/lib/phlex/html.rb +73 -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,8 +0,0 @@
1
- Description:
2
- Generates a Phlex collection view with the given name
3
-
4
- Example:
5
- rails generate phlex:collection Articles::List
6
-
7
- This will create:
8
- app/views/articles/list.rb
@@ -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,10 +0,0 @@
1
- Description:
2
- Generates a Rails controller with Phlex views for the supplied actions
3
-
4
- Example:
5
- rails generate phlex:controller Articles index show
6
-
7
- This will create:
8
- app/controllers/articles_controller.rb
9
- app/views/articles/index.rb
10
- app/views/articles/show.rb
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Generators
5
- class ControllerGenerator < ::Rails::Generators::NamedBase # :nodoc:
6
- source_root File.expand_path("templates", __dir__)
7
-
8
- argument :actions, type: :array, default: [], banner: "action action"
9
- class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
10
- class_option :parent, type: :string, default: "ApplicationController", desc: "The parent class for the generated controller"
11
-
12
- check_class_collision suffix: "Controller"
13
-
14
- def create_controller_files
15
- template "controller.rb.erb", File.join("app/controllers", class_path, "#{file_name}_controller.rb")
16
- end
17
-
18
- def copy_view_files
19
- base_path = File.join("app/views", class_path, file_name)
20
- empty_directory base_path
21
-
22
- actions.each do |action|
23
- Rails::Generators.invoke("phlex:view", [remove_possible_suffix(name) + "/" + action])
24
- end
25
- end
26
-
27
- def add_routes
28
- return if options[:skip_routes]
29
- return if actions.empty?
30
-
31
- routing_code = actions.map { |action| "get '#{file_name}/#{action}'" }.join("\n")
32
- route routing_code, namespace: regular_class_path
33
- end
34
-
35
- hook_for :test_framework, as: :controller do |generator|
36
- invoke generator, [remove_possible_suffix(name), actions]
37
- end
38
-
39
- private
40
-
41
- def parent_class_name
42
- options[:parent]
43
- end
44
-
45
- def file_name
46
- @_file_name ||= remove_possible_suffix(super)
47
- end
48
-
49
- def remove_possible_suffix(name)
50
- name.sub(/_?controller$/i, "")
51
- end
52
- end
53
- end
54
- end
@@ -1,10 +0,0 @@
1
- <% module_namespacing do -%>
2
- class <%= class_name %>Controller < <%= parent_class_name.classify %>
3
- <% actions.each do |action| -%>
4
- def <%= action %>
5
- render Views::<%= class_name %>::<%= action.camelize %>.new
6
- end
7
- <%= "\n" unless action == actions.last -%>
8
- <% end -%>
9
- end
10
- <% end -%>
@@ -1,14 +0,0 @@
1
- <% module_namespacing do -%>
2
- module Views
3
- class <%= class_name %>::<%= @action.camelize %> < Phlex::HTML
4
- include ApplicationView
5
-
6
- def template
7
- <%= "# " unless @has_layout %>render Layout.new(title: "<%= class_name.gsub("::", " ").titlecase %> - <%= @action.titlecase %>") do
8
- h1 { "<%= class_name %>#<%= @action %>" }
9
- p { "Find me in <%= @path %>" }
10
- <%= "# " unless @has_layout %>end
11
- end
12
- end
13
- end
14
- <% end %>
@@ -1,8 +0,0 @@
1
- Description:
2
- Generates a Phlex layout view with the given name
3
-
4
- Example:
5
- rails generate phlex:layout Layout
6
-
7
- This will create:
8
- app/views/layout.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Generators
5
- class LayoutGenerator < ::Rails::Generators::NamedBase
6
- source_root File.expand_path("templates", __dir__)
7
-
8
- def create_view
9
- template "layout.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
10
- end
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- <% module_namespacing do -%>
2
- module Views
3
- class <%= class_name %> < Phlex::HTML
4
- include ApplicationView
5
- include Phlex::Rails::Layout
6
-
7
- def initialize(title:)
8
- @title = title
9
- end
10
-
11
- def template(&)
12
- doctype
13
-
14
- html do
15
- head do
16
- meta charset: "utf-8"
17
- csp_meta_tag
18
- csrf_meta_tags
19
- meta name: "viewport", content: "width=device-width,initial-scale=1"
20
- title { @title }
21
- stylesheet_link_tag "application"
22
- end
23
-
24
- body do
25
- main(&)
26
- end
27
- end
28
- end
29
- end
30
- end
31
- <% end %>
@@ -1,8 +0,0 @@
1
- Description:
2
- Generates a Phlex page view with the given name
3
-
4
- Example:
5
- rails generate phlex:page Articles::Index
6
-
7
- This will create:
8
- app/views/articles/index.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Generators
5
- class PageGenerator < ::Rails::Generators::NamedBase
6
- source_root File.expand_path("templates", __dir__)
7
-
8
- def create_view
9
- template "page.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- <% module_namespacing do -%>
2
- module Views
3
- class <%= class_name %> < Phlex::HTML
4
- include ApplicationView
5
-
6
- def template
7
- render Layout.new(title: "<%= class_name.gsub("::", " ") %>") do
8
- h1 { "👋 Hello World!" }
9
- end
10
- end
11
- end
12
- end
13
- <% end %>
@@ -1,8 +0,0 @@
1
- Description:
2
- Generates a Phlex table collection view with the given name
3
-
4
- Example:
5
- rails generate phlex:collection Articles::Table --properties title author created_at
6
-
7
- This will create:
8
- app/views/articles/table.rb
@@ -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,8 +0,0 @@
1
- Description:
2
- Generates a Phlex view with the given name
3
-
4
- Example:
5
- rails generate phlex:view Sidebar
6
-
7
- This will create:
8
- app/views/sidebar.rb
@@ -1,14 +0,0 @@
1
- <% module_namespacing do -%>
2
- module Views
3
- class <%= class_name %> < Phlex::HTML
4
- include ApplicationView
5
-
6
- def template
7
- <%= "# " unless @layout %>render Layout.new(title: "<%= class_name.gsub("::", " ").titlecase %>") do
8
- h1 { "<%= class_name %>" }
9
- p { "Find me in <%= @path %>" }
10
- <%= "# " unless @layout %>end
11
- end
12
- end
13
- end
14
- <% end %>
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Generators
5
- class ViewGenerator < ::Rails::Generators::NamedBase
6
- source_root File.expand_path("templates", __dir__)
7
-
8
- def create_view
9
- @layout = layout
10
- @path = File.join("app/views", class_path, "#{file_name}.rb")
11
- template "view.rb.erb", @path
12
- end
13
-
14
- private
15
-
16
- def layout
17
- ::Rails.root.join("app/views/layout.rb").exist?
18
- end
19
- end
20
- end
21
- end
data/lib/install/phlex.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- say "Installing Phlex..."
4
-
5
- application_configuration_path = Rails.root.join("config/application.rb")
6
- application_configuration_content = File.read(application_configuration_path)
7
-
8
- pattern = %r(config.autoload_paths << (Rails.root.join\(.app.\)|.\#{root}/app.)\n)
9
-
10
- unless application_configuration_content.match?(pattern)
11
- inject_into_class(
12
- application_configuration_path,
13
- "Application",
14
- %( config.autoload_paths << "\#{root}/app"\n)
15
- )
16
- end
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
- include Phlex::Translation
26
- end
27
- end
28
- RUBY
29
- end
30
-
31
- tailwind_config_path = Rails.root.join("config/tailwind.config.js")
32
-
33
- if tailwind_config_path.exist?
34
- insert_into_file tailwind_config_path, after: "content: [" do
35
- "\n './app/views/**/*.rb',"
36
- end
37
- end
38
-
39
- say "Phlex successfully installed!"
data/lib/phlex/block.rb DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Block
5
- include Callable
6
-
7
- def initialize(context, &block)
8
- @context = context
9
- @block = block
10
- end
11
-
12
- def call(*args, **kwargs)
13
- @context.instance_exec(*args, **kwargs, &@block)
14
- end
15
- end
16
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Elements
4
- module VCall
5
- def format(formatter)
6
- Phlex::Compiler::Generators::Element.new(
7
- Phlex::Compiler::Nodes::VCall.new(self),
8
- formatter: formatter
9
- ).call
10
- end
11
- end
12
-
13
- module FCall
14
- def format(formatter)
15
- Phlex::Compiler::Generators::Element.new(
16
- Phlex::Compiler::Nodes::FCall.new(self),
17
- formatter: formatter
18
- ).call
19
- end
20
- end
21
-
22
- module Command
23
- def format(formatter)
24
- Phlex::Compiler::Generators::Element.new(
25
- Phlex::Compiler::Nodes::Command.new(self),
26
- formatter: formatter
27
- ).call
28
- end
29
- end
30
-
31
- module MutatingMethodAddBlock
32
- def format(formatter)
33
- Phlex::Compiler::Generators::Element.new(
34
- Phlex::Compiler::Nodes::MethodAddBlock.new(self),
35
- formatter: formatter,
36
- mutating: true
37
- ).call
38
- end
39
- end
40
-
41
- module MethodAddBlock
42
- def format(formatter)
43
- Phlex::Compiler::Generators::Element.new(
44
- Phlex::Compiler::Nodes::MethodAddBlock.new(self),
45
- formatter: formatter
46
- ).call
47
- end
48
- end
49
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Compiler
5
- class Formatter < SyntaxTree::Formatter
6
- def genspace
7
- -> (n) { "\t" * (n / 2) }
8
- end
9
-
10
- def format(node, stackable: true)
11
- stack << node if stackable
12
- doc = node.format(self)
13
- stack.pop if stackable
14
- doc
15
- end
16
-
17
- def flush
18
- text "" if @open_string_append
19
-
20
- super
21
- end
22
-
23
- def breakable(*args, **kwargs)
24
- if !@texting && @open_string_append
25
- @broken = kwargs
26
- else
27
- super
28
- end
29
- end
30
-
31
- def chain_append(&block)
32
- @appending = true
33
-
34
- if @open_string_append
35
- text '" << '
36
- elsif @open_chain_append
37
- text " << "
38
- else
39
- text "@_target << "
40
- end
41
-
42
- @open_string_append = false
43
- @open_chain_append = true
44
-
45
- yield(self)
46
-
47
- @appending = false
48
- end
49
-
50
- def append(&block)
51
- @appending = true
52
-
53
- unless @open_string_append
54
- if @open_chain_append
55
- text ' << "'
56
- else
57
- text '@_target << "'
58
- end
59
-
60
- @open_chain_append = false
61
- @open_string_append = true
62
- end
63
-
64
- yield(self)
65
-
66
- @appending = false
67
- end
68
-
69
- def text(value, ...)
70
- @texting = true
71
-
72
- unless @appending
73
- if @open_string_append
74
- super('"')
75
- @open_string_append = false
76
- end
77
-
78
- @open_chain_append = false
79
-
80
- breakable(**@broken) if @broken
81
- end
82
-
83
- @broken = false
84
-
85
- super
86
-
87
- @texting = false
88
- end
89
- end
90
- end
91
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Compiler
5
- module Generators
6
- class Content
7
- def initialize(formatter, content:, mutating: false)
8
- @formatter = formatter
9
- @content = content
10
- @mutating = mutating
11
- end
12
-
13
- def call
14
- return if nil_value?
15
- return bare_string_value if bare_string_value?
16
- return symbol_value if symbol_value?
17
- return numeric_value if numeric_value?
18
- return variable_value if variable_value?
19
-
20
- unknown_value
21
- end
22
-
23
- private
24
-
25
- def nil_value?
26
- case @content
27
- in SyntaxTree::VarRef[value: SyntaxTree::Kw[value: "nil"]]
28
- true
29
- else
30
- false
31
- end
32
- end
33
-
34
- def bare_string_value?
35
- case @content
36
- in SyntaxTree::StringLiteral[parts: [SyntaxTree::TStringContent]]
37
- true
38
- else
39
- false
40
- end
41
- end
42
-
43
- def symbol_value?
44
- @content.is_a?(SyntaxTree::SymbolLiteral)
45
- end
46
-
47
- def numeric_value?
48
- @content.is_a?(SyntaxTree::Int) || @content.is_a?(SyntaxTree::FloatLiteral)
49
- end
50
-
51
- def variable_value?
52
- @content.is_a?(SyntaxTree::VarRef)
53
- end
54
-
55
- def bare_string_value
56
- @formatter.append do |f|
57
- f.text Hescape.escape_html(
58
- @content.parts.first.value
59
- )
60
- end
61
- end
62
-
63
- def symbol_value
64
- @formatter.append do |f|
65
- f.text Hescape.escape_html(
66
- @content.value.value
67
- )
68
- end
69
- end
70
-
71
- def numeric_value
72
- @formatter.append do |f|
73
- f.text Hescape.escape_html(
74
- @content.value
75
- )
76
- end
77
- end
78
-
79
- def variable_value
80
- @formatter.chain_append do |f|
81
- f.text "Hescape.escape_html("
82
- @content.format(f)
83
- f.text ")"
84
- end
85
- end
86
-
87
- def unknown_value
88
- @formatter.breakable(force: true)
89
- if @mutating
90
- @content.format(@formatter)
91
- else
92
- @formatter.text "yield_content {"
93
- @formatter.breakable(force: true)
94
- @content.format(@formatter)
95
- @formatter.breakable(force: true)
96
- @formatter.text "}"
97
- end
98
- @formatter.breakable(force: true)
99
- end
100
- end
101
- end
102
- end
103
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Compiler
5
- module Generators
6
- class Element
7
- def initialize(node, formatter:, mutating: false)
8
- @node = node
9
- @formatter = formatter
10
- @mutating = mutating
11
- end
12
-
13
- def call
14
- @formatter.append do |f|
15
- f.text "<"
16
- f.text tag
17
- end
18
-
19
- if @node.arguments&.parts&.any?
20
- @formatter.chain_append do |f|
21
- f.text "_attributes("
22
- @node.arguments.format(@formatter)
23
- f.text ")"
24
- end
25
- end
26
-
27
- @formatter.append do |f|
28
- f.text ">"
29
- end
30
-
31
- return if void?
32
-
33
- case @node.content
34
- in SyntaxTree::Statements[body: [c]]
35
- Content.new(@formatter, content: c, mutating: @mutating).call
36
- in nil
37
- nil
38
- else
39
- @node.content.format(@formatter)
40
- end
41
-
42
- @formatter.append do |f|
43
- f.text "</"
44
- f.text tag
45
- f.text ">"
46
- end
47
- end
48
-
49
- private
50
-
51
- def tag
52
- HTML::STANDARD_ELEMENTS[@node.name] || HTML::VOID_ELEMENTS[@node.name]
53
- end
54
-
55
- def void?
56
- HTML::VOID_ELEMENTS.key?(@node.name)
57
- end
58
- end
59
- end
60
- end
61
- end