crudable-rails 1.5.0 → 1.5.1
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/README.md +1 -1
- data/lib/crudable/rails/generators/scaffold_controller_extension.rb +5 -1
- data/lib/crudable/rails/generators/turbo_forms_scaffold_extension.rb +32 -12
- data/lib/crudable/rails/version.rb +1 -1
- data/lib/generators/crudable/scaffold/USAGE +3 -2
- metadata +1 -4
- data/lib/generators/crudable/templates/turbo_forms/_form.html.erb.tt +0 -37
- data/lib/generators/crudable/templates/turbo_forms/edit.html.erb.tt +0 -14
- data/lib/generators/crudable/templates/turbo_forms/new.html.erb.tt +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bc075d091ac9fd062d7aa5c2ab7cceecaaa189c152d603a73006891650a661f
|
|
4
|
+
data.tar.gz: 1cca79a75e27ec9fdf7d82b889030fc1c208caa63308993b2accf5226789a347
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b8f108bf56e924eb6c47fafaeabacc2a2e2b94380cfd7cd885e9ded0bc4f36f83155d63449d1349b7a9c1a56d2a21ec6f9281d5668ffa5f3c4b3597f11628e9
|
|
7
|
+
data.tar.gz: 00e9eb6393f9582fb722ea57794c5ba234eab1eecded762fd0d14760adae60098cfbc2c1d89d531b68e17fd2c2ad842b6acfff23c124578fa725cd8ace03660b
|
data/README.md
CHANGED
|
@@ -61,7 +61,7 @@ bin/rails generate crudable:scaffold Post title:string body:text
|
|
|
61
61
|
bin/rails generate crudable:scaffold Post title:string body:text --turbo-forms
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
With `--turbo-forms`, generated `new` and `edit`
|
|
64
|
+
With `--turbo-forms`, generated `new.turbo_stream.erb` and `edit.turbo_stream.erb` templates re-render the scaffold `_form` partial on validation failure. HTML views and `_form` are left to the scaffold generator (for example tailwindcss-rails or your view component extension). The `_form` partial should expose a `dom_id(record, :form)` target so turbo_stream responses can replace it inline.
|
|
65
65
|
|
|
66
66
|
**Controller only** — when you already have a model and views, or want to wire up the controller yourself:
|
|
67
67
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../../../generators/crudable/controller_helpers'
|
|
4
4
|
require_relative 'turbo_forms_generator_option'
|
|
5
|
+
require_relative 'turbo_forms_scaffold_extension'
|
|
5
6
|
|
|
6
7
|
module Crudable
|
|
7
8
|
module Rails
|
|
@@ -36,7 +37,6 @@ Rails.application.config.after_initialize do
|
|
|
36
37
|
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
|
37
38
|
require 'rails/generators/rails/scaffold/scaffold_generator'
|
|
38
39
|
require_relative 'scaffold_extension'
|
|
39
|
-
require_relative 'turbo_forms_scaffold_extension'
|
|
40
40
|
|
|
41
41
|
unless Rails::Generators::ScaffoldControllerGenerator
|
|
42
42
|
.ancestors.include?(Crudable::Rails::Generators::ScaffoldControllerExtension)
|
|
@@ -53,3 +53,7 @@ Rails.application.config.after_initialize do
|
|
|
53
53
|
Erb::Generators::ScaffoldGenerator.prepend Crudable::Rails::Generators::TurboFormsScaffoldExtension
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
|
+
|
|
57
|
+
Rails.application.config.to_prepare do
|
|
58
|
+
Crudable::Rails::Generators.install_tailwindcss_turbo_forms_extension!
|
|
59
|
+
end
|
|
@@ -6,12 +6,28 @@ require_relative '../../../generators/crudable/controller_helpers'
|
|
|
6
6
|
module Crudable
|
|
7
7
|
module Rails
|
|
8
8
|
module Generators
|
|
9
|
+
module TurboFormsViewFileCopying
|
|
10
|
+
extend ActiveSupport::Concern
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def copy_turbo_forms_view_files
|
|
15
|
+
view_path = File.join('app/views', controller_file_path)
|
|
16
|
+
|
|
17
|
+
%w[new edit].each do |view|
|
|
18
|
+
template "turbo_forms/#{view}.turbo_stream.erb",
|
|
19
|
+
File.join(view_path, "#{view}.turbo_stream.erb")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
9
24
|
module TurboFormsScaffoldExtension
|
|
10
25
|
extend ActiveSupport::Concern
|
|
11
26
|
|
|
12
27
|
prepended do
|
|
13
28
|
include TurboFormsGeneratorOption
|
|
14
29
|
include ::Crudable::Generators::ControllerHelpers
|
|
30
|
+
include TurboFormsViewFileCopying
|
|
15
31
|
end
|
|
16
32
|
|
|
17
33
|
def copy_view_files
|
|
@@ -20,22 +36,26 @@ module Crudable
|
|
|
20
36
|
|
|
21
37
|
copy_turbo_forms_view_files
|
|
22
38
|
end
|
|
39
|
+
end
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
def self.install_tailwindcss_turbo_forms_extension!
|
|
42
|
+
return unless defined?(Tailwindcss::Generators::ScaffoldGenerator)
|
|
25
43
|
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
klass = Tailwindcss::Generators::ScaffoldGenerator
|
|
45
|
+
return if klass.instance_methods.include?(:copy_view_files_without_crudable_turbo_forms)
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
klass.include TurboFormsGeneratorOption
|
|
48
|
+
klass.include ::Crudable::Generators::ControllerHelpers
|
|
49
|
+
klass.include TurboFormsViewFileCopying
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
klass.class_eval do
|
|
52
|
+
alias_method :copy_view_files_without_crudable_turbo_forms, :copy_view_files
|
|
53
|
+
|
|
54
|
+
def copy_view_files
|
|
55
|
+
copy_view_files_without_crudable_turbo_forms
|
|
56
|
+
return unless options.turbo_forms?
|
|
57
|
+
|
|
58
|
+
copy_turbo_forms_view_files
|
|
39
59
|
end
|
|
40
60
|
end
|
|
41
61
|
end
|
|
@@ -11,8 +11,9 @@ Example:
|
|
|
11
11
|
This will create the same files as `rails generate scaffold`, but the controller
|
|
12
12
|
will use `crudable` with documented override hooks.
|
|
13
13
|
|
|
14
|
-
With --turbo-forms, new and edit
|
|
15
|
-
|
|
14
|
+
With --turbo-forms, matching new.turbo_stream.erb and edit.turbo_stream.erb templates
|
|
15
|
+
are generated for validation error responses. Scaffold HTML views and _form.html.erb
|
|
16
|
+
are left to the scaffold generator (e.g. tailwindcss-rails).
|
|
16
17
|
|
|
17
18
|
Notes:
|
|
18
19
|
Nested routing is automatically supported: if a parent `*_id` param is present
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: crudable-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.5.
|
|
4
|
+
version: 1.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomislav Simnett
|
|
@@ -118,10 +118,7 @@ files:
|
|
|
118
118
|
- lib/generators/crudable/scaffold/USAGE
|
|
119
119
|
- lib/generators/crudable/scaffold/scaffold_generator.rb
|
|
120
120
|
- lib/generators/crudable/templates/crudable_controller.rb.tt
|
|
121
|
-
- lib/generators/crudable/templates/turbo_forms/_form.html.erb.tt
|
|
122
|
-
- lib/generators/crudable/templates/turbo_forms/edit.html.erb.tt
|
|
123
121
|
- lib/generators/crudable/templates/turbo_forms/edit.turbo_stream.erb.tt
|
|
124
|
-
- lib/generators/crudable/templates/turbo_forms/new.html.erb.tt
|
|
125
122
|
- lib/generators/crudable/templates/turbo_forms/new.turbo_stream.erb.tt
|
|
126
123
|
- lib/tasks/crudable_tasks.rake
|
|
127
124
|
homepage: https://gitlab.com/initforthe/crudable-rails
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<%%= form_with model: <%= form_with_model %> do |f| %>
|
|
2
|
-
<%% if f.object.errors.any? %>
|
|
3
|
-
<div style="color: red">
|
|
4
|
-
<h2><%%= pluralize(f.object.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
|
5
|
-
|
|
6
|
-
<ul>
|
|
7
|
-
<%% f.object.errors.each do |error| %>
|
|
8
|
-
<li><%%= error.full_message %></li>
|
|
9
|
-
<%% end %>
|
|
10
|
-
</ul>
|
|
11
|
-
</div>
|
|
12
|
-
<%% end %>
|
|
13
|
-
|
|
14
|
-
<% form_attributes.each do |attribute| -%>
|
|
15
|
-
<div>
|
|
16
|
-
<% if attribute.password_digest? -%>
|
|
17
|
-
<%%= f.label :password, style: "display: block" %>
|
|
18
|
-
<%%= f.password_field :password %>
|
|
19
|
-
</div>
|
|
20
|
-
|
|
21
|
-
<div>
|
|
22
|
-
<%%= f.label :password_confirmation, style: "display: block" %>
|
|
23
|
-
<%%= f.password_field :password_confirmation %>
|
|
24
|
-
<% elsif attribute.attachments? -%>
|
|
25
|
-
<%%= f.label :<%= attribute.column_name %>, style: "display: block" %>
|
|
26
|
-
<%%= f.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
|
|
27
|
-
<% else -%>
|
|
28
|
-
<%%= f.label :<%= attribute.column_name %>, style: "display: block" %>
|
|
29
|
-
<%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %>
|
|
30
|
-
<% end -%>
|
|
31
|
-
</div>
|
|
32
|
-
|
|
33
|
-
<% end -%>
|
|
34
|
-
<div>
|
|
35
|
-
<%%= f.submit %>
|
|
36
|
-
</div>
|
|
37
|
-
<%% end %>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<%% content_for :title, "Editing <%= human_name.downcase %>" %>
|
|
2
|
-
|
|
3
|
-
<h1>Editing <%= human_name.downcase %></h1>
|
|
4
|
-
|
|
5
|
-
<%%= tag.div id: dom_id(@<%= singular_table_name %>, :form) do %>
|
|
6
|
-
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
|
7
|
-
<%% end %>
|
|
8
|
-
|
|
9
|
-
<br>
|
|
10
|
-
|
|
11
|
-
<div>
|
|
12
|
-
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %> %> |
|
|
13
|
-
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
|
|
14
|
-
</div>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<%% content_for :title, "New <%= human_name.downcase %>" %>
|
|
2
|
-
|
|
3
|
-
<h1>New <%= human_name.downcase %></h1>
|
|
4
|
-
|
|
5
|
-
<%%= tag.div id: dom_id(@<%= singular_table_name %>, :form) do %>
|
|
6
|
-
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
|
7
|
-
<%% end %>
|
|
8
|
-
|
|
9
|
-
<br>
|
|
10
|
-
|
|
11
|
-
<div>
|
|
12
|
-
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
|
|
13
|
-
</div>
|