dry_crud 5.2.0 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +2 -2
- data/README.rdoc +52 -51
- data/VERSION +1 -1
- data/app/assets/stylesheets/sample.scss +45 -24
- data/app/controllers/crud_controller.rb +19 -19
- data/app/controllers/dry_crud/generic_model.rb +2 -4
- data/app/controllers/dry_crud/render_callbacks.rb +3 -3
- data/app/controllers/list_controller.rb +1 -1
- data/app/helpers/actions_helper.rb +7 -7
- data/app/helpers/dry_crud/form/builder.rb +50 -43
- data/app/helpers/dry_crud/form/control.rb +8 -11
- data/app/helpers/dry_crud/table/actions.rb +12 -12
- data/app/helpers/dry_crud/table/builder.rb +10 -10
- data/app/helpers/dry_crud/table/col.rb +4 -4
- data/app/helpers/form_helper.rb +6 -8
- data/app/helpers/format_helper.rb +7 -7
- data/app/helpers/i18n_helper.rb +5 -5
- data/app/helpers/table_helper.rb +15 -16
- data/app/helpers/utility_helper.rb +5 -6
- data/app/views/crud/new.html.erb +1 -1
- data/app/views/crud/new.html.haml +1 -1
- data/app/views/layouts/application.html.erb +9 -6
- data/app/views/layouts/application.html.haml +7 -5
- data/app/views/list/_search.html.erb +1 -3
- data/app/views/list/_search.html.haml +1 -2
- data/app/views/shared/_error_messages.html.erb +2 -2
- data/lib/dry_crud/engine.rb +8 -4
- data/lib/generators/dry_crud/dry_crud_generator.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +4 -4
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +3 -3
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +6 -5
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +2 -2
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +6 -6
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +2 -2
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +4 -14
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +4 -4
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +1 -1
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +5 -5
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +3 -3
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +8 -8
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +7 -7
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +2 -2
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +20 -11
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +2 -3
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +4 -6
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +6 -6
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf13269261b9cbae5f96418d05f9032805c3a50e1f1e7c02b79d71bfbf6c89c1
|
4
|
+
data.tar.gz: e28764d18296115dcae6119a97ed282d1d4da809585791333c0e6c328634d140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a767e47df9be1a264bafa9af864278546e14fcfdf5bf728686c01bdf76d52823a73a215177a136a8c696c15898a82da899b88a2fc3252977d88c16a9da811436
|
7
|
+
data.tar.gz: d899147d340aae9dc0e75a64f718b3ada4debdd84a5d77970d2b6284cb9690f2f43877fe77319c900cb524a6da57a79be5c155098114d298cc040c09b6e3353b
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010-
|
1
|
+
Copyright (c) 2010-2023 Pascal Zumkehr
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
= DRY CRUD
|
2
2
|
|
3
|
-
{
|
3
|
+
{rdoc-image:https://github.com/codez/dry_crud/actions/workflows/build.yml/badge.svg}[https://github.com/codez/dry_crud/actions/workflows/build.yml]
|
4
|
+
{rdoc-image:https://api.codeclimate.com/v1/badges/ef7488764a0d9805b37d/maintainability}[https://codeclimate.com/github/codez/dry_crud/maintainability]
|
5
|
+
{rdoc-image:https://api.codeclimate.com/v1/badges/ef7488764a0d9805b37d/test_coverage}[https://codeclimate.com/github/codez/dry_crud/test_coverage]
|
4
6
|
|
5
7
|
dry_crud generates simple and extendable controllers, views and helpers that support you to DRY up the CRUD code in your Rails projects. List, search, sort, show, create, edit and destroy any model entries in just 5 minutes. Start with these artifacts and build a clean base to efficiently develop your application upon.
|
6
8
|
|
@@ -21,7 +23,7 @@ We recommend to use dry_crud as a generator as described above for the best unde
|
|
21
23
|
|
22
24
|
rails generate dry_crud:file list/index.html.erb
|
23
25
|
|
24
|
-
If a dry_crud file exists in your application, it will be used, if not, the one from the engine is used. This holds for controllers,
|
26
|
+
If a dry_crud file exists in your application, it will be used, if not, the one from the engine is used. This holds for controllers, helper methods and view templates.
|
25
27
|
|
26
28
|
|
27
29
|
== Integration
|
@@ -33,12 +35,11 @@ To integrate dry_crud into your code, only a few additions are required:
|
|
33
35
|
* Optionally define a +list+ scope in your models to be used in the +index+ action.
|
34
36
|
* Optionally define a +options_list+ scope in your models to be used in select dropdowns.
|
35
37
|
|
36
|
-
From version 5.0 onwards, the major and minor version numbers will be kept in sync with Rails, and only the matching Rails version is supported.
|
37
|
-
|
38
|
+
From version 5.0 onwards, the major and minor version numbers will be kept in sync with Rails, and only the matching Rails version is supported.
|
38
39
|
|
39
40
|
== Background
|
40
41
|
|
41
|
-
In most Rails applications, you have some models that require basic CRUD (create, read, update, delete) functionality. There are various possibilities like Rails scaffolding, {Inherited Resources}[https://github.com/
|
42
|
+
In most Rails applications, you have some models that require basic CRUD (create, read, update, delete) functionality. There are various possibilities like Rails scaffolding, {Inherited Resources}[https://github.com/activeadmin/inherited_resources] or {Rails Admin}[https://github.com/railsadminteam/rails_admin]. Still, various parts in your application remain duplicated. While you might pull up common methods into a common superclass controller, most views still contain very similar code. And then you also have to remember the entire API of these frameworks.
|
42
43
|
|
43
44
|
Enter dry_crud.
|
44
45
|
|
@@ -46,11 +47,11 @@ Enter dry_crud.
|
|
46
47
|
The main idea of dry_crud is to concentrate basic functionality of your application, like CRUD actions, uniform formatting, forms and tables into specifically extendable units. dry_crud generates various foundation classes that you may browse easily and adapt freely to your application's needs. For each model, you may transparently customize arbitrary parts or just fallback to the general behavior. This applies not only for controllers, but also for view templates and helpers. There is no black box your code depends on. You lay the foundation that fits your application best.
|
47
48
|
</b>
|
48
49
|
|
49
|
-
dry_crud is a Rails generator. All code resides in your application and is open for you to inspect and to extend. You may pick whatever you consider useful or adapt what is not sufficient. Even if you do not require any CRUD functionality, you might find some helpers simplifying your work. There are no runtime dependencies to the dry_crud gem. Having said this, dry_crud does not want to provide a maximum of functionality that requires a lot of configuration, but rather a clean and lightweight foundation to build your application's requirements upon. This is why dry_crud comes as a generator and not as a Rails
|
50
|
+
dry_crud is a Rails generator. All code resides in your application and is open for you to inspect and to extend. You may pick whatever you consider useful or adapt what is not sufficient. Even if you do not require any CRUD functionality, you might find some helpers simplifying your work. There are no runtime dependencies to the dry_crud gem. Having said this, dry_crud does not want to provide a maximum of functionality that requires a lot of configuration, but rather a clean and lightweight foundation to build your application's requirements upon. This is why dry_crud comes as a generator and not as a Rails extension.
|
50
51
|
|
51
|
-
dry_crud does not depend on any other
|
52
|
+
dry_crud does not depend on any other gems, but easily allows you to integrate them in order to unify the behavior of your CRUD controllers. You might even use the gems mentioned above to adapt your generated CrudController base class. All classes come with thorough tests that provide you with a solid foundation for implementing your own adaptions.
|
52
53
|
|
53
|
-
A basic CSS gets you started with your application's layout. For advanced needs, dry_crud supports the styles and classes used in {Bootstrap
|
54
|
+
A basic CSS gets you started with your application's layout. For advanced needs, dry_crud supports the styles and classes used in {Bootstrap}[http://getbootstrap.com]. As the views are generated into your application code, you are free to change the styling to your needs.
|
54
55
|
|
55
56
|
If you find yourself adapting the same parts of dry_crud for your applications over and over, please feel free to {fork me on Github}[http://github.com/codez/dry_crud].
|
56
57
|
|
@@ -66,7 +67,7 @@ Say you want to manage a +Person+ model. Overwrite the +to_s+ method of your mod
|
|
66
67
|
<tt>app/models/person.rb</tt>:
|
67
68
|
class Person
|
68
69
|
def to_s
|
69
|
-
|
70
|
+
[lastname, firstname].compact.join(' ')
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -74,7 +75,7 @@ Then create the following controller. The +permitted_attrs+ define the attribute
|
|
74
75
|
|
75
76
|
<tt>app/controllers/people_controller.rb</tt>:
|
76
77
|
class PeopleController < CrudController
|
77
|
-
self.permitted_attrs = [:firstname, :lastname, :birthday, :
|
78
|
+
self.permitted_attrs = [:firstname, :lastname, :birthday, :gender, :city_id]
|
78
79
|
end
|
79
80
|
|
80
81
|
That's it. You have a sortable overview of all people, detail pages and forms to edit and create people. Of course, you may delete people as well. By default, all attributes are displayed and formatted according to their column type wherever they appear. This applies for the input fields as well.
|
@@ -84,14 +85,14 @@ That's it. You have a sortable overview of all people, detail pages and forms to
|
|
84
85
|
|
85
86
|
Well, maybe there are certain attributes you do not want to display in the people list, or others that are not editable in the form. No problem, simply create a <tt> _list</tt> partial in <tt>app/views/people/_list.html.erb</tt> to customize this:
|
86
87
|
|
87
|
-
<%= crud_table :lastname, :firstname, :city, :
|
88
|
+
<%= crud_table :lastname, :firstname, :city, :gender %>
|
88
89
|
|
89
90
|
This only displays these four attributes in the table. All other templates, as well as the main index view, fallback to the ones in <tt>app/views/crud</tt>.
|
90
91
|
|
91
92
|
|
92
93
|
==== Adapt general behavior
|
93
94
|
|
94
|
-
Next, let's adapt a part of the general behavior used in all CRUD controllers. As an example, we include pagination with kaminari[https://github.com/
|
95
|
+
Next, let's adapt a part of the general behavior used in all CRUD controllers. As an example, we include pagination with kaminari[https://github.com/kaminari/kaminari] in all our overview tables:
|
95
96
|
|
96
97
|
In <tt>app/controllers/list_controller.rb</tt>, change the list_entries method to
|
97
98
|
def list_entries
|
@@ -106,11 +107,11 @@ And we are done. All our controllers inheriting from ListController, including a
|
|
106
107
|
|
107
108
|
==== Special formatting for selected attributes
|
108
109
|
|
109
|
-
Sometimes, the default formatting provided by +format_attr+ will not be sufficient. We have a boolean column +
|
110
|
+
Sometimes, the default formatting provided by +format_attr+ will not be sufficient. We have a boolean column +female+ in our model (which is quite a legacy nowadays!), but we would like to display 'male' or 'female' for it (instead of 'no' or 'yes', which is a bit cryptic). Just define a method in your view helper starting with <tt>format_</tt>, followed by the class and attribute name:
|
110
111
|
|
111
112
|
In <tt>app/helpers/people.rb</tt>:
|
112
|
-
def
|
113
|
-
person.
|
113
|
+
def format_person_female(person)
|
114
|
+
person.female ? 'female' : 'male'
|
114
115
|
end
|
115
116
|
|
116
117
|
Should you have attributes with the same name for multiple models that you want to be formatted the same way, you may define a helper method <tt>format_{attr}</tt> for these attributes.
|
@@ -133,7 +134,7 @@ In <tt>app/controllers/people_controller.rb</tt>:
|
|
133
134
|
When you display computed values in your list table, you may define sort mappings to enable sorting of these columns:
|
134
135
|
|
135
136
|
In <tt>app/controllers/people_controller.rb</tt>:
|
136
|
-
self.sort_mappings = {age: 'birthday', city_id: 'cities.name'}
|
137
|
+
self.sort_mappings = { age: 'birthday', city_id: 'cities.name' }
|
137
138
|
|
138
139
|
There is also a simple search functionality (based on SQL LIKE queries) implemented in Crud::Searchable. Define an array of columns in your controller's +search_columns+ class variable to make the entries searchable by these fields:
|
139
140
|
|
@@ -151,17 +152,17 @@ dry_crud provides two builder classes for update/create forms and tables for dis
|
|
151
152
|
|
152
153
|
The following code defines a table with some attribute columns for a list of same-type entries. Columns get a header corresponding to the attribute name:
|
153
154
|
<%= plain_table(@people) do |t|
|
154
|
-
t.sortable_attrs
|
155
|
+
t.sortable_attrs(:lastname, :firstname)
|
155
156
|
end %>
|
156
157
|
|
157
158
|
If entries is empty, a basic 'No entries found' message is rendered instead of the table.
|
158
159
|
|
159
160
|
To render custom columns, use the +col+ method with an appropriate block:
|
160
161
|
<%= plain_table(@people) do |t|
|
161
|
-
t.sortable_attrs
|
162
|
-
t.col('', class: 'center') {|entry| image_tag(entry.picture) }
|
163
|
-
t.attr
|
164
|
-
t.col('Map') {|entry| link_to(entry.city, "http://maps.google.com/?q=#{entry.city}" }
|
162
|
+
t.sortable_attrs(:lastname, :firstname)
|
163
|
+
t.col('', class: 'center') { |entry| image_tag(entry.picture) }
|
164
|
+
t.attr(:street)
|
165
|
+
t.col('Map') { |entry| link_to(entry.city, "http://maps.google.com/?q=#{entry.city}") }
|
165
166
|
end %>
|
166
167
|
|
167
168
|
For views of subclasses of ListController, you can directly use the +crud_table+ helper method, where you do not have to pass the <tt>@people</tt> list explicitly and actions are added automatically.
|
@@ -175,9 +176,9 @@ Forms work very similar. In the most simple case, you just have to specify which
|
|
175
176
|
Of course, custom input fields may be defined as well:
|
176
177
|
<%= standard_form(@person, url: custom_update_person_path(@person.id)) do |f| %>
|
177
178
|
<%= f.labeled_input_fields :firstname, :lastname %>
|
178
|
-
<%= f.labeled(:
|
179
|
-
<%= f.radio_button :
|
180
|
-
<%= f.radio_button :
|
179
|
+
<%= f.labeled(:female) do %>
|
180
|
+
<%= f.radio_button :female, true %> female
|
181
|
+
<%= f.radio_button :female, false %> male
|
181
182
|
<% end %>
|
182
183
|
<%= f.labeled_integer_field :age %>
|
183
184
|
<%= f.labeled_file_field :picture %>
|
@@ -193,7 +194,7 @@ Optionally, +has_and_belongs_to_many+ and +has_many+ associations can be rendere
|
|
193
194
|
|
194
195
|
And yes again, the same advice for where to put finder logic applies here as well.
|
195
196
|
|
196
|
-
<b>Note:</b> +has_and_belongs_to_many+ and +has_many+ associations are not automatically rendered in a form, you have to explicitly include these attributes. You might also want to stylize the multi-select widget
|
197
|
+
<b>Note:</b> +has_and_belongs_to_many+ and +has_many+ associations are not automatically rendered in a form, you have to explicitly include these attributes. You might also want to stylize the multi-select widget with a JavaScript library of your choice.
|
197
198
|
|
198
199
|
|
199
200
|
=== Nested Resources
|
@@ -221,8 +222,8 @@ In <tt>app/controllers/people_controller.rb</tt>:
|
|
221
222
|
|
222
223
|
def delete_picture
|
223
224
|
if !perform_delete_picture(entry.picture)
|
224
|
-
flash
|
225
|
-
|
225
|
+
flash[:alert] = 'Could not delete picture'
|
226
|
+
throw :abort
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
@@ -269,49 +270,49 @@ All generated files are supposed to provide a reasonable foundation for the CRUD
|
|
269
270
|
|
270
271
|
=== Controller
|
271
272
|
|
272
|
-
{controller/crud_controller.rb}[
|
273
|
+
{controller/crud_controller.rb}[https://rubydoc.info/github/codez/dry_crud/master/CrudController]:: Abstract controller providing basic CRUD actions. This implementation mainly follows the one of the Rails scaffolding controller and responses to HTML and JSON requests. Some enhancements were made to ease extendability. Several protected helper methods are there to be (optionally) overriden by subclasses. With the help of additional callbacks, it is possible to hook into the action procedures without overriding the entire method. This class is based on ListController.
|
273
274
|
|
274
|
-
{controller/list_controller.rb}[
|
275
|
+
{controller/list_controller.rb}[https://rubydoc.info/github/codez/dry_crud/master/ListController]:: Abstract controller providing a basic list action. Use this controller if you require read-only functionality. It includes the following modules.
|
275
276
|
|
276
|
-
{controller/dry_crud/generic_model.rb}[
|
277
|
+
{controller/dry_crud/generic_model.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/GenericModel]:: Work with the model whose name corrsponds to the controller's name.
|
277
278
|
|
278
|
-
{controller/dry_crud/nestable.rb}[
|
279
|
+
{controller/dry_crud/nestable.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Nestable]:: Provides functionality to easily nest controllers/resources.
|
279
280
|
|
280
|
-
{controller/dry_crud/rememberable.rb}[
|
281
|
+
{controller/dry_crud/rememberable.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Rememberable]:: Remembers certain params of the index action in order to return to the same list after an entry was viewed or edited.
|
281
282
|
|
282
|
-
{controller/dry_crud/searchable.rb}[
|
283
|
+
{controller/dry_crud/searchable.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Searchable]:: Search functionality for the index table.
|
283
284
|
|
284
|
-
{controller/dry_crud/sortable.rb}[
|
285
|
+
{controller/dry_crud/sortable.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Sortable]:: Sort functionality for the index table.
|
285
286
|
|
286
|
-
{controller/dry_crud/render_callbacks.rb}[
|
287
|
+
{controller/dry_crud/render_callbacks.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/RenderCallbacks]:: Provide +before_render+ callbacks to controllers.
|
287
288
|
|
288
|
-
{controller/dry_crud/responder.rb}[
|
289
|
+
{controller/dry_crud/responder.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Responder]:: Responder used by the CrudController to handle the +path_args+.
|
289
290
|
|
290
291
|
=== Helpers
|
291
292
|
|
292
|
-
{helpers/dry_crud/form/builder.rb}[
|
293
|
+
{helpers/dry_crud/form/builder.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Form/Builder]:: A form builder that automatically selects the corresponding input type for ActiveRecord columns. Input elements are rendered together with a label by default.
|
293
294
|
|
294
|
-
{helpers/dry_crud/form/control.rb}[
|
295
|
+
{helpers/dry_crud/form/control.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Form/Control]:: Representation of a single form control consisting of a label, input field, addon or help text.
|
295
296
|
|
296
|
-
{helpers/dry_crud/table/builder.rb}[
|
297
|
+
{helpers/dry_crud/table/builder.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Table/Builder]:: A helper object to easily define tables listing several rows of the same data type.
|
297
298
|
|
298
|
-
{helpers/dry_crud/table/col.rb}[
|
299
|
+
{helpers/dry_crud/table/col.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Table/Col]:: Helper class representing a single table column.
|
299
300
|
|
300
|
-
{helpers/dry_crud/table/actions.rb}[
|
301
|
+
{helpers/dry_crud/table/actions.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Table/Actions]:: Module to add support for uniform CRUD actions in tables.
|
301
302
|
|
302
|
-
{helpers/dry_crud/table/sorting.rb}[
|
303
|
+
{helpers/dry_crud/table/sorting.rb}[https://rubydoc.info/github/codez/dry_crud/master/DryCrud/Table/Sorting]:: Module to add support for sort links in table headers.
|
303
304
|
|
304
|
-
{helpers/form_helper.rb}[
|
305
|
+
{helpers/form_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/FormHelper]:: Create forms to edit models with Crud::FormBuilder. Contains a standardized and a custom definable form.
|
305
306
|
|
306
|
-
{helpers/table_helper.rb}[
|
307
|
+
{helpers/table_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/TableHelper]:: Create tables to list multiple models with Crud::TableBuilder. Contains a standardized and a custom definable table.
|
307
308
|
|
308
|
-
{helpers/format_helper.rb}[
|
309
|
+
{helpers/format_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/FormatHelper]:: Format attribute and basic values according to their database or Ruby type.
|
309
310
|
|
310
|
-
{helpers/actions_helper.rb}[
|
311
|
+
{helpers/actions_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/ActionsHelper]:: Uniform action links for the most common crud actions.
|
311
312
|
|
312
|
-
{helpers/i18n_helper.rb}[
|
313
|
+
{helpers/i18n_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/I18nHelper]:: Translation helpers extending Rails' +translate+ helper to support translation inheritance over the controller class hierarchy.
|
313
314
|
|
314
|
-
{helpers/utility_helper.rb}[
|
315
|
+
{helpers/utility_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/UtilityHelper]:: View helpers for basic functions used in various other helpers.
|
315
316
|
|
316
317
|
|
317
318
|
|
@@ -372,9 +373,9 @@ app/assets/images/action/*.png:: Some sample action icons from the {Open Icon Li
|
|
372
373
|
|
373
374
|
test/support/crud_test_model.rb:: A dummy model to run CRUD tests against.
|
374
375
|
|
375
|
-
{test/support/custom_assertions.rb}[
|
376
|
+
{test/support/custom_assertions.rb}[https://rubydoc.info/github/codez/dry_crud/master/CustomAssertions]:: A handful of convenient assertions. Include this module into your <tt>test_helper.rb</tt> file.
|
376
377
|
|
377
|
-
{test/support/crud_controller_test_helper.rb}[
|
378
|
+
{test/support/crud_controller_test_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/CrudControllerTestHelper]:: A module to include into the functional tests for your CrudController subclasses. Contains a handful of CRUD functionality tests for the provided implementation. So for each new CRUD controller, you get 20 tests for free.
|
378
379
|
|
379
380
|
test/controllers/crud_test_models_controller_test.rb:: Functional tests for the basic CrudController functionality.
|
380
381
|
|
@@ -385,7 +386,7 @@ test/helpers/*_test.rb:: Tests for the provided helper implementations and a gre
|
|
385
386
|
|
386
387
|
spec/support/crud_controller_examples.rb:: A whole set of shared exampled to include into your controller specs. See <tt>spec/controllers/crud_test_models_controller_spec.rb</tt> for usage. So for each new CRUD controller, you get all the basic specs for free.
|
387
388
|
|
388
|
-
{spec/support/crud_controller_test_helper.rb}[
|
389
|
+
{spec/support/crud_controller_test_helper.rb}[https://rubydoc.info/github/codez/dry_crud/master/CrudControllerTestHelper/ClassMethods]:: Convenience methods used by the crud controller examples.
|
389
390
|
|
390
391
|
spec/support/crud_test_model.rb:: A dummy model to run CRUD tests against.
|
391
392
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
7.1.0
|
@@ -1,8 +1,12 @@
|
|
1
1
|
$container_width: 1000px;
|
2
2
|
$theme_color: #2580a2;
|
3
3
|
|
4
|
-
body,
|
5
|
-
|
4
|
+
body,
|
5
|
+
div,
|
6
|
+
p,
|
7
|
+
td,
|
8
|
+
th {
|
9
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
6
10
|
font-size: 14px;
|
7
11
|
line-height: 1.42857;
|
8
12
|
}
|
@@ -101,7 +105,8 @@ table.table {
|
|
101
105
|
}
|
102
106
|
|
103
107
|
/* div rendered if no entries available for list */
|
104
|
-
div.table {
|
108
|
+
div.table {
|
109
|
+
}
|
105
110
|
|
106
111
|
table.table th {
|
107
112
|
background-color: $theme_color;
|
@@ -119,20 +124,21 @@ table.table td {
|
|
119
124
|
padding: 4px 4px;
|
120
125
|
}
|
121
126
|
|
122
|
-
.table-striped thead tr:nth-child(odd),
|
123
|
-
|
127
|
+
.table-striped thead tr:nth-child(odd),
|
128
|
+
.table thead tr:nth-child(even) {
|
129
|
+
background-color: #d0d0d0;
|
124
130
|
}
|
125
131
|
|
126
132
|
.table-striped tr:nth-child(odd) {
|
127
|
-
background-color: #
|
133
|
+
background-color: #f8f8f8;
|
128
134
|
}
|
129
135
|
|
130
136
|
.table-striped tr:nth-child(even) {
|
131
|
-
background-color: #
|
137
|
+
background-color: #f0f0f0;
|
132
138
|
}
|
133
139
|
|
134
140
|
.table-hover tr:hover {
|
135
|
-
background-color: #
|
141
|
+
background-color: #ffffe0;
|
136
142
|
}
|
137
143
|
|
138
144
|
td {
|
@@ -153,7 +159,7 @@ a:hover {
|
|
153
159
|
}
|
154
160
|
|
155
161
|
a:visited {
|
156
|
-
color:
|
162
|
+
color: #2580a2;
|
157
163
|
}
|
158
164
|
|
159
165
|
a img {
|
@@ -213,11 +219,21 @@ a.icon img {
|
|
213
219
|
vertical-align: top;
|
214
220
|
}
|
215
221
|
|
216
|
-
.icon-plus {
|
217
|
-
|
218
|
-
|
219
|
-
.icon-
|
220
|
-
|
222
|
+
.icon-plus {
|
223
|
+
background-image: image-url("actions/add.png");
|
224
|
+
}
|
225
|
+
.icon-trash {
|
226
|
+
background-image: image-url("actions/delete.png");
|
227
|
+
}
|
228
|
+
.icon-pencil {
|
229
|
+
background-image: image-url("actions/edit.png");
|
230
|
+
}
|
231
|
+
.icon-list {
|
232
|
+
background-image: image-url("actions/list.png");
|
233
|
+
}
|
234
|
+
.icon-zoom-in {
|
235
|
+
background-image: image-url("actions/show.png");
|
236
|
+
}
|
221
237
|
|
222
238
|
.form-group {
|
223
239
|
clear: both;
|
@@ -231,34 +247,39 @@ a.icon img {
|
|
231
247
|
padding-top: 3px;
|
232
248
|
}
|
233
249
|
|
234
|
-
input,
|
250
|
+
input,
|
251
|
+
textarea,
|
252
|
+
select {
|
235
253
|
font-family: Verdana, Geneva, Helvetica, Arial, sans-serif;
|
236
254
|
font-size: 14px;
|
237
255
|
}
|
238
256
|
|
239
|
-
input[type=text],
|
257
|
+
input[type="text"],
|
258
|
+
input[type="password"],
|
259
|
+
input[type="email"] {
|
240
260
|
width: 300px;
|
241
261
|
}
|
242
262
|
|
243
|
-
input[type=number] {
|
263
|
+
input[type="number"] {
|
244
264
|
width: 100px;
|
245
265
|
}
|
246
266
|
|
247
|
-
textarea,
|
267
|
+
textarea,
|
268
|
+
select[multiple] {
|
248
269
|
width: 300px;
|
249
270
|
height: 80px;
|
250
271
|
}
|
251
272
|
|
252
|
-
[role=search] [type=search] {
|
273
|
+
[role="search"] [type="search"] {
|
253
274
|
width: 220px;
|
254
275
|
}
|
255
276
|
|
256
277
|
.has-error .control-label {
|
257
|
-
color: #
|
278
|
+
color: #d88;
|
258
279
|
}
|
259
280
|
|
260
281
|
.has-error .form-control {
|
261
|
-
border-color: #
|
282
|
+
border-color: #d88;
|
262
283
|
}
|
263
284
|
|
264
285
|
.input-group-append {
|
@@ -284,7 +305,7 @@ textarea, select[multiple] {
|
|
284
305
|
}
|
285
306
|
|
286
307
|
.alert-danger {
|
287
|
-
border: solid 2px #
|
308
|
+
border: solid 2px #d88;
|
288
309
|
background-color: #fec;
|
289
310
|
}
|
290
311
|
|
@@ -292,11 +313,11 @@ textarea, select[multiple] {
|
|
292
313
|
float: right;
|
293
314
|
}
|
294
315
|
|
295
|
-
.float-
|
316
|
+
.float-end {
|
296
317
|
float: right;
|
297
318
|
}
|
298
319
|
|
299
|
-
.float-
|
320
|
+
.float-start {
|
300
321
|
float: left;
|
301
322
|
}
|
302
323
|
|
@@ -40,6 +40,11 @@ class CrudController < ListController
|
|
40
40
|
assign_attributes if params[model_identifier]
|
41
41
|
end
|
42
42
|
|
43
|
+
# GET /entries/1/edit
|
44
|
+
#
|
45
|
+
# Display a form to edit an exisiting entry of this model.
|
46
|
+
def edit; end
|
47
|
+
|
43
48
|
# POST /entries
|
44
49
|
# POST /entries.json
|
45
50
|
#
|
@@ -52,22 +57,17 @@ class CrudController < ListController
|
|
52
57
|
# in the given block will take precedence over the one defined here.
|
53
58
|
#
|
54
59
|
# Specify a :location option if you wish to do a custom redirect.
|
55
|
-
def create(options
|
60
|
+
def create(**options, &block)
|
56
61
|
model_class.transaction do
|
57
62
|
assign_attributes
|
58
63
|
created = with_callbacks(:create, :save) { entry.save }
|
59
64
|
respond(created,
|
60
|
-
options.merge(status: :created, render_on_failure: :new),
|
65
|
+
**options.merge(status: :created, render_on_failure: :new),
|
61
66
|
&block)
|
62
67
|
raise ActiveRecord::Rollback unless created
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
66
|
-
# GET /entries/1/edit
|
67
|
-
#
|
68
|
-
# Display a form to edit an exisiting entry of this model.
|
69
|
-
def edit; end
|
70
|
-
|
71
71
|
# PUT /entries/1
|
72
72
|
# PUT /entries/1.json
|
73
73
|
#
|
@@ -80,12 +80,12 @@ class CrudController < ListController
|
|
80
80
|
# in the given block will take precedence over the one defined here.
|
81
81
|
#
|
82
82
|
# Specify a :location option if you wish to do a custom redirect.
|
83
|
-
def update(options
|
83
|
+
def update(**options, &block)
|
84
84
|
model_class.transaction do
|
85
85
|
assign_attributes
|
86
86
|
updated = with_callbacks(:update, :save) { entry.save }
|
87
87
|
respond(updated,
|
88
|
-
options.merge(status: :ok, render_on_failure: :edit),
|
88
|
+
**options.merge(status: :ok, render_on_failure: :edit),
|
89
89
|
&block)
|
90
90
|
raise ActiveRecord::Rollback unless updated
|
91
91
|
end
|
@@ -103,11 +103,11 @@ class CrudController < ListController
|
|
103
103
|
# in the given block will take precedence over the one defined here.
|
104
104
|
#
|
105
105
|
# Specify a :location option if you wish to do a custom redirect.
|
106
|
-
def destroy(options
|
106
|
+
def destroy(**options, &block)
|
107
107
|
model_class.transaction do
|
108
108
|
destroyed = run_callbacks(:destroy) { entry.destroy }
|
109
109
|
respond(destroyed,
|
110
|
-
options.merge(status: :no_content),
|
110
|
+
**options.merge(status: :no_content),
|
111
111
|
&block)
|
112
112
|
raise ActiveRecord::Rollback unless destroyed
|
113
113
|
end
|
@@ -152,14 +152,14 @@ class CrudController < ListController
|
|
152
152
|
path_args(entry)
|
153
153
|
end
|
154
154
|
|
155
|
-
def respond(success, options)
|
155
|
+
def respond(success, **options)
|
156
156
|
respond_to do |format|
|
157
157
|
yield(format, success) if block_given?
|
158
158
|
if success
|
159
|
-
format.html { redirect_on_success(options) }
|
159
|
+
format.html { redirect_on_success(**options) }
|
160
160
|
format.json { render_success_json(options[:status]) }
|
161
161
|
else
|
162
|
-
format.html { render_or_redirect_on_failure(options) }
|
162
|
+
format.html { render_or_redirect_on_failure(**options) }
|
163
163
|
format.json { render_failure_json }
|
164
164
|
end
|
165
165
|
end
|
@@ -167,16 +167,16 @@ class CrudController < ListController
|
|
167
167
|
|
168
168
|
# If the option :render_on_failure is given, render the corresponding
|
169
169
|
# template, otherwise redirect.
|
170
|
-
def render_or_redirect_on_failure(options)
|
170
|
+
def render_or_redirect_on_failure(**options)
|
171
171
|
if options[:render_on_failure]
|
172
172
|
render options[:render_on_failure]
|
173
173
|
else
|
174
|
-
redirect_on_failure(options)
|
174
|
+
redirect_on_failure(**options)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
# Perform a redirect after a successfull operation and set a flash notice.
|
179
|
-
def redirect_on_success(options
|
179
|
+
def redirect_on_success(**options)
|
180
180
|
location = options[:location] ||
|
181
181
|
(entry.destroyed? ? index_path : show_path)
|
182
182
|
flash[:notice] ||= flash_message(:success)
|
@@ -184,7 +184,7 @@ class CrudController < ListController
|
|
184
184
|
end
|
185
185
|
|
186
186
|
# Perform a redirect after a failed operation and set a flash alert.
|
187
|
-
def redirect_on_failure(options
|
187
|
+
def redirect_on_failure(**options)
|
188
188
|
location = options[:location] ||
|
189
189
|
request.env['HTTP_REFERER'].presence ||
|
190
190
|
index_path
|
@@ -221,7 +221,7 @@ class CrudController < ListController
|
|
221
221
|
# A label for the current entry, including the model name.
|
222
222
|
def full_entry_label
|
223
223
|
# rubocop:disable Rails/OutputSafety
|
224
|
-
"#{models_label(false)} <i>#{ERB::Util.h(entry)}</i>".html_safe
|
224
|
+
"#{models_label(plural: false)} <i>#{ERB::Util.h(entry)}</i>".html_safe
|
225
225
|
# rubocop:enable Rails/OutputSafety
|
226
226
|
end
|
227
227
|
|
@@ -13,8 +13,6 @@ module DryCrud
|
|
13
13
|
included do
|
14
14
|
helper_method :model_class, :models_label, :path_args
|
15
15
|
|
16
|
-
private
|
17
|
-
|
18
16
|
delegate :model_class, :models_label, :model_identifier, to: 'self.class'
|
19
17
|
end
|
20
18
|
|
@@ -33,7 +31,7 @@ module DryCrud
|
|
33
31
|
|
34
32
|
# Get the instance variable named after the +model_class+.
|
35
33
|
# If the collection variable is required, pass true as the second argument.
|
36
|
-
def model_ivar_get(plural
|
34
|
+
def model_ivar_get(plural: false)
|
37
35
|
name = ivar_name(model_class)
|
38
36
|
name = name.pluralize if plural
|
39
37
|
name = :"@#{name}"
|
@@ -72,7 +70,7 @@ module DryCrud
|
|
72
70
|
end
|
73
71
|
|
74
72
|
# A human readable plural name of the model.
|
75
|
-
def models_label(plural
|
73
|
+
def models_label(plural: true)
|
76
74
|
opts = { count: (plural ? 3 : 1) }
|
77
75
|
opts[:default] = model_class.model_name.human.titleize
|
78
76
|
opts[:default] = opts[:default].pluralize if plural
|
@@ -15,13 +15,13 @@ module DryCrud
|
|
15
15
|
|
16
16
|
# Helper method to run +before_render+ callbacks and render the action.
|
17
17
|
# If a callback renders or redirects, the action is not rendered.
|
18
|
-
def render(
|
19
|
-
options = _normalize_render(
|
18
|
+
def render(...)
|
19
|
+
options = _normalize_render(...)
|
20
20
|
callback = "render_#{options[:template]}"
|
21
21
|
|
22
22
|
run_callbacks(callback) if respond_to?(:"_#{callback}_callbacks", true)
|
23
23
|
|
24
|
-
super(
|
24
|
+
super(...) unless performed?
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -32,7 +32,7 @@ class ListController < ApplicationController
|
|
32
32
|
# Helper method to access the entries to be displayed in the current index
|
33
33
|
# page in an uniform way.
|
34
34
|
def entries
|
35
|
-
model_ivar_get(true) || model_ivar_set(list_entries)
|
35
|
+
model_ivar_get(plural: true) || model_ivar_set(list_entries)
|
36
36
|
end
|
37
37
|
|
38
38
|
# The base relation used to filter the entries.
|