dry_crud 6.0.0 → 8.0.0

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +2 -2
  3. data/README.rdoc +7 -6
  4. data/VERSION +1 -1
  5. data/app/assets/stylesheets/sample.scss +45 -24
  6. data/app/controllers/crud_controller.rb +24 -26
  7. data/app/controllers/dry_crud/generic_model.rb +6 -12
  8. data/app/controllers/dry_crud/nestable.rb +1 -4
  9. data/app/controllers/dry_crud/rememberable.rb +1 -4
  10. data/app/controllers/dry_crud/render_callbacks.rb +4 -12
  11. data/app/controllers/dry_crud/searchable.rb +3 -10
  12. data/app/controllers/dry_crud/sortable.rb +3 -10
  13. data/app/controllers/list_controller.rb +1 -3
  14. data/app/helpers/actions_helper.rb +13 -15
  15. data/app/helpers/dry_crud/form/builder.rb +56 -62
  16. data/app/helpers/dry_crud/form/control.rb +12 -19
  17. data/app/helpers/dry_crud/table/actions.rb +15 -20
  18. data/app/helpers/dry_crud/table/builder.rb +12 -15
  19. data/app/helpers/dry_crud/table/col.rb +5 -8
  20. data/app/helpers/dry_crud/table/sorting.rb +3 -6
  21. data/app/helpers/form_helper.rb +11 -15
  22. data/app/helpers/format_helper.rb +18 -20
  23. data/app/helpers/i18n_helper.rb +13 -15
  24. data/app/helpers/table_helper.rb +16 -19
  25. data/app/helpers/utility_helper.rb +12 -14
  26. data/app/views/crud/new.html.erb +1 -1
  27. data/app/views/crud/new.html.haml +1 -1
  28. data/app/views/layouts/application.html.erb +8 -6
  29. data/app/views/layouts/application.html.haml +6 -5
  30. data/app/views/list/_search.html.erb +1 -3
  31. data/app/views/list/_search.html.haml +1 -2
  32. data/app/views/shared/_error_messages.html.erb +2 -2
  33. data/lib/dry_crud/engine.rb +1 -3
  34. data/lib/dry_crud.rb +1 -1
  35. data/lib/generators/dry_crud/dry_crud_generator.rb +18 -18
  36. data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
  37. data/lib/generators/dry_crud/file_generator.rb +6 -6
  38. data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
  39. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +122 -122
  40. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +55 -60
  41. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +24 -26
  42. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +16 -18
  43. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +90 -94
  44. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
  45. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +59 -61
  46. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +20 -23
  47. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +66 -68
  48. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +11 -13
  49. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
  50. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +25 -27
  51. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
  52. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
  53. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +21 -23
  54. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
  55. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
  56. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +28 -30
  57. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +17 -19
  58. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
  59. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +15 -19
  60. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +9 -14
  61. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +16 -20
  62. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +8 -10
  63. metadata +9 -10
@@ -1,10 +1,8 @@
1
1
  module DryCrud
2
2
  module Table
3
-
4
3
  # Helper class to store column information.
5
- class Col #:nodoc:
6
-
7
- delegate :content_tag, :capture, to: :template
4
+ class Col # :nodoc:
5
+ delegate :tag, :capture, to: :template
8
6
 
9
7
  attr_reader :header, :html_options, :template, :block
10
8
 
@@ -17,19 +15,18 @@ module DryCrud
17
15
 
18
16
  # Runs the Col block for the given entry.
19
17
  def content(entry)
20
- entry.nil? ? '' : capture(entry, &block)
18
+ entry.nil? ? "" : capture(entry, &block)
21
19
  end
22
20
 
23
21
  # Renders the header cell of the Col.
24
22
  def html_header
25
- content_tag(:th, header, html_options)
23
+ tag.th(header, **html_options)
26
24
  end
27
25
 
28
26
  # Renders a table cell for the given entry.
29
27
  def html_cell(entry)
30
- content_tag(:td, content(entry), html_options)
28
+ tag.td(content(entry), **html_options)
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -1,11 +1,9 @@
1
1
  module DryCrud
2
2
  module Table
3
-
4
3
  # Provides headers with sort links. Expects a method :sortable?(attr)
5
4
  # in the template/controller to tell if an attribute is sortable or not.
6
5
  # Extracted into an own module for convenience.
7
6
  module Sorting
8
-
9
7
  # Create a header with sort links and a mark for the current sort
10
8
  # direction.
11
9
  def sort_header(attr, label = nil)
@@ -40,10 +38,10 @@ module DryCrud
40
38
  def current_mark(attr)
41
39
  if current_sort?(attr)
42
40
  # rubocop:disable Rails/OutputSafety
43
- (sort_dir(attr) == 'asc' ? ' ↑' : ' ↓').html_safe
41
+ (sort_dir(attr) == "asc" ? " ↑" : " ↓").html_safe
44
42
  # rubocop:enable Rails/OutputSafety
45
43
  else
46
- ''
44
+ ""
47
45
  end
48
46
  end
49
47
 
@@ -54,14 +52,13 @@ module DryCrud
54
52
 
55
53
  # The sort direction to use in the sort link for the given attribute.
56
54
  def sort_dir(attr)
57
- current_sort?(attr) && params[:sort_dir] == 'asc' ? 'desc' : 'asc'
55
+ current_sort?(attr) && params[:sort_dir] == "asc" ? "desc" : "asc"
58
56
  end
59
57
 
60
58
  # Delegate to template.
61
59
  def params
62
60
  template.params
63
61
  end
64
-
65
62
  end
66
63
  end
67
64
  end
@@ -6,16 +6,15 @@
6
6
  # * #crud_form - A #standard_form for the current +entry+, with the given
7
7
  # attributes or default.
8
8
  module FormHelper
9
-
10
9
  # Renders a form using Crud::FormBuilder.
11
- def plain_form(object, options = {}, &block)
10
+ def plain_form(object, **options, &block)
12
11
  options[:html] ||= {}
13
- add_css_class(options[:html], 'form-horizontal')
14
- options[:html][:role] ||= 'form'
12
+ add_css_class(options[:html], "form-horizontal")
13
+ options[:html][:role] ||= "form"
15
14
  options[:builder] ||= DryCrud::Form::Builder
16
15
  options[:cancel_url] ||= polymorphic_path(object, returning: true)
17
16
 
18
- form_for(object, options, &block)
17
+ form_for(object, **options, &block)
19
18
  end
20
19
 
21
20
  # Renders a standard form for the given entry and attributes.
@@ -23,15 +22,15 @@ module FormHelper
23
22
  # If a block is given, custom input fields may be rendered and attrs is
24
23
  # ignored. Before the input fields, the error messages are rendered,
25
24
  # if present. An options hash may be given as the last argument.
26
- def standard_form(object, *attrs, &block)
27
- plain_form(object, attrs.extract_options!) do |form|
28
- content = [form.error_messages]
25
+ def standard_form(object, *attrs, **options, &block)
26
+ plain_form(object, **options) do |form|
27
+ content = [ form.error_messages ]
29
28
 
30
29
  content << if block_given?
31
30
  capture(form, &block)
32
- else
31
+ else
33
32
  form.labeled_input_fields(*attrs)
34
- end
33
+ end
35
34
 
36
35
  content << form.standard_actions
37
36
  safe_join(content)
@@ -41,11 +40,8 @@ module FormHelper
41
40
  # Renders a crud form for the current entry with default_crud_attrs or the
42
41
  # given attribute array. An options hash may be given as the last argument.
43
42
  # If a block is given, a custom form may be rendered and attrs is ignored.
44
- def crud_form(*attrs, &block)
45
- options = attrs.extract_options!
43
+ def crud_form(*attrs, **options, &block)
46
44
  attrs = default_crud_attrs - %i[created_at updated_at] if attrs.blank?
47
- attrs << options
48
- standard_form(path_args(entry), *attrs, &block)
45
+ standard_form(path_args(entry), *attrs, **options, &block)
49
46
  end
50
-
51
47
  end
@@ -6,19 +6,18 @@
6
6
  # Futher helpers standartize the layout of multiple attributes (#render_attrs),
7
7
  # values with labels (#labeled) and simple lists.
8
8
  module FormatHelper
9
-
10
9
  # Formats a basic value based on its Ruby class.
11
10
  def f(value)
12
11
  case value
13
- when Float, BigDecimal then
14
- number_with_precision(value, precision: t('number.format.precision'),
15
- delimiter: t('number.format.delimiter'))
16
- when Integer then
17
- number_with_delimiter(value, delimiter: t('number.format.delimiter'))
12
+ when Float, BigDecimal
13
+ number_with_precision(value, precision: t("number.format.precision"),
14
+ delimiter: t("number.format.delimiter"))
15
+ when Integer
16
+ number_with_delimiter(value, delimiter: t("number.format.delimiter"))
18
17
  when Date then l(value)
19
18
  when Time then "#{l(value.to_date)} #{l(value, format: :time)}"
20
- when true then t('global.yes')
21
- when false then t('global.no')
19
+ when true then t("global.yes")
20
+ when false then t("global.no")
22
21
  when nil then UtilityHelper::EMPTY_STRING
23
22
  else value.to_s
24
23
  end
@@ -38,16 +37,16 @@ module FormatHelper
38
37
  # Renders a simple unordered list, which will
39
38
  # simply render all passed items or yield them
40
39
  # to your block.
41
- def simple_list(items, ul_options = {})
42
- content_tag_nested(:ul, items, ul_options) do |item|
43
- content_tag(:li, block_given? ? yield(item) : f(item))
40
+ def simple_list(items, **ul_options)
41
+ content_tag_nested(:ul, items, **ul_options) do |item|
42
+ tag.li(block_given? ? yield(item) : f(item))
44
43
  end
45
44
  end
46
45
 
47
46
  # Renders a list of attributes with label and value for a given object.
48
47
  # Optionally surrounded with a div.
49
48
  def render_attrs(obj, *attrs)
50
- content_tag_nested(:dl, attrs, class: 'dl-horizontal') do |a|
49
+ content_tag_nested(:dl, attrs, class: "dl-horizontal") do |a|
51
50
  labeled_attr(obj, a)
52
51
  end
53
52
  end
@@ -61,14 +60,14 @@ module FormatHelper
61
60
  # presentation.
62
61
  def labeled(label, content = nil, &block)
63
62
  content = capture(&block) if block_given?
64
- render('shared/labeled', label: label, content: content)
63
+ render("shared/labeled", label: label, content: content)
65
64
  end
66
65
 
67
66
  # Transform the given text into a form as used by labels or table headers.
68
67
  def captionize(text, clazz = nil)
69
68
  text = text.to_s
70
69
  if clazz.respond_to?(:human_attribute_name)
71
- text_without_id = text.end_with?('_ids') ? text[0..-5].pluralize : text
70
+ text_without_id = text.end_with?("_ids") ? text[0..-5].pluralize : text
72
71
  clazz.human_attribute_name(text_without_id)
73
72
  else
74
73
  text.humanize.titleize
@@ -80,7 +79,7 @@ module FormatHelper
80
79
  # Checks whether a format_{class}_{attr} or format_{attr} helper method is
81
80
  # defined and calls it if is.
82
81
  def format_with_helper(obj, attr)
83
- class_name = obj.class.name.underscore.tr('/', '_')
82
+ class_name = obj.class.name.underscore.tr("/", "_")
84
83
  format_type_attr_method = :"format_#{class_name}_#{attr}"
85
84
  format_attr_method = :"format_#{attr}"
86
85
 
@@ -119,11 +118,11 @@ module FormatHelper
119
118
  when :time then l(val, format: :time)
120
119
  when :date then f(val.to_date)
121
120
  when :datetime, :timestamp then f(val.time)
122
- when :text then simple_format(h(val))
123
- when :decimal then
121
+ when :text then simple_format(h(val))
122
+ when :decimal
124
123
  number_with_precision(val.to_s.to_f,
125
124
  precision: column_property(obj, attr, :scale),
126
- delimiter: t('number.format.delimiter'))
125
+ delimiter: t("number.format.delimiter"))
127
126
  else f(val)
128
127
  end
129
128
  end
@@ -159,7 +158,6 @@ module FormatHelper
159
158
  # Returns true if no link should be created when formatting the given
160
159
  # association.
161
160
  def assoc_link?(_assoc, val)
162
- respond_to?("#{val.class.model_name.singular_route_key}_path".to_sym)
161
+ respond_to?(:"#{val.class.model_name.singular_route_key}_path")
163
162
  end
164
-
165
163
  end
@@ -1,7 +1,6 @@
1
1
  # Translation helpers extending the Rails +translate+ helper to support
2
2
  # translation inheritance over the controller class hierarchy.
3
3
  module I18nHelper
4
-
5
4
  # Translates the passed key by looking it up over the controller hierarchy.
6
5
  # The key is searched in the following order:
7
6
  # - {controller}.{current_partial}.{key}
@@ -12,11 +11,11 @@ module I18nHelper
12
11
  # - {parent_controller}.global.{key}
13
12
  # - ...
14
13
  # - global.{key}
15
- def translate_inheritable(key, variables = {})
16
- partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, '') : nil
14
+ def translate_inheritable(key, **variables)
15
+ partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, "") : nil
17
16
  defaults = inheritable_translation_defaults(key, partial)
18
17
  variables[:default] ||= defaults
19
- t(defaults.shift, variables)
18
+ t(defaults.shift, **variables)
20
19
  end
21
20
 
22
21
  alias ti translate_inheritable
@@ -28,13 +27,13 @@ module I18nHelper
28
27
  # - activerecord.associations.models.{model_name}.{association_name}.{key}
29
28
  # - activerecord.associations.{association_model_name}.{key}
30
29
  # - global.associations.{key}
31
- def translate_association(key, assoc = nil, variables = {})
30
+ def translate_association(key, assoc = nil, **variables)
32
31
  if assoc && assoc.options[:polymorphic].nil?
33
- variables[:default] ||= [association_klass_key(assoc, key).to_sym,
34
- :"global.associations.#{key}"]
35
- t(association_owner_key(assoc, key), variables)
32
+ variables[:default] ||= [ association_klass_key(assoc, key).to_sym,
33
+ :"global.associations.#{key}" ]
34
+ t(association_owner_key(assoc, key), **variables)
36
35
  else
37
- t("global.associations.#{key}", variables)
36
+ t("global.associations.#{key}", **variables)
38
37
  end
39
38
  end
40
39
 
@@ -44,20 +43,20 @@ module I18nHelper
44
43
 
45
44
  # General translation key based on the klass of the association.
46
45
  def association_klass_key(assoc, key)
47
- k = 'activerecord.associations.'
46
+ k = "activerecord.associations."
48
47
  k << assoc.klass.model_name.singular
49
- k << '.'
48
+ k << "."
50
49
  k << key.to_s
51
50
  end
52
51
 
53
52
  # Specific translation key based on the owner model and the name
54
53
  # of the association.
55
54
  def association_owner_key(assoc, key)
56
- k = 'activerecord.associations.models.'
55
+ k = "activerecord.associations.models."
57
56
  k << assoc.active_record.model_name.singular
58
- k << '.'
57
+ k << "."
59
58
  k << assoc.name.to_s
60
- k << '.'
59
+ k << "."
61
60
  k << key.to_s
62
61
  end
63
62
 
@@ -79,5 +78,4 @@ module I18nHelper
79
78
  defaults << :"#{folder}.#{action_name}.#{key}"
80
79
  defaults << :"#{folder}.global.#{key}"
81
80
  end
82
-
83
81
  end
@@ -7,17 +7,15 @@
7
7
  # * #crud_table - A sortable #plain_table for the current +entries+, with the
8
8
  # given attributes or default and the standard crud action links.
9
9
  module TableHelper
10
-
11
10
  # Renders a table for the given entries. One column is rendered for each
12
11
  # attribute passed. If a block is given, the columns defined therein are
13
12
  # appended to the attribute columns.
14
13
  # If entries is empty, an appropriate message is rendered.
15
14
  # An options hash may be given as the last argument.
16
- def plain_table(entries, *attrs)
17
- options = attrs.extract_options!
18
- add_css_class(options, 'table table-striped table-hover')
15
+ def plain_table(entries, *attrs, **options)
16
+ add_css_class(options, "table table-striped table-hover")
19
17
  builder = options.delete(:builder) || DryCrud::Table::Builder
20
- builder.table(entries, self, options) do |t|
18
+ builder.table(entries, self, **options) do |t|
21
19
  t.attrs(*attrs)
22
20
  yield t if block_given?
23
21
  end
@@ -25,21 +23,21 @@ module TableHelper
25
23
 
26
24
  # Renders a #plain_table for the given entries.
27
25
  # If entries is empty, an appropriate message is rendered.
28
- def plain_table_or_message(entries, *attrs, &block)
26
+ def plain_table_or_message(entries, *attrs, **options, &block)
29
27
  entries.to_a # force evaluation of relations
30
28
  if entries.present?
31
- plain_table(entries, *attrs, &block)
29
+ plain_table(entries, *attrs, **options, &block)
32
30
  else
33
- content_tag(:div, ti(:no_list_entries), class: 'table')
31
+ tag.div(ti(:no_list_entries), class: "table")
34
32
  end
35
33
  end
36
34
 
37
35
  # Create a table of the +entries+ with the default or
38
36
  # the passed attributes in its columns. An options hash may be given
39
37
  # as the last argument.
40
- def list_table(*attrs, &block)
41
- attrs, options = explode_attrs_with_options(attrs, &block)
42
- plain_table_or_message(entries, options) do |t|
38
+ def list_table(*attrs, **options, &block)
39
+ attrs = attrs_or_default(attrs, &block)
40
+ plain_table_or_message(entries, **options) do |t|
43
41
  t.sortable_attrs(*attrs)
44
42
  yield t if block_given?
45
43
  end
@@ -52,10 +50,10 @@ module TableHelper
52
50
  # If a block is given, the column defined there will be inserted
53
51
  # between the given attributes and the actions.
54
52
  # An options hash for the table builder may be given as the last argument.
55
- def crud_table(*attrs, &block)
56
- attrs, options = explode_attrs_with_options(attrs, &block)
53
+ def crud_table(*attrs, **options, &block)
54
+ attrs = attrs_or_default(attrs, &block)
57
55
  first = attrs.shift
58
- plain_table_or_message(entries, options) do |t|
56
+ plain_table_or_message(entries, **options) do |t|
59
57
  t.attr_with_show_link(first) if first
60
58
  t.sortable_attrs(*attrs)
61
59
  yield t if block_given?
@@ -71,12 +69,11 @@ module TableHelper
71
69
 
72
70
  private
73
71
 
74
- def explode_attrs_with_options(attrs)
75
- options = attrs.extract_options!
72
+ def attrs_or_default(attrs)
76
73
  if !block_given? && attrs.blank?
77
- attrs = default_crud_attrs
74
+ default_crud_attrs
75
+ else
76
+ attrs
78
77
  end
79
- [attrs, options]
80
78
  end
81
-
82
79
  end
@@ -1,15 +1,14 @@
1
- require 'English'
1
+ require "English"
2
2
 
3
3
  # View helpers for basic functions used in various other helpers.
4
4
  module UtilityHelper
5
-
6
5
  # non-breaking space asserts better css.
7
- EMPTY_STRING = '&nbsp;'.html_safe.freeze
6
+ EMPTY_STRING = "&nbsp;".html_safe.freeze
8
7
 
9
8
  # Render a content tag with the collected contents rendered
10
9
  # by &block for each item in collection.
11
- def content_tag_nested(tag, collection, options = {}, &block)
12
- content_tag(tag, safe_join(collection, &block), options)
10
+ def content_tag_nested(tag, collection, **options, &block)
11
+ content_tag(tag, safe_join(collection, &block), **options)
13
12
  end
14
13
 
15
14
  # Overridden method that takes a block that is executed for each item in
@@ -21,8 +20,8 @@ module UtilityHelper
21
20
  # Returns the css class for the given flash level.
22
21
  def flash_class(level)
23
22
  case level
24
- when :notice then 'success'
25
- when :alert then 'error'
23
+ when :notice then "success"
24
+ when :alert then "error"
26
25
  else level.to_s
27
26
  end
28
27
  end
@@ -30,7 +29,7 @@ module UtilityHelper
30
29
  # Adds a class to the given options, even if there are already classes.
31
30
  def add_css_class(options, classes)
32
31
  if options[:class]
33
- options[:class] += ' ' + classes if classes
32
+ options[:class] += " #{classes}" if classes
34
33
  else
35
34
  options[:class] = classes
36
35
  end
@@ -72,13 +71,12 @@ module UtilityHelper
72
71
  # Returns the name of the attr and it's corresponding field
73
72
  def assoc_and_id_attr(attr)
74
73
  attr = attr.to_s
75
- if attr.end_with?('_id')
76
- [attr[0..-4], attr]
77
- elsif attr.end_with?('_ids')
78
- [attr[0..-5].pluralize, attr]
74
+ if attr.end_with?("_id")
75
+ [ attr[0..-4], attr ]
76
+ elsif attr.end_with?("_ids")
77
+ [ attr[0..-5].pluralize, attr ]
79
78
  else
80
- [attr, "#{attr}_id"]
79
+ [ attr, "#{attr}_id" ]
81
80
  end
82
81
  end
83
-
84
82
  end
@@ -1,4 +1,4 @@
1
- <% @title ||= ti(:title, model: models_label(false)) -%>
1
+ <% @title ||= ti(:title, model: models_label(plural: false)) -%>
2
2
 
3
3
  <% content_for(:actions, index_action_link) %>
4
4
 
@@ -1,4 +1,4 @@
1
- - @title ||= ti(:title, model: models_label(false))
1
+ - @title ||= ti(:title, model: models_label(plural: false))
2
2
 
3
3
  - content_for(:actions, index_action_link)
4
4
 
@@ -5,31 +5,33 @@
5
5
  <meta charset="utf-8" />
6
6
  <title><%= strip_tags(@title) %> - MyApp</title>
7
7
 
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <meta name="viewport" content="width=device-width,initial-scale=1">
9
9
  <%= csrf_meta_tag %>
10
10
  <%= csp_meta_tag %>
11
11
 
12
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
13
- <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
12
+ <%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %>
13
+ <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true %>
14
14
 
15
15
  <%= yield :head %>
16
16
  </head>
17
17
  <body>
18
18
 
19
19
  <nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
20
- <%= render 'layouts/nav' %>
20
+ <div class="container-fluid">
21
+ <%= render 'layouts/nav' %>
22
+ </div>
21
23
  </nav>
22
24
 
23
25
  <div class="container">
24
26
 
25
27
  <h1><%= @title %></h1>
26
28
 
27
- <div class="row actions">
29
+ <div class="row actions mb-3">
28
30
  <div class="col-md-5">
29
31
  <%= yield :tools %>
30
32
  </div>
31
33
  <div class="col-md-7">
32
- <div class="btn-toolbar float-right">
34
+ <div class="btn-toolbar float-end">
33
35
  <%= yield :actions %>
34
36
  </div>
35
37
  </div>
@@ -11,23 +11,24 @@
11
11
  = csrf_meta_tag
12
12
  = csp_meta_tag
13
13
 
14
- = stylesheet_link_tag 'application', :media => 'all', 'data-turbolinks-track': 'reload'
15
- = javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'
14
+ = stylesheet_link_tag 'application', 'data-turbo-track': 'reload'
15
+ = javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true
16
16
 
17
17
  = yield :head
18
18
 
19
19
  %body
20
20
  %nav.navbar.navbar-expand-lg.navbar-light.bg-light.mb-4
21
- = render 'layouts/nav'
21
+ .container-fluid
22
+ = render 'layouts/nav'
22
23
 
23
24
  .container
24
25
  %h1= @title
25
26
 
26
- .row.actions
27
+ .row.actions.mb-3
27
28
  .col-md-5
28
29
  = yield :tools
29
30
  .col-md-7
30
- .btn-toolbar.float-right
31
+ .btn-toolbar.float-end
31
32
  = yield :actions
32
33
 
33
34
  #flash= render partial: 'layouts/flash', collection: [:notice, :alert], as: :level
@@ -3,8 +3,6 @@
3
3
  <%= hidden_field_tag :page, 1 %>
4
4
  <div class="input-group">
5
5
  <%= search_field_tag :q, params[:q], class: 'form-control' %>
6
- <span class="input-group-append">
7
- <%= submit_tag ti(:"button.search"), class: 'btn btn-outline-secondary' %>
8
- </span>
6
+ <%= submit_tag ti(:"button.search"), class: 'btn btn-outline-secondary' %>
9
7
  </div>
10
8
  <% end %>
@@ -3,5 +3,4 @@
3
3
  = hidden_field_tag :page, 1
4
4
  .input-group
5
5
  = search_field_tag :q, params[:q], class: 'form-control'
6
- %span.input-group-append
7
- = submit_tag ti(:"button.search"), class: 'btn btn-outline-secondary'
6
+ = submit_tag ti(:"button.search"), class: 'btn btn-outline-secondary'
@@ -1,8 +1,8 @@
1
1
  <% if errors.any? %>
2
2
  <div id='error_explanation' class='alert alert-danger'>
3
- <h2>
3
+ <p>
4
4
  <%= ti(:"errors.header", count: errors.count, model: object.to_s) %>
5
- </h2>
5
+ </p>
6
6
  <ul>
7
7
  <% errors.full_messages.each do |msg| %>
8
8
  <li><%= msg %></li>
@@ -1,10 +1,9 @@
1
1
  module DryCrud
2
2
  # Dry Crud Rails engine
3
3
  class Engine < Rails::Engine
4
-
5
4
  # Fields with errors are directly styled in DryCrud::FormBuilder.
6
5
  # Rails should just output the plain html tag.
7
- initializer 'dry_crud.field_error_proc' do |_app|
6
+ initializer "dry_crud.field_error_proc" do |_app|
8
7
  ActionView::Base.field_error_proc =
9
8
  proc { |html_tag, _instance| html_tag }
10
9
  end
@@ -21,6 +20,5 @@ module DryCrud
21
20
  paths.prepend(dry_crud_helpers)
22
21
  end
23
22
  end
24
-
25
23
  end
26
24
  end
data/lib/dry_crud.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'dry_crud/engine'
1
+ require "dry_crud/engine"
2
2
 
3
3
  # Base namespace
4
4
  module DryCrud
@@ -1,15 +1,15 @@
1
1
  begin
2
- require 'generators/dry_crud/dry_crud_generator_base'
3
- rescue LoadError => _e # rubocop:disable Lint/HandleExceptions
2
+ require "generators/dry_crud/dry_crud_generator_base"
3
+ rescue LoadError => _e
4
4
  # ok, we are in the rake task
5
5
  end
6
6
 
7
7
  # Copies all dry_crud files to the rails application.
8
8
  class DryCrudGenerator < DryCrudGeneratorBase
9
- desc 'Copy all dry_crud files to the application.'
9
+ desc "Copy all dry_crud files to the application."
10
10
 
11
- class_options %w[templates -t] => 'erb'
12
- class_options %w[tests] => 'testunit'
11
+ class_options %w[templates -t] => "erb"
12
+ class_options %w[tests] => "testunit"
13
13
 
14
14
  # copy everything to application
15
15
  def install_dry_crud
@@ -19,7 +19,7 @@ class DryCrudGenerator < DryCrudGeneratorBase
19
19
  copy_crud_test_model
20
20
  end
21
21
 
22
- readme 'INSTALL'
22
+ readme "INSTALL"
23
23
  end
24
24
 
25
25
  private
@@ -27,29 +27,29 @@ class DryCrudGenerator < DryCrudGeneratorBase
27
27
  def should_copy?(file_source)
28
28
  !file_source.end_with?(exclude_template) &&
29
29
  !file_source.start_with?(exclude_test_dir) &&
30
- file_source != 'INSTALL'
30
+ file_source != "INSTALL"
31
31
  end
32
32
 
33
33
  def copy_crud_test_model
34
- unless exclude_test_dir == 'spec'
35
- template(File.join('test', 'support', 'crud_test_model.rb'),
36
- File.join('spec', 'support', 'crud_test_model.rb'))
37
- template(File.join('test', 'support', 'crud_test_models_controller.rb'),
38
- File.join('spec', 'support', 'crud_test_models_controller.rb'))
39
- template(File.join('test', 'support', 'crud_test_helper.rb'),
40
- File.join('spec', 'support', 'crud_test_helper.rb'))
34
+ unless exclude_test_dir == "spec"
35
+ template(File.join("test", "support", "crud_test_model.rb"),
36
+ File.join("spec", "support", "crud_test_model.rb"))
37
+ template(File.join("test", "support", "crud_test_models_controller.rb"),
38
+ File.join("spec", "support", "crud_test_models_controller.rb"))
39
+ template(File.join("test", "support", "crud_test_helper.rb"),
40
+ File.join("spec", "support", "crud_test_helper.rb"))
41
41
  end
42
42
  end
43
43
 
44
44
  def exclude_template
45
- options[:templates].casecmp('haml').zero? ? '.erb' : '.haml'
45
+ options[:templates].casecmp("haml").zero? ? ".erb" : ".haml"
46
46
  end
47
47
 
48
48
  def exclude_test_dir
49
49
  case options[:tests].downcase
50
- when 'rspec' then 'test'
51
- when 'all' then 'exclude_nothing'
52
- else 'spec'
50
+ when "rspec" then "test"
51
+ when "all" then "exclude_nothing"
52
+ else "spec"
53
53
  end
54
54
  end
55
55
  end