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 +4 -4
- data/lib/generators/phlex/controller/controller_generator.rb +25 -7
- data/lib/generators/phlex/view/view_generator.rb +1 -1
- data/lib/phlex/rails/output_buffer.rb +33 -0
- data/lib/phlex/rails/renderable.rb +17 -10
- data/lib/phlex/rails/version.rb +1 -1
- metadata +3 -3
- data/lib/phlex/rails/buffer.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d270dd49cf94953641c2f7987f05c3a4904b3e6c39983884b6c6dca60bd89a78
|
4
|
+
data.tar.gz: ee571c67532384b55c641777c42d295820f3ec00b5a48fb8bb3b331f3539009d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
9
|
-
|
10
|
-
|
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:
|
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 =
|
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
|
-
|
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)
|
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
data/lib/phlex/rails/version.rb
CHANGED
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.
|
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-
|
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
|
data/lib/phlex/rails/buffer.rb
DELETED
@@ -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
|