dry_crud 7.1.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/controllers/crud_controller.rb +5 -7
- data/app/controllers/dry_crud/generic_model.rb +4 -8
- data/app/controllers/dry_crud/nestable.rb +1 -4
- data/app/controllers/dry_crud/rememberable.rb +1 -4
- data/app/controllers/dry_crud/render_callbacks.rb +2 -10
- data/app/controllers/dry_crud/searchable.rb +3 -10
- data/app/controllers/dry_crud/sortable.rb +3 -10
- data/app/controllers/list_controller.rb +0 -2
- data/app/helpers/actions_helper.rb +8 -10
- data/app/helpers/dry_crud/form/builder.rb +23 -26
- data/app/helpers/dry_crud/form/control.rb +7 -11
- data/app/helpers/dry_crud/table/actions.rb +8 -13
- data/app/helpers/dry_crud/table/builder.rb +3 -6
- data/app/helpers/dry_crud/table/col.rb +1 -4
- data/app/helpers/dry_crud/table/sorting.rb +3 -6
- data/app/helpers/form_helper.rb +5 -7
- data/app/helpers/format_helper.rb +11 -13
- data/app/helpers/i18n_helper.rb +8 -10
- data/app/helpers/table_helper.rb +2 -4
- data/app/helpers/utility_helper.rb +9 -11
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/layouts/application.html.haml +1 -1
- data/lib/dry_crud/engine.rb +1 -3
- data/lib/dry_crud.rb +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +17 -17
- data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
- data/lib/generators/dry_crud/file_generator.rb +6 -6
- data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +119 -119
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +54 -59
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +23 -25
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +10 -13
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +88 -92
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +57 -59
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +18 -21
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +62 -62
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +8 -10
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +20 -22
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +13 -15
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
- data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +25 -27
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +15 -17
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +9 -13
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +7 -11
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +2 -4
- metadata +5 -5
@@ -1,12 +1,10 @@
|
|
1
1
|
module DryCrud
|
2
2
|
module Table
|
3
|
-
|
4
3
|
# Adds action columns to the table builder.
|
5
4
|
# Predefined actions are available for show, edit and destroy.
|
6
5
|
# Additionally, a special col type to define cells linked to the show page
|
7
6
|
# of the row entry is provided.
|
8
7
|
module Actions
|
9
|
-
|
10
8
|
extend ActiveSupport::Concern
|
11
9
|
|
12
10
|
included do
|
@@ -30,7 +28,7 @@ module DryCrud
|
|
30
28
|
action_col do |entry|
|
31
29
|
path = action_path(entry, &block)
|
32
30
|
if path
|
33
|
-
table_action_link(
|
31
|
+
table_action_link("zoom-in",
|
34
32
|
path,
|
35
33
|
**html_options.clone)
|
36
34
|
end
|
@@ -45,7 +43,7 @@ module DryCrud
|
|
45
43
|
path = action_path(entry, &block)
|
46
44
|
if path
|
47
45
|
path = edit_polymorphic_path(path) unless path.is_a?(String)
|
48
|
-
table_action_link(
|
46
|
+
table_action_link("pencil", path, **html_options.clone)
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -57,12 +55,11 @@ module DryCrud
|
|
57
55
|
action_col do |entry|
|
58
56
|
path = action_path(entry, &block)
|
59
57
|
if path
|
60
|
-
table_action_link(
|
58
|
+
table_action_link("trash",
|
61
59
|
path,
|
62
|
-
**html_options
|
63
|
-
|
64
|
-
|
65
|
-
))
|
60
|
+
**html_options,
|
61
|
+
data: { 'turbo-confirm': ti(:confirm_delete),
|
62
|
+
'turbo-method': :delete })
|
66
63
|
end
|
67
64
|
end
|
68
65
|
end
|
@@ -70,13 +67,13 @@ module DryCrud
|
|
70
67
|
# Action column inside a table. No header.
|
71
68
|
# The cell content should be defined in the passed block.
|
72
69
|
def action_col(&block)
|
73
|
-
col(
|
70
|
+
col("", class: "action", &block)
|
74
71
|
end
|
75
72
|
|
76
73
|
# Generic action link inside a table.
|
77
74
|
def table_action_link(icon, url, **html_options)
|
78
75
|
add_css_class(html_options, "bi-#{icon}")
|
79
|
-
link_to(
|
76
|
+
link_to("", url, html_options)
|
80
77
|
end
|
81
78
|
|
82
79
|
private
|
@@ -86,8 +83,6 @@ module DryCrud
|
|
86
83
|
def action_path(entry)
|
87
84
|
block_given? ? yield(entry) : path_args(entry)
|
88
85
|
end
|
89
|
-
|
90
86
|
end
|
91
|
-
|
92
87
|
end
|
93
88
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module DryCrud
|
2
2
|
module Table
|
3
|
-
|
4
3
|
# A simple helper to easily define tables listing several rows of the same
|
5
4
|
# data type.
|
6
5
|
#
|
@@ -10,7 +9,6 @@ module DryCrud
|
|
10
9
|
# t.attrs :name, :city
|
11
10
|
# end
|
12
11
|
class Builder
|
13
|
-
|
14
12
|
include Sorting
|
15
13
|
include Actions
|
16
14
|
|
@@ -39,7 +37,7 @@ module DryCrud
|
|
39
37
|
# Define a column for the table with the given header, the html_options
|
40
38
|
# used for each td and a block rendering the contents of a cell for the
|
41
39
|
# current entry. The columns appear in the order they are defined.
|
42
|
-
def col(header =
|
40
|
+
def col(header = "", **html_options, &block)
|
43
41
|
@cols << Col.new(header, html_options, @template, block)
|
44
42
|
end
|
45
43
|
|
@@ -76,9 +74,9 @@ module DryCrud
|
|
76
74
|
entry = entries.present? ? entry_class.new : nil
|
77
75
|
case column_type(entry, attr)
|
78
76
|
when :integer, :float, :decimal
|
79
|
-
|
77
|
+
"right" unless association(entry, attr, :belongs_to)
|
80
78
|
when :boolean
|
81
|
-
|
79
|
+
"center"
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
@@ -110,7 +108,6 @@ module DryCrud
|
|
110
108
|
entries.first.class
|
111
109
|
end
|
112
110
|
end
|
113
|
-
|
114
111
|
end
|
115
112
|
end
|
116
113
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module DryCrud
|
2
2
|
module Table
|
3
|
-
|
4
3
|
# Helper class to store column information.
|
5
4
|
class Col # :nodoc:
|
6
|
-
|
7
5
|
delegate :tag, :capture, to: :template
|
8
6
|
|
9
7
|
attr_reader :header, :html_options, :template, :block
|
@@ -17,7 +15,7 @@ module DryCrud
|
|
17
15
|
|
18
16
|
# Runs the Col block for the given entry.
|
19
17
|
def content(entry)
|
20
|
-
entry.nil? ?
|
18
|
+
entry.nil? ? "" : capture(entry, &block)
|
21
19
|
end
|
22
20
|
|
23
21
|
# Renders the header cell of the Col.
|
@@ -29,7 +27,6 @@ module DryCrud
|
|
29
27
|
def html_cell(entry)
|
30
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) ==
|
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] ==
|
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
|
data/app/helpers/form_helper.rb
CHANGED
@@ -6,12 +6,11 @@
|
|
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
10
|
def plain_form(object, **options, &block)
|
12
11
|
options[:html] ||= {}
|
13
|
-
add_css_class(options[:html],
|
14
|
-
options[:html][:role] ||=
|
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
|
|
@@ -25,13 +24,13 @@ module FormHelper
|
|
25
24
|
# if present. An options hash may be given as the last argument.
|
26
25
|
def standard_form(object, *attrs, **options, &block)
|
27
26
|
plain_form(object, **options) do |form|
|
28
|
-
content = [form.error_messages]
|
27
|
+
content = [ form.error_messages ]
|
29
28
|
|
30
29
|
content << if block_given?
|
31
30
|
capture(form, &block)
|
32
|
-
|
31
|
+
else
|
33
32
|
form.labeled_input_fields(*attrs)
|
34
|
-
|
33
|
+
end
|
35
34
|
|
36
35
|
content << form.standard_actions
|
37
36
|
safe_join(content)
|
@@ -45,5 +44,4 @@ module FormHelper
|
|
45
44
|
attrs = default_crud_attrs - %i[created_at updated_at] if attrs.blank?
|
46
45
|
standard_form(path_args(entry), *attrs, **options, &block)
|
47
46
|
end
|
48
|
-
|
49
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
12
|
when Float, BigDecimal
|
14
|
-
number_with_precision(value, precision: t(
|
15
|
-
delimiter: t(
|
13
|
+
number_with_precision(value, precision: t("number.format.precision"),
|
14
|
+
delimiter: t("number.format.delimiter"))
|
16
15
|
when Integer
|
17
|
-
number_with_delimiter(value, delimiter: t(
|
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(
|
21
|
-
when false then t(
|
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
|
@@ -47,7 +46,7 @@ module FormatHelper
|
|
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:
|
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(
|
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?(
|
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
|
|
@@ -123,7 +122,7 @@ module FormatHelper
|
|
123
122
|
when :decimal
|
124
123
|
number_with_precision(val.to_s.to_f,
|
125
124
|
precision: column_property(obj, attr, :scale),
|
126
|
-
delimiter: t(
|
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"
|
161
|
+
respond_to?(:"#{val.class.model_name.singular_route_key}_path")
|
163
162
|
end
|
164
|
-
|
165
163
|
end
|
data/app/helpers/i18n_helper.rb
CHANGED
@@ -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}
|
@@ -13,7 +12,7 @@ module I18nHelper
|
|
13
12
|
# - ...
|
14
13
|
# - global.{key}
|
15
14
|
def translate_inheritable(key, **variables)
|
16
|
-
partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/,
|
15
|
+
partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, "") : nil
|
17
16
|
defaults = inheritable_translation_defaults(key, partial)
|
18
17
|
variables[:default] ||= defaults
|
19
18
|
t(defaults.shift, **variables)
|
@@ -30,8 +29,8 @@ module I18nHelper
|
|
30
29
|
# - global.associations.{key}
|
31
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}"]
|
32
|
+
variables[:default] ||= [ association_klass_key(assoc, key).to_sym,
|
33
|
+
:"global.associations.#{key}" ]
|
35
34
|
t(association_owner_key(assoc, key), **variables)
|
36
35
|
else
|
37
36
|
t("global.associations.#{key}", **variables)
|
@@ -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 =
|
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 =
|
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
|
data/app/helpers/table_helper.rb
CHANGED
@@ -7,14 +7,13 @@
|
|
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
15
|
def plain_table(entries, *attrs, **options)
|
17
|
-
add_css_class(options,
|
16
|
+
add_css_class(options, "table table-striped table-hover")
|
18
17
|
builder = options.delete(:builder) || DryCrud::Table::Builder
|
19
18
|
builder.table(entries, self, **options) do |t|
|
20
19
|
t.attrs(*attrs)
|
@@ -29,7 +28,7 @@ module TableHelper
|
|
29
28
|
if entries.present?
|
30
29
|
plain_table(entries, *attrs, **options, &block)
|
31
30
|
else
|
32
|
-
tag.div(ti(:no_list_entries), class:
|
31
|
+
tag.div(ti(:no_list_entries), class: "table")
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -77,5 +76,4 @@ module TableHelper
|
|
77
76
|
attrs
|
78
77
|
end
|
79
78
|
end
|
80
|
-
|
81
79
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
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 =
|
6
|
+
EMPTY_STRING = " ".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.
|
@@ -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
|
25
|
-
when :alert then
|
23
|
+
when :notice then "success"
|
24
|
+
when :alert then "error"
|
26
25
|
else level.to_s
|
27
26
|
end
|
28
27
|
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?(
|
76
|
-
[attr[0..-4], attr]
|
77
|
-
elsif attr.end_with?(
|
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
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%= csp_meta_tag %>
|
11
11
|
|
12
12
|
<%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %>
|
13
|
-
<%= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true %>
|
13
|
+
<%= javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true %>
|
14
14
|
|
15
15
|
<%= yield :head %>
|
16
16
|
</head>
|
@@ -12,7 +12,7 @@
|
|
12
12
|
= csp_meta_tag
|
13
13
|
|
14
14
|
= stylesheet_link_tag 'application', 'data-turbo-track': 'reload'
|
15
|
-
= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true
|
15
|
+
= javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true
|
16
16
|
|
17
17
|
= yield :head
|
18
18
|
|
data/lib/dry_crud/engine.rb
CHANGED
@@ -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
|
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,15 +1,15 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "generators/dry_crud/dry_crud_generator_base"
|
3
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
|
9
|
+
desc "Copy all dry_crud files to the application."
|
10
10
|
|
11
|
-
class_options %w[templates -t] =>
|
12
|
-
class_options %w[tests] =>
|
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
|
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 !=
|
30
|
+
file_source != "INSTALL"
|
31
31
|
end
|
32
32
|
|
33
33
|
def copy_crud_test_model
|
34
|
-
unless exclude_test_dir ==
|
35
|
-
template(File.join(
|
36
|
-
File.join(
|
37
|
-
template(File.join(
|
38
|
-
File.join(
|
39
|
-
template(File.join(
|
40
|
-
File.join(
|
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(
|
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
|
51
|
-
when
|
52
|
-
else
|
50
|
+
when "rspec" then "test"
|
51
|
+
when "all" then "exclude_nothing"
|
52
|
+
else "spec"
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators"
|
2
2
|
|
3
3
|
# Generates all dry crud files
|
4
4
|
class DryCrudGeneratorBase < Rails::Generators::Base
|
5
5
|
def self.template_root
|
6
|
-
File.join(File.dirname(__FILE__),
|
6
|
+
File.join(File.dirname(__FILE__), "templates")
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.gem_root
|
10
|
-
File.join(File.dirname(__FILE__),
|
10
|
+
File.join(File.dirname(__FILE__), "..", "..", "..")
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.source_paths
|
14
|
-
[gem_root,
|
15
|
-
template_root]
|
14
|
+
[ gem_root,
|
15
|
+
template_root ]
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def all_template_files
|
21
21
|
{ self.class.gem_root =>
|
22
|
-
template_files(self.class.gem_root,
|
22
|
+
template_files(self.class.gem_root, "app", "config"),
|
23
23
|
self.class.template_root =>
|
24
24
|
template_files(self.class.template_root) }
|
25
25
|
end
|
26
26
|
|
27
27
|
def template_files(root, *folders)
|
28
|
-
pattern = File.join(
|
28
|
+
pattern = File.join("**", "**")
|
29
29
|
pattern = File.join("{#{folders.join(',')}}", pattern) if folders.present?
|
30
30
|
Dir.chdir(root) do
|
31
31
|
Dir.glob(pattern).sort.reject { |f| File.directory?(f) }
|
@@ -47,7 +47,7 @@ class DryCrudGeneratorBase < Rails::Generators::Base
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def copy_file_source(file_source)
|
50
|
-
if file_source.end_with?(
|
50
|
+
if file_source.end_with?(".erb")
|
51
51
|
copy_file(file_source)
|
52
52
|
else
|
53
53
|
template(file_source)
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "generators/dry_crud/dry_crud_generator_base"
|
2
2
|
|
3
3
|
module DryCrud
|
4
4
|
# Copies one file of dry_crud to the rails application.
|
5
5
|
class FileGenerator < ::DryCrudGeneratorBase
|
6
6
|
desc "Copy one file from dry_crud to the application.\n" \
|
7
|
-
|
8
|
-
|
7
|
+
"FILENAME is a part of the name of the file to copy. " \
|
8
|
+
"Must match exactly one file."
|
9
9
|
|
10
10
|
argument :filename,
|
11
11
|
type: :string,
|
12
|
-
desc:
|
13
|
-
|
12
|
+
desc: "Name or part of the filename to copy. " \
|
13
|
+
"Must match exactly one file."
|
14
14
|
|
15
15
|
# rubocop:disable Rails/Output
|
16
16
|
def copy_matching_file
|
@@ -21,7 +21,7 @@ module DryCrud
|
|
21
21
|
when 0
|
22
22
|
puts "No file containing '#{filename}' found in dry_crud."
|
23
23
|
else
|
24
|
-
puts
|
24
|
+
puts "Please be more specific. " \
|
25
25
|
"All the following files match '#{filename}':"
|
26
26
|
files.each do |f|
|
27
27
|
puts " * #{f}"
|