phlex-rails 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ef3316773401cb9a664f24dfaf751f282bdceafc22db5d5aa59173d96b0794c
4
- data.tar.gz: 253849ceeeb4af1c1a3dd673c6e862cb17f8b1c3a13695556ccfc5b8d2855ce0
3
+ metadata.gz: d270dd49cf94953641c2f7987f05c3a4904b3e6c39983884b6c6dca60bd89a78
4
+ data.tar.gz: ee571c67532384b55c641777c42d295820f3ec00b5a48fb8bb3b331f3539009d
5
5
  SHA512:
6
- metadata.gz: 5e3cedfb00ab5762f2ffeeecf66e59a28dd8eac55d44272521c3c4094f0bd66d41d6a64925242cf429678417e87c536d644b3da0ebc0a566900665fb8863e894
7
- data.tar.gz: a88ea4826134ece2cda7cfae473e362dc1571822a4e27865e99b695bbdcf5bf2cd4d745334d6a1927a10cd463c7ccac54244af99d7255be6b28a144b5f6020e3
6
+ metadata.gz: b8bdc497af4542412f8addfda2b7cdb3602448df6867010a2352d7ed66e862073eb3cce54167ddf1cda8d8f7ad5a7f528f6a90987ad51107987fe7dcced8074b
7
+ data.tar.gz: 597a9cd87505991851beeaa69a3c41453b476a0e4d7b5709d8a3b6c9ab7ddd5df5b50bfe2a673c6c9ec62ba5c0bc2aa822315f8be5dec62cbf1e96fc9bcd8b8c
@@ -5,9 +5,19 @@ module Phlex
5
5
  class ControllerGenerator < ::Rails::Generators::NamedBase # :nodoc:
6
6
  source_root File.expand_path("templates", __dir__)
7
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"
8
+ argument :actions,
9
+ type: :array,
10
+ default: [],
11
+ banner: "action action"
12
+
13
+ class_option :skip_routes,
14
+ type: :boolean,
15
+ desc: "Don't add routes to config/routes.rb."
16
+
17
+ class_option :parent,
18
+ type: :string,
19
+ default: "ApplicationController",
20
+ desc: "The parent class for the generated controller"
11
21
 
12
22
  check_class_collision suffix: "Controller"
13
23
 
@@ -20,15 +30,19 @@ module Phlex
20
30
  empty_directory base_path
21
31
 
22
32
  actions.each do |action|
23
- Rails::Generators.invoke("phlex:view", [remove_possible_suffix(name) + "/" + action])
33
+ ::Rails::Generators.invoke("phlex:page", [name + "/" + action])
24
34
  end
25
35
  end
26
36
 
27
37
  def add_routes
28
38
  return if options[:skip_routes]
29
- return if actions.empty?
30
39
 
31
- routing_code = actions.map { |action| "get '#{file_name}/#{action}'" }.join("\n")
40
+ routing_code = "resources :#{file_name}"
41
+
42
+ if actions.any?
43
+ routing_code << ", only: [#{actions.map { ":#{_1}" }.join(', ')}]"
44
+ end
45
+
32
46
  route routing_code, namespace: regular_class_path
33
47
  end
34
48
 
@@ -43,7 +57,11 @@ module Phlex
43
57
  end
44
58
 
45
59
  def file_name
46
- @_file_name ||= remove_possible_suffix(super)
60
+ remove_possible_suffix(super)
61
+ end
62
+
63
+ def name
64
+ remove_possible_suffix(super)
47
65
  end
48
66
 
49
67
  def remove_possible_suffix(name)
@@ -17,7 +17,7 @@ module Phlex
17
17
  ::Rails.root.join("app/views/layout.rb").exist?
18
18
  end
19
19
 
20
- hook_for :test_framework
20
+ # hook_for :test_framework
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+
5
+ module Phlex
6
+ module Rails
7
+ class OutputBuffer < SimpleDelegator
8
+ def safe_append=(value)
9
+ return unless value
10
+
11
+ self << case value
12
+ when String then value
13
+ when Symbol then value.name
14
+ else value.to_s
15
+ end
16
+ end
17
+
18
+ def append=(value)
19
+ return unless value
20
+
21
+ if value.html_safe?
22
+ self.safe_append = value
23
+ else
24
+ self << case value
25
+ when String then CGI.escape_html(value)
26
+ when Symbol then CGI.escape_html(value.name)
27
+ else CGI.escape_html(value.to_s)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -17,18 +17,25 @@ module Phlex
17
17
  end
18
18
 
19
19
  def render_in(view_context, &block)
20
- output_buffer = view_context.output_buffer
21
-
22
- # Since https://github.com/rails/rails/pull/45731
23
- if output_buffer.respond_to?(:raw_buffer)
24
- buffer = output_buffer.raw_buffer
20
+ if block_given?
21
+ call(view_context: view_context) do |*args|
22
+ view_context.with_output_buffer(OutputBuffer.new(@_target)) 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
25
36
  else
26
- buffer = Buffer.new(output_buffer)
37
+ call(view_context: view_context).html_safe
27
38
  end
28
-
29
- call(buffer, view_context: view_context, &block)
30
-
31
- nil
32
39
  end
33
40
  end
34
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  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.2.0
4
+ version: 0.2.2
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-11-24 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -125,11 +125,11 @@ files:
125
125
  - lib/install/phlex.rb
126
126
  - lib/phlex-rails.rb
127
127
  - lib/phlex/rails.rb
128
- - lib/phlex/rails/buffer.rb
129
128
  - lib/phlex/rails/engine.rb
130
129
  - lib/phlex/rails/form.rb
131
130
  - lib/phlex/rails/helpers.rb
132
131
  - lib/phlex/rails/layout.rb
132
+ - lib/phlex/rails/output_buffer.rb
133
133
  - lib/phlex/rails/renderable.rb
134
134
  - lib/phlex/rails/version.rb
135
135
  - lib/phlex/testing/rails.rb
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex
4
- module Rails
5
- # A wrapper for Rails’ OutputBuffer that acts like a Phlex buffer.
6
-
7
- class Buffer < SimpleDelegator
8
- def <<(value)
9
- __getobj__.safe_append = (value)
10
- self
11
- end
12
-
13
- def length
14
- __getobj__.length
15
- end
16
- end
17
- end
18
- end