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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile +2 -1
  4. data/config.ru +9 -0
  5. data/lib/generators/phlex/controller/templates/view.rb.erb +0 -2
  6. data/lib/generators/phlex/layout/templates/layout.rb.erb +0 -1
  7. data/lib/generators/phlex/page/templates/page.rb.erb +0 -2
  8. data/lib/install/phlex.rb +0 -12
  9. data/lib/phlex/rails/form.rb +3 -3
  10. data/lib/phlex/rails/helpers.rb +31 -22
  11. data/lib/phlex/rails/html/append_method_added_warning.rb +17 -0
  12. data/lib/phlex/rails/html/class_methods.rb +13 -0
  13. data/lib/phlex/rails/html/overrides.rb +112 -0
  14. data/lib/phlex/rails/layout.rb +1 -0
  15. data/lib/phlex/rails/version.rb +1 -1
  16. data/lib/phlex/rails.rb +5 -1
  17. metadata +9 -40
  18. data/config/sus.rb +0 -5
  19. data/fixtures/dummy/app/assets/config/manifest.js +0 -0
  20. data/fixtures/dummy/app/components/comment_component.html.erb +0 -14
  21. data/fixtures/dummy/app/components/comment_component.rb +0 -8
  22. data/fixtures/dummy/app/components/reaction_component.html.erb +0 -3
  23. data/fixtures/dummy/app/components/reaction_component.rb +0 -7
  24. data/fixtures/dummy/app/controllers/articles_controller.rb +0 -4
  25. data/fixtures/dummy/app/controllers/comments_controller.rb +0 -4
  26. data/fixtures/dummy/app/views/application_view.rb +0 -7
  27. data/fixtures/dummy/app/views/articles/blog.html.erb +0 -14
  28. data/fixtures/dummy/app/views/articles/form.rb +0 -15
  29. data/fixtures/dummy/app/views/articles/index.html.erb +0 -14
  30. data/fixtures/dummy/app/views/articles/new.html.erb +0 -1
  31. data/fixtures/dummy/app/views/blog.rb +0 -27
  32. data/fixtures/dummy/app/views/card.rb +0 -15
  33. data/fixtures/dummy/app/views/comments/comment.rb +0 -25
  34. data/fixtures/dummy/app/views/comments/index.html.erb +0 -3
  35. data/fixtures/dummy/app/views/comments/reaction.rb +0 -17
  36. data/fixtures/dummy/app/views/comments/show.html.erb +0 -3
  37. data/fixtures/dummy/app/views/heading.rb +0 -9
  38. data/fixtures/dummy/config/database.yml +0 -3
  39. data/fixtures/dummy/config/routes.rb +0 -5
  40. data/fixtures/dummy/config/storage.yml +0 -3
  41. data/fixtures/dummy/db/schema.rb +0 -6
  42. data/fixtures/dummy/log/.gitignore +0 -1
  43. data/fixtures/dummy/public/favicon.ico +0 -0
  44. data/fixtures/rails_helper.rb +0 -9
  45. data/fixtures/view_helper.rb +0 -16
  46. data/lib/generators/phlex/collection/USAGE +0 -8
  47. data/lib/generators/phlex/collection/collection_generator.rb +0 -13
  48. data/lib/generators/phlex/collection/templates/collection.rb.erb +0 -16
  49. data/lib/generators/phlex/table/USAGE +0 -8
  50. data/lib/generators/phlex/table/table_generator.rb +0 -14
  51. data/lib/generators/phlex/table/templates/table.rb.erb +0 -11
  52. data/lib/phlex/rails/renderable.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a623bc2f1743cc9fb1c081bb545570ea4f74c68fd3239a91e2ea578f84351d49
4
- data.tar.gz: 49ef5747faf129b2c03a74f12f2aa20d1c42618309d3cb3f96eba7f27d0867b2
3
+ metadata.gz: 407ff3d219b8d6ec6bbe429422b18125dde3f9cfb73ec756bad2ab4f08953083
4
+ data.tar.gz: b0e4f337a9626bf67a5e4dfd4172648cf69c264008fde9a5e3c1b456b98d7e72
5
5
  SHA512:
6
- metadata.gz: 1bd8a771b4f85a3a3a6cd60e9b9e5c813f19a3ad5399fe5a2b668ac9a120435e5239c6a540b8565b3ac8a34848bb31fd0588c3bc9df0398148abb621eeb460d6
7
- data.tar.gz: 2822f8e1c9cff19bf6ac7aaa7e8f76241bdec94f425bebb195c60d750bd5262996a4db0acbdb55e28e49cf3280def61274588dfdc9d964efe3b0ef7db16b3823
6
+ metadata.gz: b4e29f9f569bc0259d037d7b8a6e3ee8fb267d8210b2faf1e0a952d25275419e27c9621b615aad8be7d3f5531872848a63e46fdeb1a3ec8506e9babc5b27b1af
7
+ data.tar.gz: 4440057f8e253c7f0f78dbd41e4f92c6a8e4faeeac4cb339fbc26d09bc7bafa72302d2f2bc066b8879579b4dc3c053ba07f301622a8801d9a635a216f0ef2ac3
data/.rubocop.yml CHANGED
@@ -29,3 +29,6 @@ Style/MixinUsage:
29
29
 
30
30
  Style/ConditionalAssignment:
31
31
  Enabled: false
32
+
33
+ Lint/UnderscorePrefixedVariableName:
34
+ Enabled: false
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 "sus"
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :all
9
+ run Combustion::Application
@@ -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 %>" }
@@ -1,7 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module Views
3
3
  class <%= class_name %> < Phlex::HTML
4
- include ApplicationView
5
4
  include Phlex::Rails::Layout
6
5
 
7
6
  def initialize(title:)
@@ -1,8 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  module Views
3
3
  class <%= class_name %> < Phlex::HTML
4
- include ApplicationView
5
-
6
4
  def template
7
5
  render Layout.new(title: "<%= class_name.gsub("::", " ") %>") do
8
6
  h1 { "👋 Hello World!" }
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?
@@ -29,7 +29,7 @@ module Phlex
29
29
  input(
30
30
  name: "authenticity_token",
31
31
  type: "hidden",
32
- value: @_view_context.form_authenticity_token
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
- @_view_context.url_for(@model)
45
+ helpers.url_for(@model)
46
46
  end
47
47
 
48
48
  def field_name(*field)
49
- @_view_context.field_name(ActiveModel::Naming.param_key(@model.class), *field)
49
+ helpers.field_name(ActiveModel::Naming.param_key(@model.class), *field)
50
50
  end
51
51
 
52
52
  input_field :url_field, type: "url"
@@ -4,8 +4,8 @@ module Phlex
4
4
  module Rails
5
5
  module Helpers
6
6
  module CSPMetaTag
7
- def csp_meta_tag(**options)
8
- if (output = @_view_context.csp_meta_tag(**options))
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 = @_view_context.csrf_meta_tags)
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 = @_view_context.action_cable_meta_tag)
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 << @_view_context.form_with(*args, **kwargs) { |form|
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(*sources)
81
- if (output = @_view_context.stylesheet_link_tag(*sources))
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(*args)
89
- if (output = @_view_context.favicon_link_tag(*args))
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(*args)
97
- if (output = @_view_context.image_tag(*args))
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(*args)
105
- if (output = @_view_context.audio_tag(*args))
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(*args)
113
- if (output = @_view_context.video_tag(*args))
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(*args)
121
- if (output = @_view_context.preload_link_tag(*args))
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(*sources)
129
- if (output = @_view_context.javascript_include_tag(*sources))
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 = @_view_context.javascript_importmap_tags)
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
- @_view_context.content_for(slot, capture(&block))
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex
4
+ module Rails
5
+ module HTML
6
+ module ClassMethods
7
+ def render_in(...)
8
+ new.render_in(...)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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
@@ -11,6 +11,7 @@ module Phlex
11
11
  include Helpers::ActionCableMetaTag
12
12
  include Helpers::JavaScriptIncludeTag
13
13
  include Helpers::JavaScriptImportmapTags
14
+ include Helpers::JavaScriptImportModuleTag
14
15
  end
15
16
  end
16
17
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.4.2"
5
+ VERSION = "0.5.1"
6
6
  end
7
7
  end
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::Renderable)
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.2
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: 2022-12-14 00:00:00.000000000 Z
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: '1'
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: '1'
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/sus.rb
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.25
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
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "phlex/rails"
4
-
5
- Zeitwerk::Loader.eager_load_all
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,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- class ApplicationView < Phlex::HTML
5
- include Rails.application.routes.url_helpers
6
- end
7
- end
@@ -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,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,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,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 %>
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- module Comments
5
- class Reaction < ApplicationView
6
- def initialize(emoji:)
7
- @emoji = emoji
8
- end
9
-
10
- def template(&block)
11
- p { @emoji }
12
-
13
- yield_content(&block)
14
- end
15
- end
16
- end
17
- end
@@ -1,3 +0,0 @@
1
- <%= render Views::Comments::Comment.new(name: "_why", body: "I'm back") do %>
2
- Hello, World from a Phlex Component!
3
- <% end %>
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Views
4
- class Heading < ApplicationView
5
- def template(&block)
6
- h1(&block)
7
- end
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: db/combustion_test.sqlite
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Rails.application.routes.draw do
4
- # Rails routes here
5
- end
@@ -1,3 +0,0 @@
1
- test:
2
- service: Disk
3
- root: /Users/joeldrapper/src/joeldrapper/phlex/tmp/storage
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Schema.define do
4
- # Set up any tables you need to exist for your test suite that don't belong
5
- # in migrations.
6
- end
@@ -1 +0,0 @@
1
- *.log
File without changes
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Bundler.require :default
4
-
5
- Combustion.path = "fixtures/dummy"
6
-
7
- Combustion.initialize! :action_controller do
8
- config.autoload_paths << "#{root}/app"
9
- end
@@ -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,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,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,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