phlex 0.5.2 → 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 -29
  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/engine.rb +0 -8
  120. data/lib/phlex/html/callbacks.rb +0 -11
  121. data/lib/phlex/markdown.rb +0 -76
  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 -10
  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 -10
  132. data/package-lock.json +0 -1195
  133. data/package.json +0 -5
  134. data/tailwind.config.js +0 -7
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class Base
5
- def initialize(node)
6
- @node = node
7
- end
8
-
9
- attr_accessor :node
10
-
11
- def arguments
12
- nil
13
- end
14
-
15
- def content
16
- nil
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class Call < Base
5
- def name
6
- nil
7
- end
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class Command < Base
5
- def name
6
- @node.message.value.to_sym
7
- end
8
-
9
- def arguments
10
- @node.arguments
11
- end
12
- end
13
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class FCall < Base
5
- def name
6
- @node.value.value.to_sym
7
- end
8
-
9
- def arguments
10
- case @node.arguments
11
- in SyntaxTree::Args
12
- @node.arguments
13
- in SyntaxTree::ArgParen
14
- @node.arguments.arguments
15
- end
16
- end
17
- end
18
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class MethodAddBlock < Base
5
- def name
6
- method_call.name
7
- end
8
-
9
- def arguments
10
- method_call.arguments
11
- end
12
-
13
- def method_call
14
- @method_call ||= case @node.call
15
- in SyntaxTree::FCall
16
- Phlex::Compiler::Nodes::FCall.new(@node.call)
17
- in SyntaxTree::Command
18
- Phlex::Compiler::Nodes::Command.new(@node.call)
19
- in SyntaxTree::Call
20
- Phlex::Compiler::Nodes::Call.new(@node.call)
21
- end
22
- end
23
-
24
- def content
25
- case @node.block
26
- in SyntaxTree::BraceBlock
27
- @node.block.statements
28
- in SyntaxTree::DoBlock
29
- @node.block.bodystmt.statements
30
- end
31
- end
32
- end
33
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Nodes
4
- class VCall < Base
5
- def name
6
- @node.value.value.to_sym
7
- end
8
- end
9
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Phlex::Compiler
4
- class Optimizer
5
- def initialize(node, compiler:)
6
- @node = node
7
- @compiler = compiler
8
- end
9
-
10
- def call
11
- return optimize_element if optimize_element?
12
-
13
- false
14
- end
15
-
16
- private
17
-
18
- def optimize_element
19
- case @node
20
- in Nodes::VCall
21
- @node.node.extend(Phlex::Compiler::Elements::VCall)
22
- in Nodes::FCall
23
- @node.node.extend(Phlex::Compiler::Elements::FCall)
24
- in Nodes::Command
25
- @node.node.extend(Phlex::Compiler::Elements::Command)
26
- in Nodes::MethodAddBlock
27
- optimize_add_method_block_element
28
- end
29
-
30
- true
31
- end
32
-
33
- def optimize_add_method_block_element
34
- visitor = Phlex::Compiler::Visitors::Statements.new(@compiler)
35
- visitor.visit(@node.content)
36
-
37
- if visitor.mutating?
38
- @node.node.extend(Phlex::Compiler::Elements::MutatingMethodAddBlock)
39
- else
40
- @node.node.extend(Phlex::Compiler::Elements::MethodAddBlock)
41
- end
42
-
43
- Phlex::Compiler::Visitors::ViewMethod.new(@compiler).visit(@node.content)
44
- end
45
-
46
- def optimize_element?
47
- element? && !redefined?
48
- end
49
-
50
- def element?
51
- standard_element? || void_element?
52
- end
53
-
54
- def redefined?
55
- @compiler.redefined?(@node.name)
56
- end
57
-
58
- def standard_element?
59
- Phlex::HTML::STANDARD_ELEMENTS.key?(@node.name)
60
- end
61
-
62
- def void_element?
63
- Phlex::HTML::VOID_ELEMENTS.key?(@node.name)
64
- end
65
- end
66
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Visitors
4
- class Base < SyntaxTree::Visitor
5
- def initialize(compiler = nil)
6
- @compiler = compiler
7
- end
8
-
9
- private
10
-
11
- def format(node)
12
- Phlex::Compiler::Formatter.format("", node)
13
- end
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Visitors
4
- class File < Base
5
- def initialize(compiler)
6
- @scope = []
7
- super
8
- end
9
-
10
- visit_method def visit_class(node)
11
- @scope.push(node)
12
-
13
- if node.location.start_line == @compiler.line
14
- @compiler.scope = @scope
15
- View.new(@compiler).visit_all(node.child_nodes)
16
- else
17
- super
18
- end
19
-
20
- @scope.pop
21
- end
22
-
23
- visit_method def visit_module(node)
24
- @scope.push(node)
25
- super
26
- @scope.pop
27
- end
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # A mixin for visitors that stops them from visiting other scopes.
4
-
5
- module Phlex::Compiler::Visitors::StableScope
6
- def visit_class(node)
7
- nil
8
- end
9
-
10
- def visit_module(node)
11
- nil
12
- end
13
-
14
- def visit_brace_block(node)
15
- nil
16
- end
17
-
18
- def visit_do_block(node)
19
- nil
20
- end
21
-
22
- def visit_method_add_block(node)
23
- node = Phlex::Compiler::Nodes::MethodAddBlock.new(node)
24
- if node.method_call.name == :render
25
- visit(node.content)
26
- end
27
- end
28
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Visitors
4
- class Statements < Base
5
- MUTATING_METHODS = [:raw, :whitespace, :comment, :text, :doctype]
6
-
7
- include StableScope
8
-
9
- def mutating?
10
- !!@mutating
11
- end
12
-
13
- visit_method def visit_vcall(node)
14
- check Phlex::Compiler::Nodes::VCall.new(node)
15
- end
16
-
17
- visit_method def visit_fcall(node)
18
- check Phlex::Compiler::Nodes::FCall.new(node)
19
- end
20
-
21
- visit_method def visit_command(node)
22
- check Phlex::Compiler::Nodes::Command.new(node)
23
- end
24
-
25
- visit_method def visit_method_add_block(node)
26
- check Phlex::Compiler::Nodes::MethodAddBlock.new(node)
27
- end
28
-
29
- private
30
-
31
- def check(node)
32
- @mutating = true if @compiler.tag_method?(node.name)
33
- @mutating = true if MUTATING_METHODS.include?(node.name) && !@compiler.redefined?(node.name)
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Visitors
4
- class View < Base
5
- include StableScope
6
-
7
- visit_method def visit_def(node)
8
- visitor = ViewMethod.new(@compiler)
9
- visitor.visit_all(node.child_nodes)
10
-
11
- if visitor.optimized_something?
12
- @compiler.redefine(
13
- format(node),
14
- line: node.location.start_line
15
- )
16
- end
17
- end
18
- end
19
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Compiler::Visitors
4
- class ViewMethod < Base
5
- include StableScope
6
-
7
- def optimized_something?
8
- !!@optimized_something
9
- end
10
-
11
- visit_method def visit_method_add_block(node)
12
- return super if node.call.is_a?(SyntaxTree::Call)
13
-
14
- optimizer = Phlex::Compiler::Optimizer.new(
15
- Phlex::Compiler::Nodes::MethodAddBlock.new(node),
16
- compiler: @compiler
17
- )
18
-
19
- if optimizer.call
20
- @optimized_something = true
21
- end
22
-
23
- super
24
- end
25
-
26
- visit_method def visit_vcall(node)
27
- optimizer = Phlex::Compiler::Optimizer.new(
28
- Phlex::Compiler::Nodes::VCall.new(node),
29
- compiler: @compiler
30
- )
31
-
32
- if optimizer.call
33
- @optimized_something = true
34
- end
35
- end
36
-
37
- visit_method def visit_fcall(node)
38
- optimizer = Phlex::Compiler::Optimizer.new(
39
- Phlex::Compiler::Nodes::FCall.new(node),
40
- compiler: @compiler
41
- )
42
-
43
- if optimizer.call
44
- @optimized_something = true
45
- end
46
- end
47
-
48
- visit_method def visit_command(node)
49
- optimizer = Phlex::Compiler::Optimizer.new(
50
- Phlex::Compiler::Nodes::Command.new(node),
51
- compiler: @compiler
52
- )
53
-
54
- if optimizer.call
55
- @optimized_something = true
56
- end
57
- end
58
- end
59
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- class Compiler
5
- def initialize(view)
6
- @view = view
7
- end
8
-
9
- attr_writer :scope
10
-
11
- def inspect
12
- "#{self.class.name} for #{@view.name} view class"
13
- end
14
-
15
- def call
16
- Visitors::File.new(self).visit(tree)
17
- end
18
-
19
- def tag_method?(method_name)
20
- (HTML::STANDARD_ELEMENTS.key?(method_name) || HTML::VOID_ELEMENTS.key?(method_name)) && !redefined?(method_name)
21
- end
22
-
23
- def redefined?(method_name)
24
- prototype = @view.allocate
25
-
26
- @view.instance_method(method_name).bind(prototype) !=
27
- Phlex::HTML.instance_method(method_name).bind(prototype)
28
- end
29
-
30
- def redefine(method, line:)
31
- patch = scope + method + unscope
32
- eval(patch, Kernel.binding, file, (line - 1))
33
- end
34
-
35
- def scope
36
- @scope.map do |scope|
37
- case scope
38
- in SyntaxTree::ModuleDeclaration then "module #{scope.constant.constant.value};"
39
- in SyntaxTree::ClassDeclaration then "class #{scope.constant.constant.value};"
40
- end
41
- end.join + "\n"
42
- end
43
-
44
- def unscope
45
- "; end" * @scope.size
46
- end
47
-
48
- def line
49
- location[1]
50
- end
51
-
52
- private
53
-
54
- def tree
55
- @tree ||= SyntaxTree.parse(source)
56
- end
57
-
58
- def source
59
- SyntaxTree.read(file)
60
- end
61
-
62
- def file
63
- location[0]
64
- end
65
-
66
- def location
67
- ::Module.const_source_location(@view.name)
68
- end
69
- end
70
- end
data/lib/phlex/engine.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/engine"
4
-
5
- module Phlex
6
- class Engine < ::Rails::Engine
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::HTML::Callbacks
4
- def template(&block)
5
- before_rendering_template if respond_to?(:before_rendering_template)
6
-
7
- super
8
-
9
- after_rendering_template if respond_to?(:after_rendering_template)
10
- end
11
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "markly"
4
-
5
- module Phlex
6
- class Markdown < Phlex::HTML
7
- def initialize(content)
8
- @content = content
9
- end
10
-
11
- def template
12
- visit(doc)
13
- end
14
-
15
- private
16
-
17
- def doc
18
- Markly.parse(@content)
19
- end
20
-
21
- def visit(node)
22
- return if node.nil?
23
-
24
- case node.type
25
- in :document | :softbreak
26
- visit_children(node)
27
- in :text
28
- text(node.string_content)
29
- in :header
30
- case node.header_level
31
- in 1 then h1 { visit_children(node) }
32
- in 2 then h2 { visit_children(node) }
33
- in 3 then h3 { visit_children(node) }
34
- in 4 then h4 { visit_children(node) }
35
- in 5 then h5 { visit_children(node) }
36
- in 6 then h6 { visit_children(node) }
37
- end
38
- in :paragraph
39
- grandparent = node.parent&.parent
40
-
41
- if grandparent&.type == :list && grandparent&.list_tight
42
- visit_children(node)
43
- else
44
- p { visit_children(node) }
45
- end
46
- in :link
47
- a(href: node.url) { visit_children(node) }
48
- in :emph
49
- em { visit_children(node) }
50
- in :strong
51
- strong { visit_children(node) }
52
- in :list
53
- case node.list_type
54
- in :ordered_list then ol { visit_children(node) }
55
- in :bullet_list then ul { visit_children(node) }
56
- end
57
- in :list_item
58
- li { visit_children(node) }
59
- in :code
60
- whitespace { code { text(node.string_content) } }
61
- in :code_block
62
- code_block(node.string_content, language: node.fence_info) do |**attributes|
63
- pre(**attributes) { text(node.string_content) }
64
- end
65
- end
66
- end
67
-
68
- def code_block(code, language:)
69
- yield
70
- end
71
-
72
- def visit_children(node)
73
- node.each { |c| visit(c) }
74
- end
75
- end
76
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Rails
5
- class Form < Phlex::HTML
6
- def initialize(model)
7
- @model = model
8
- end
9
-
10
- def self.input_field(method_name, type:)
11
- define_method method_name do |field, value: @model.attributes[field.to_s], **attributes|
12
- input(
13
- name: field_name(field),
14
- type: type,
15
- value: value,
16
- **attributes
17
- )
18
- end
19
- end
20
-
21
- def template(&block)
22
- form action: @url, method: @method do
23
- authenticity_token_field
24
- yield_content(&block)
25
- end
26
- end
27
-
28
- def authenticity_token_field
29
- input(
30
- name: "authenticity_token",
31
- type: "hidden",
32
- value: @_view_context.form_authenticity_token
33
- )
34
- end
35
-
36
- def submit(value)
37
- input(
38
- name: "commit",
39
- type: "submit",
40
- value: value
41
- )
42
- end
43
-
44
- def url
45
- @_view_context.url_for(@model)
46
- end
47
-
48
- def field_name(*field)
49
- @_view_context.field_name(ActiveModel::Naming.param_key(@model.class), *field)
50
- end
51
-
52
- input_field :url_field, type: "url"
53
- input_field :text_field, type: "text"
54
- input_field :date_field, type: "date"
55
- input_field :time_field, type: "time"
56
- input_field :week_field, type: "week"
57
- input_field :month_field, type: "month"
58
- input_field :email_field, type: "email"
59
- input_field :color_field, type: "color"
60
- input_field :hidden_field, type: "hidden"
61
- input_field :search_field, type: "search"
62
- input_field :password_field, type: "password"
63
- input_field :telephone_field, type: "tel"
64
- input_field :datetime_local_field, type: "datetime-local"
65
- end
66
- end
67
- end