dry_crud 5.0.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +2 -2
  3. data/VERSION +1 -1
  4. data/app/assets/stylesheets/sample.scss +8 -11
  5. data/app/controllers/crud_controller.rb +63 -45
  6. data/app/controllers/dry_crud/generic_model.rb +0 -2
  7. data/app/controllers/dry_crud/nestable.rb +0 -2
  8. data/app/controllers/dry_crud/rememberable.rb +1 -3
  9. data/app/controllers/dry_crud/render_callbacks.rb +0 -2
  10. data/app/controllers/dry_crud/searchable.rb +0 -2
  11. data/app/controllers/dry_crud/sortable.rb +1 -3
  12. data/app/controllers/list_controller.rb +0 -2
  13. data/app/helpers/actions_helper.rb +1 -3
  14. data/app/helpers/dry_crud/form/builder.rb +7 -8
  15. data/app/helpers/dry_crud/form/control.rb +3 -5
  16. data/app/helpers/dry_crud/table/actions.rb +10 -12
  17. data/app/helpers/dry_crud/table/builder.rb +4 -6
  18. data/app/helpers/dry_crud/table/col.rb +0 -2
  19. data/app/helpers/dry_crud/table/sorting.rb +4 -6
  20. data/app/helpers/form_helper.rb +1 -3
  21. data/app/helpers/format_helper.rb +4 -5
  22. data/app/helpers/i18n_helper.rb +0 -2
  23. data/app/helpers/table_helper.rb +0 -2
  24. data/app/helpers/utility_helper.rb +1 -2
  25. data/app/views/layouts/_nav.html.erb +4 -4
  26. data/app/views/layouts/_nav.html.haml +4 -4
  27. data/app/views/layouts/application.html.erb +3 -23
  28. data/app/views/layouts/application.html.haml +3 -21
  29. data/app/views/list/_search.html.erb +4 -4
  30. data/app/views/list/_search.html.haml +2 -2
  31. data/config/locales/crud.it.yml +64 -0
  32. data/lib/dry_crud.rb +1 -0
  33. data/lib/dry_crud/engine.rb +9 -3
  34. data/lib/generators/dry_crud/dry_crud_generator.rb +3 -5
  35. data/lib/generators/dry_crud/dry_crud_generator_base.rb +5 -4
  36. data/lib/generators/dry_crud/file_generator.rb +11 -5
  37. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +48 -23
  38. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +6 -8
  39. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +1 -2
  40. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +0 -1
  41. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +23 -7
  42. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +43 -11
  43. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +8 -6
  44. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +8 -8
  45. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +32 -35
  46. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +1 -3
  47. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +38 -17
  48. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +0 -1
  49. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +6 -6
  50. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +1 -2
  51. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +1 -2
  52. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +13 -3
  53. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +28 -11
  54. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +5 -5
  55. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +11 -18
  56. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +5 -7
  57. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +17 -16
  58. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +4 -4
  59. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +11 -6
  60. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +1 -3
  61. metadata +14 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cd475eb483f54acdff9dff23ae75d80715edfcdb
4
- data.tar.gz: 7ba54fb2d5a22f562627fd0641f23e2a32a975ee
2
+ SHA256:
3
+ metadata.gz: 3fa4767cf781b94a5ed47a5833f76a96494c450967e9f3599806226aafcf4a74
4
+ data.tar.gz: bd4c40f8493eef40c6618ead701877f8ec8d39b552db5787ae184273be0fc8d3
5
5
  SHA512:
6
- metadata.gz: 38e784965cdb8dc622b659437fa6cb2e4be27eb3eb17b3c1686a5ec6cdfded184fb08fb10a533ff6d7f9e14331045b111aadbde8a371d6c59272462c589839e6
7
- data.tar.gz: e0b78f3534243dd715cb53c6ddbfc547f236e90e84ee6a7439e392a4d0b837f17fd2a7e9e5a24fb1b885611aaf44f7c2dca47ac388256279559cd5b212e24699
6
+ metadata.gz: 8fef4d2ed06521eafd92c4fa87a36d07fdeee79a1a0f0d3a0e6098e2ac98b6c92d7c5cd2e87046b4cf37a3fa2e90f2d1cda382d645e828b3aeba2b5cd26e0903
7
+ data.tar.gz: 41b31166a4f5c82374587e49fe76580d32487ccff0fa52b6f0e72f131b2eb9a7d296d6ff53d8cc3de470fe1671dbdfb2749a4bdba685ce2bf110ea163abea225
@@ -70,7 +70,7 @@ Say you want to manage a +Person+ model. Overwrite the +to_s+ method of your mod
70
70
  end
71
71
  end
72
72
 
73
- Then create the following controller. The +permitted_attrs+ define the attribute parameters allowed when creating or updating a model entry (see {Strong Paramters}[http://api.rubyonrails.org/classes/ActionController/StrongParameters.html]).
73
+ Then create the following controller. The +permitted_attrs+ define the attribute parameters allowed when creating or updating a model entry (see {Strong Parameters}[http://api.rubyonrails.org/classes/ActionController/StrongParameters.html]).
74
74
 
75
75
  <tt>app/controllers/people_controller.rb</tt>:
76
76
  class PeopleController < CrudController
@@ -86,7 +86,7 @@ Well, maybe there are certain attributes you do not want to display in the peopl
86
86
 
87
87
  <%= crud_table :lastname, :firstname, :city, :sex %>
88
88
 
89
- This only displays these three attributes in the table. All other templates, as well as the main index view, fallback to the ones in <tt>app/views/crud</tt>.
89
+ 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
90
 
91
91
 
92
92
  ==== Adapt general behavior
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.0
1
+ 5.2.0
@@ -51,20 +51,20 @@ a.navbar-brand:hover {
51
51
  color: #ddd;
52
52
  }
53
53
 
54
- .nav {
54
+ .navbar-nav {
55
55
  list-style: none;
56
56
  margin: 0;
57
57
  float: left;
58
58
  }
59
59
 
60
- .nav li {
60
+ .navbar-nav li.nav-item {
61
61
  float: left;
62
62
  font-size: 110%;
63
63
  margin: 0;
64
64
  padding: 0;
65
65
  }
66
66
 
67
- .nav a {
67
+ .navbar-nav a.nav-link {
68
68
  color: #ddd !important;
69
69
  display: block;
70
70
  float: left;
@@ -74,7 +74,7 @@ a.navbar-brand:hover {
74
74
  height: 19px;
75
75
  }
76
76
 
77
- .nav a:hover {
77
+ .navbar-nav a.nav-link:hover {
78
78
  background: $theme_color bottom center no-repeat;
79
79
  color: #fff !important;
80
80
  text-decoration: none;
@@ -261,10 +261,11 @@ textarea, select[multiple] {
261
261
  border-color: #D88;
262
262
  }
263
263
 
264
- .input-group-addon {
264
+ .input-group-append {
265
265
  font-size: 80%;
266
266
  vertical-align: top;
267
267
  margin-left: 4px;
268
+ display: inline-block;
268
269
  }
269
270
 
270
271
  .help-block {
@@ -291,11 +292,11 @@ textarea, select[multiple] {
291
292
  float: right;
292
293
  }
293
294
 
294
- .pull-right {
295
+ .float-right {
295
296
  float: right;
296
297
  }
297
298
 
298
- .pull-left {
299
+ .float-left {
299
300
  float: left;
300
301
  }
301
302
 
@@ -306,10 +307,6 @@ footer {
306
307
  min-width: $container_width - 200px;
307
308
  }
308
309
 
309
- footer * {
310
- font-size: 80%;
311
- }
312
-
313
310
  .col-md-offset-2 {
314
311
  margin-left: 130px;
315
312
  }
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  # Abstract controller providing basic CRUD actions.
4
2
  #
5
3
  # Some enhancements were made to ease extensibility.
@@ -22,7 +20,7 @@ class CrudController < ListController
22
20
  # further down.
23
21
  define_render_callbacks :show, :new, :edit
24
22
 
25
- before_action :entry, only: [:show, :new, :edit, :update, :destroy]
23
+ before_action :entry, only: %i[show new edit update destroy]
26
24
 
27
25
  helper_method :entry, :full_entry_label
28
26
 
@@ -32,8 +30,7 @@ class CrudController < ListController
32
30
  # GET /entries/1.json
33
31
  #
34
32
  # Show one entry of this model.
35
- def show
36
- end
33
+ def show; end
37
34
 
38
35
  # GET /entries/new
39
36
  # GET /entries/new.json
@@ -55,27 +52,21 @@ class CrudController < ListController
55
52
  # in the given block will take precedence over the one defined here.
56
53
  #
57
54
  # Specify a :location option if you wish to do a custom redirect.
58
- def create(options = {}, &_block)
59
- assign_attributes
60
- created = with_callbacks(:create, :save) { entry.save }
61
-
62
- respond_to do |format|
63
- yield(format, created) if block_given?
64
- if created
65
- format.html { redirect_on_success(options) }
66
- format.json { render :show, status: :created, location: show_path }
67
- else
68
- format.html { render :new }
69
- format.json { render json: entry.errors, status: :unprocessable_entity }
70
- end
55
+ def create(options = {}, &block)
56
+ model_class.transaction do
57
+ assign_attributes
58
+ created = with_callbacks(:create, :save) { entry.save }
59
+ respond(created,
60
+ options.merge(status: :created, render_on_failure: :new),
61
+ &block)
62
+ raise ActiveRecord::Rollback unless created
71
63
  end
72
64
  end
73
65
 
74
66
  # GET /entries/1/edit
75
67
  #
76
68
  # Display a form to edit an exisiting entry of this model.
77
- def edit
78
- end
69
+ def edit; end
79
70
 
80
71
  # PUT /entries/1
81
72
  # PUT /entries/1.json
@@ -89,19 +80,14 @@ class CrudController < ListController
89
80
  # in the given block will take precedence over the one defined here.
90
81
  #
91
82
  # Specify a :location option if you wish to do a custom redirect.
92
- def update(options = {}, &_block)
93
- assign_attributes
94
- updated = with_callbacks(:update, :save) { entry.save }
95
-
96
- respond_to do |format|
97
- yield(format, updated) if block_given?
98
- if updated
99
- format.html { redirect_on_success(options) }
100
- format.json { render :show, status: :ok, location: show_path }
101
- else
102
- format.html { render :edit }
103
- format.json { render json: entry.errors, status: :unprocessable_entity }
104
- end
83
+ def update(options = {}, &block)
84
+ model_class.transaction do
85
+ assign_attributes
86
+ updated = with_callbacks(:update, :save) { entry.save }
87
+ respond(updated,
88
+ options.merge(status: :ok, render_on_failure: :edit),
89
+ &block)
90
+ raise ActiveRecord::Rollback unless updated
105
91
  end
106
92
  end
107
93
 
@@ -117,18 +103,13 @@ class CrudController < ListController
117
103
  # in the given block will take precedence over the one defined here.
118
104
  #
119
105
  # Specify a :location option if you wish to do a custom redirect.
120
- def destroy(options = {}, &_block)
121
- destroyed = run_callbacks(:destroy) { entry.destroy }
122
-
123
- respond_to do |format|
124
- yield(format, destroyed) if block_given?
125
- if destroyed
126
- format.html { redirect_on_success(options) }
127
- format.json { head :no_content }
128
- else
129
- format.html { redirect_on_failure(options) }
130
- format.json { render json: entry.errors, status: :unprocessable_entity }
131
- end
106
+ def destroy(options = {}, &block)
107
+ model_class.transaction do
108
+ destroyed = run_callbacks(:destroy) { entry.destroy }
109
+ respond(destroyed,
110
+ options.merge(status: :no_content),
111
+ &block)
112
+ raise ActiveRecord::Rollback unless destroyed
132
113
  end
133
114
  end
134
115
 
@@ -171,6 +152,29 @@ class CrudController < ListController
171
152
  path_args(entry)
172
153
  end
173
154
 
155
+ def respond(success, options)
156
+ respond_to do |format|
157
+ yield(format, success) if block_given?
158
+ if success
159
+ format.html { redirect_on_success(options) }
160
+ format.json { render_success_json(options[:status]) }
161
+ else
162
+ format.html { render_or_redirect_on_failure(options) }
163
+ format.json { render_failure_json }
164
+ end
165
+ end
166
+ end
167
+
168
+ # If the option :render_on_failure is given, render the corresponding
169
+ # template, otherwise redirect.
170
+ def render_or_redirect_on_failure(options)
171
+ if options[:render_on_failure]
172
+ render options[:render_on_failure]
173
+ else
174
+ redirect_on_failure(options)
175
+ end
176
+ end
177
+
174
178
  # Perform a redirect after a successfull operation and set a flash notice.
175
179
  def redirect_on_success(options = {})
176
180
  location = options[:location] ||
@@ -188,6 +192,20 @@ class CrudController < ListController
188
192
  redirect_to location
189
193
  end
190
194
 
195
+ # Render the show json with the given status or :no_content
196
+ def render_success_json(status)
197
+ if status == :no_content
198
+ head :no_content
199
+ else
200
+ render :show, status: status, location: show_path
201
+ end
202
+ end
203
+
204
+ # Render a json with the errors.
205
+ def render_failure_json
206
+ render json: entry.errors, status: :unprocessable_entity
207
+ end
208
+
191
209
  # Get an I18n flash message.
192
210
  # Uses the key {controller_name}.{action_name}.flash.{state}
193
211
  # or crud.{action_name}.flash.{state} as fallback.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # Connects the including controller to the model whose name corrsponds to
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # Provides functionality to nest controllers/resources.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # Remembers certain params of the index action in order to return
@@ -18,7 +16,7 @@ module DryCrud
18
16
 
19
17
  included do
20
18
  class_attribute :remember_params
21
- self.remember_params = %w(q sort sort_dir page)
19
+ self.remember_params = %w[q sort sort_dir page]
22
20
 
23
21
  before_action :handle_remember_params, only: [:index]
24
22
  end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # Provide +before_render+ callbacks.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # The search functionality for the index table.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
 
5
3
  # Sort functionality for the index table.
@@ -44,7 +42,7 @@ module DryCrud
44
42
  sortable = sortable?(params[:sort])
45
43
  if sortable || default_sort
46
44
  clause = [sortable ? sort_expression : nil, default_sort]
47
- super.reorder(clause.compact.join(', '))
45
+ super.reorder(Arel.sql(clause.compact.join(', ')))
48
46
  else
49
47
  super
50
48
  end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  # Abstract controller providing a basic list action.
4
2
  # The loaded model entries are available in the view as an instance variable
5
3
  # named after the +model_class+ or by the helper method +entries+.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  # Helpers to create action links. This default implementation supports
4
2
  # regular links with an icon and a label. To change the general style
5
3
  # of action links, change the method #action_link, e.g. to generate a button.
@@ -9,7 +7,7 @@ module ActionsHelper
9
7
  # A generic helper method to create action links.
10
8
  # These link could be styled to look like buttons, for example.
11
9
  def action_link(label, icon = nil, url = {}, html_options = {})
12
- add_css_class html_options, 'action btn btn-default'
10
+ add_css_class html_options, 'action btn btn-light'
13
11
  link_to(icon ? action_icon(icon, label) : label,
14
12
  url, html_options)
15
13
  end
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
  module Form
5
3
 
@@ -84,8 +82,8 @@ module DryCrud
84
82
  end
85
83
 
86
84
  # Add form-control class to all input fields.
87
- %w(text_field password_field email_field text_area
88
- number_field date_field time_field datetime_field).each do |method|
85
+ %w[text_field password_field email_field
86
+ number_field date_field time_field datetime_field].each do |method|
89
87
  define_method(method) do |attr, html_options = {}|
90
88
  add_css_class(html_options, 'form-control')
91
89
  super(attr, html_options)
@@ -150,7 +148,8 @@ module DryCrud
150
148
  # Renders the given content with an addon.
151
149
  def with_addon(content, addon)
152
150
  content_tag(:div, class: 'input-group') do
153
- content + content_tag(:span, addon, class: 'input-group-addon')
151
+ html = content_tag(:span, addon, class: 'input-group-text')
152
+ content + content_tag(:div, html, class: 'input-group-append')
154
153
  end
155
154
  end
156
155
 
@@ -244,13 +243,13 @@ module DryCrud
244
243
  if field_method
245
244
  build_labeled_field(field_method, *args)
246
245
  else
247
- super(name, *args)
246
+ super
248
247
  end
249
248
  end
250
249
 
251
250
  # Overriden to fullfill contract with method_missing 'labeled_' methods.
252
- def respond_to?(name, include_private = false)
253
- labeled_field_method?(name).present? || super(name, include_private)
251
+ def respond_to_missing?(name, include_private = false)
252
+ labeled_field_method?(name).present? || super
254
253
  end
255
254
 
256
255
  private
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
  module Form
5
3
 
@@ -8,7 +6,7 @@ module DryCrud
8
6
  # required mark.
9
7
  class Control
10
8
 
11
- attr_reader :builder, :attr, :args, :options, :span, :addon, :help
9
+ attr_reader :builder, :attr, :args, :options, :addon, :help
12
10
 
13
11
  delegate :content_tag, :object,
14
12
  to: :builder
@@ -32,8 +30,8 @@ module DryCrud
32
30
  # This includes an options hash as the last argument, that
33
31
  # may contain the following special options:
34
32
  #
35
- # * <tt>:addon</tt> - Addon content displayd just after the input field.
36
- # * <tt>:help</tt> - A help text displayd below the input field.
33
+ # * <tt>:addon</tt> - Addon content displayed just after the input field.
34
+ # * <tt>:help</tt> - A help text displayed below the input field.
37
35
  # * <tt>:span</tt> - Number of columns the input field should span.
38
36
  # * <tt>:caption</tt> - Different caption for the label.
39
37
  # * <tt>:field_method</tt> - Different method to create the input field.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module DryCrud
4
2
  module Table
5
3
 
@@ -20,8 +18,8 @@ module DryCrud
20
18
  # the current entry.
21
19
  # A block may be given to define the link path for the row entry.
22
20
  def attr_with_show_link(attr, &block)
23
- sortable_attr(attr) do |e|
24
- link_to(format_attr(e, attr), action_path(e, &block))
21
+ sortable_attr(attr) do |entry|
22
+ link_to(format_attr(entry, attr), action_path(entry, &block))
25
23
  end
26
24
  end
27
25
 
@@ -29,8 +27,8 @@ module DryCrud
29
27
  # A block may be given to define the link path for the row entry.
30
28
  # If the block returns nil, no link is rendered.
31
29
  def show_action_col(html_options = {}, &block)
32
- action_col do |e|
33
- path = action_path(e, &block)
30
+ action_col do |entry|
31
+ path = action_path(entry, &block)
34
32
  if path
35
33
  table_action_link('zoom-in',
36
34
  path,
@@ -43,8 +41,8 @@ module DryCrud
43
41
  # A block may be given to define the link path for the row entry.
44
42
  # If the block returns nil, no link is rendered.
45
43
  def edit_action_col(html_options = {}, &block)
46
- action_col do |e|
47
- path = action_path(e, &block)
44
+ action_col do |entry|
45
+ path = action_path(entry, &block)
48
46
  if path
49
47
  path = path.is_a?(String) ? path : edit_polymorphic_path(path)
50
48
  table_action_link('pencil', path, html_options.clone)
@@ -56,8 +54,8 @@ module DryCrud
56
54
  # A block may be given to define the link path for the row entry.
57
55
  # If the block returns nil, no link is rendered.
58
56
  def destroy_action_col(html_options = {}, &block)
59
- action_col do |e|
60
- path = action_path(e, &block)
57
+ action_col do |entry|
58
+ path = action_path(entry, &block)
61
59
  if path
62
60
  table_action_link('remove',
63
61
  path,
@@ -85,8 +83,8 @@ module DryCrud
85
83
 
86
84
  # If a block is given, call it to get the path for the current row entry.
87
85
  # Otherwise, return the standard path args.
88
- def action_path(e)
89
- block_given? ? yield(e) : path_args(e)
86
+ def action_path(entry)
87
+ block_given? ? yield(entry) : path_args(entry)
90
88
  end
91
89
 
92
90
  end