active_scaffold 3.4.43 → 3.5.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/CHANGELOG +39 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +27 -19
- data/app/assets/javascripts/active_scaffold.js.erb +1 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
- data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
- data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
- data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
- data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
- data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
- data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
- data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
- data/app/views/active_scaffold_overrides/show.html.erb +6 -0
- data/app/views/active_scaffold_overrides/update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/config/brakeman.ignore +26 -0
- data/config/brakeman.yml +3 -0
- data/config/i18n-tasks.yml +121 -0
- data/config/locales/de.yml +81 -70
- data/config/locales/en.yml +83 -74
- data/config/locales/es.yml +82 -73
- data/config/locales/fr.yml +86 -75
- data/config/locales/hu.yml +81 -70
- data/config/locales/ja.yml +71 -60
- data/config/locales/ru.yml +85 -74
- data/lib/active_scaffold.rb +3 -0
- data/lib/active_scaffold/actions/common_search.rb +11 -7
- data/lib/active_scaffold/actions/core.rb +119 -47
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +11 -8
- data/lib/active_scaffold/actions/field_search.rb +104 -6
- data/lib/active_scaffold/actions/list.rb +25 -21
- data/lib/active_scaffold/actions/mark.rb +12 -4
- data/lib/active_scaffold/actions/nested.rb +26 -26
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +4 -5
- data/lib/active_scaffold/actions/subform.rb +9 -7
- data/lib/active_scaffold/actions/update.rb +20 -13
- data/lib/active_scaffold/active_record_permissions.rb +24 -5
- data/lib/active_scaffold/attribute_params.rb +68 -49
- data/lib/active_scaffold/bridges.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
- data/lib/active_scaffold/bridges/cancan.rb +4 -3
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen.rb +4 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker.rb +3 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
- data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/paperclip.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/record_select.rb +2 -0
- data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
- data/lib/active_scaffold/config/base.rb +9 -6
- data/lib/active_scaffold/config/core.rb +30 -21
- data/lib/active_scaffold/config/create.rb +2 -1
- data/lib/active_scaffold/config/delete.rb +2 -2
- data/lib/active_scaffold/config/field_search.rb +9 -3
- data/lib/active_scaffold/config/form.rb +4 -4
- data/lib/active_scaffold/config/list.rb +27 -23
- data/lib/active_scaffold/config/nested.rb +4 -4
- data/lib/active_scaffold/config/search.rb +6 -6
- data/lib/active_scaffold/config/show.rb +11 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -2
- data/lib/active_scaffold/constraints.rb +39 -36
- data/lib/active_scaffold/core.rb +36 -15
- data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
- data/lib/active_scaffold/data_structures/action_link.rb +4 -5
- data/lib/active_scaffold/data_structures/action_links.rb +5 -4
- data/lib/active_scaffold/data_structures/actions.rb +2 -2
- data/lib/active_scaffold/data_structures/association.rb +8 -0
- data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
- data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
- data/lib/active_scaffold/data_structures/bridge.rb +3 -6
- data/lib/active_scaffold/data_structures/column.rb +100 -82
- data/lib/active_scaffold/data_structures/columns.rb +21 -3
- data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
- data/lib/active_scaffold/data_structures/set.rb +4 -4
- data/lib/active_scaffold/data_structures/sorting.rb +29 -15
- data/lib/active_scaffold/engine.rb +3 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
- data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
- data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
- data/lib/active_scaffold/extensions/localize.rb +3 -4
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
- data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
- data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
- data/lib/active_scaffold/extensions/to_label.rb +1 -1
- data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
- data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
- data/lib/active_scaffold/finder.rb +200 -134
- data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
- data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
- data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
- data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
- data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
- data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
- data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
- data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
- data/lib/active_scaffold/orm_checks.rb +109 -0
- data/lib/active_scaffold/paginator.rb +1 -1
- data/lib/active_scaffold/responds_to_parent.rb +12 -10
- data/lib/active_scaffold/tableless.rb +81 -43
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +49 -0
- data/lib/generators/active_scaffold/install_generator.rb +45 -0
- data/lib/generators/active_scaffold/resource_generator.rb +56 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
- data/shoulda_macros/macros.rb +3 -3
- data/test/active_scaffold_config_mock.rb +33 -0
- data/test/bridges/bridge_test.rb +9 -9
- data/test/bridges/date_picker_test.rb +3 -1
- data/test/bridges/paper_trail_test.rb +2 -3
- data/test/bridges/paperclip_test.rb +21 -10
- data/test/bridges/tiny_mce_test.rb +20 -21
- data/test/class_with_finder.rb +42 -0
- data/test/company.rb +6 -4
- data/test/config/core_test.rb +1 -1
- data/test/config/create_test.rb +1 -1
- data/test/config/list_test.rb +3 -3
- data/test/config/update_test.rb +3 -3
- data/test/data_structures/action_columns_test.rb +3 -3
- data/test/data_structures/association_column_test.rb +5 -5
- data/test/data_structures/column_test.rb +14 -14
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/set_test.rb +2 -2
- data/test/data_structures/sorting_test.rb +6 -4
- data/test/extensions/active_record_test.rb +1 -1
- data/test/extensions/routing_mapper_test.rb +64 -13
- data/test/helpers/form_column_helpers_test.rb +6 -6
- data/test/helpers/list_column_helpers_test.rb +9 -5
- data/test/helpers/pagination_helpers_test.rb +1 -0
- data/test/misc/active_record_permissions_test.rb +18 -1
- data/test/misc/attribute_params_test.rb +26 -17
- data/test/misc/calculation_test.rb +8 -31
- data/test/misc/configurable_test.rb +3 -2
- data/test/misc/constraints_test.rb +33 -22
- data/test/misc/convert_numbers_format_test.rb +28 -10
- data/test/misc/finder_test.rb +6 -29
- data/test/misc/parse_datetime_test.rb +160 -0
- data/test/misc/render_test.rb +1 -1
- data/test/misc/tableless_test.rb +24 -0
- data/test/mock_app/app/models/building.rb +2 -1
- data/test/mock_app/config.ru +1 -1
- data/test/mock_app/config/environments/test.rb +1 -1
- data/test/mock_app/config/routes.rb +11 -3
- data/test/model_stub.rb +11 -6
- data/test/run_all.rb +1 -1
- data/test/test_helper.rb +19 -4
- metadata +42 -23
- data/lib/active_scaffold/data_structures/error_message.rb +0 -22
- data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
- data/lib/generators/active_scaffold/USAGE +0 -29
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
- data/lib/generators/active_scaffold_controller/USAGE +0 -19
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
- data/test/data_structures/error_message_test.rb +0 -25
@@ -0,0 +1,109 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module OrmChecks
|
3
|
+
class << self
|
4
|
+
def active_record?(klass)
|
5
|
+
return unless defined? ActiveRecord
|
6
|
+
klass < ActiveRecord::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
def mongoid?(klass)
|
10
|
+
return unless defined? Mongoid
|
11
|
+
klass < Mongoid::Document
|
12
|
+
end
|
13
|
+
|
14
|
+
def tableless?(klass)
|
15
|
+
klass < ActiveScaffold::Tableless
|
16
|
+
end
|
17
|
+
|
18
|
+
def table_name(klass)
|
19
|
+
if active_record? klass
|
20
|
+
klass.table_name
|
21
|
+
elsif mongoid? klass
|
22
|
+
klass.collection.name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def quoted_table_name(klass)
|
27
|
+
klass.quoted_table_name if active_record? klass
|
28
|
+
end
|
29
|
+
|
30
|
+
def columns(klass)
|
31
|
+
if active_record? klass
|
32
|
+
klass.columns
|
33
|
+
elsif mongoid? klass
|
34
|
+
klass.fields.values
|
35
|
+
else
|
36
|
+
[]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def columns_hash(klass)
|
41
|
+
if active_record? klass
|
42
|
+
klass.columns_hash
|
43
|
+
elsif mongoid? klass
|
44
|
+
klass.fields
|
45
|
+
else
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def reflect_on_all_associations(klass)
|
51
|
+
if active_record? klass
|
52
|
+
klass.reflect_on_all_associations
|
53
|
+
elsif mongoid? klass
|
54
|
+
klass.relations.values
|
55
|
+
else
|
56
|
+
[]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def content_columns(klass)
|
61
|
+
if active_record? klass
|
62
|
+
klass.content_columns
|
63
|
+
elsif mongoid? klass
|
64
|
+
klass.fields.reject { |field, _| field == '_id' }.values
|
65
|
+
else
|
66
|
+
[]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def type_for_attribute(klass, column_name)
|
71
|
+
if active_record? klass
|
72
|
+
if klass.respond_to? :type_for_attribute
|
73
|
+
klass.type_for_attribute column_name.to_s
|
74
|
+
else # Rails.version < 4.2
|
75
|
+
klass.column_types[column_name.to_s]
|
76
|
+
end
|
77
|
+
elsif mongoid? klass
|
78
|
+
klass.fields[column_name.to_s].type
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def column_type(klass, column_name)
|
83
|
+
if active_record? klass
|
84
|
+
type_for_attribute(klass, column_name).type
|
85
|
+
elsif mongoid? klass
|
86
|
+
type_for_attribute(klass, column_name)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
%i[active_record? mongoid? tableless?].each do |method|
|
92
|
+
define_method method do
|
93
|
+
ActiveScaffold::OrmChecks.send method, active_record_class
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
%i[_table_name _quoted_table_name _columns _columns_hash _reflect_on_all_associations _content_columns].each do |method|
|
98
|
+
define_method method do
|
99
|
+
ActiveScaffold::OrmChecks.send method.to_s[1..-1], active_record_class
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
%i[type_for_attribute column_type].each do |method|
|
104
|
+
define_method method do |column_name|
|
105
|
+
ActiveScaffold::OrmChecks.send method, active_record_class, column_name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -9,12 +9,12 @@ module ActiveScaffold
|
|
9
9
|
return unless performed?
|
10
10
|
|
11
11
|
# Either pull out a redirect or the request body
|
12
|
-
script =
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
script = if response.headers['Location']
|
13
|
+
"document.location.href = '#{self.class.helpers.escape_javascript response.headers.delete('Location').to_s}'"
|
14
|
+
else
|
15
|
+
response.body || ''
|
16
16
|
end
|
17
|
-
response.status = 200 if (300...400).
|
17
|
+
response.status = 200 if (300...400).cover? response.status
|
18
18
|
|
19
19
|
# Eval in parent scope and replace document location of this frame
|
20
20
|
# so back button doesn't replay action on targeted forms
|
@@ -27,9 +27,6 @@ module ActiveScaffold
|
|
27
27
|
with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
|
28
28
|
</script></body></html>"
|
29
29
|
|
30
|
-
# We're returning HTML instead of JS or XML now
|
31
|
-
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
32
|
-
|
33
30
|
# Clear out the previous render to prevent double render and then render
|
34
31
|
if respond_to?(:erase_results, true)
|
35
32
|
erase_results
|
@@ -37,8 +34,13 @@ module ActiveScaffold
|
|
37
34
|
instance_variable_set(:@_response_body, nil)
|
38
35
|
end
|
39
36
|
|
40
|
-
|
37
|
+
# We're returning HTML instead of JS now
|
38
|
+
if Rails.version < '4.1'
|
39
|
+
render text: script, content_type: 'text/html' # remove when rails 4.0 is not supported
|
40
|
+
else
|
41
|
+
render html: script.html_safe, content_type: 'text/html' # rubocop:disable Rails/OutputSafety
|
42
|
+
end
|
41
43
|
end
|
42
|
-
|
44
|
+
alias respond_to_parent responds_to_parent
|
43
45
|
end
|
44
46
|
end
|
@@ -1,25 +1,29 @@
|
|
1
1
|
class ActiveScaffold::Tableless < ActiveRecord::Base
|
2
2
|
class AssociationScope < ActiveRecord::Associations::AssociationScope
|
3
|
-
def column_for(table_name, column_name, alias_tracker = nil)
|
4
|
-
klass = alias_tracker ? alias_tracker.connection.klass : self.klass
|
5
|
-
if table_name == klass.table_name
|
6
|
-
klass.columns_hash[column_name]
|
7
|
-
elsif alias_tracker && (klass = alias_tracker.instance_variable_get(:@assoc_klass))
|
8
|
-
klass.columns_hash[column_name]
|
9
|
-
else # rails < 4.1
|
10
|
-
association.klass.columns_hash[column_name]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
3
|
if defined?(ActiveRecord::Associations::AssociationScope::INSTANCE) # rails >= 4.1
|
15
4
|
INSTANCE = respond_to?(:create) ? create : new # create for rails >= 4.2
|
16
5
|
def self.scope(association, connection)
|
17
6
|
INSTANCE.scope association, connection
|
18
7
|
end
|
8
|
+
end
|
19
9
|
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
if Rails.version < '5.0.0'
|
11
|
+
def column_for(table_name, column_name, alias_tracker = nil)
|
12
|
+
klass = alias_tracker ? alias_tracker.connection.klass : self.klass
|
13
|
+
if table_name == klass.table_name
|
14
|
+
klass.columns_hash[column_name]
|
15
|
+
elsif alias_tracker && (klass = alias_tracker.instance_variable_get(:@assoc_klass))
|
16
|
+
klass.columns_hash[column_name]
|
17
|
+
else # rails < 4.1
|
18
|
+
association.klass.columns_hash[column_name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if Rails.version >= '4.1'
|
23
|
+
def add_constraints(scope, owner, assoc_klass, refl, tracker)
|
24
|
+
tracker.instance_variable_set(:@assoc_klass, assoc_klass)
|
25
|
+
super
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -30,10 +34,19 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
30
34
|
super(nil, *args)
|
31
35
|
@klass = klass
|
32
36
|
end
|
37
|
+
|
38
|
+
def columns(table_name)
|
39
|
+
klass.columns
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
class Column < ActiveRecord::ConnectionAdapters::Column
|
36
|
-
if
|
44
|
+
if Rails.version >= '5.0.0'
|
45
|
+
def initialize(name, default, sql_type = nil, null = true)
|
46
|
+
metadata = ActiveRecord::Base.connection.send :fetch_type_metadata, sql_type
|
47
|
+
super(name, default, metadata, null)
|
48
|
+
end
|
49
|
+
elsif Rails.version >= '4.2.0'
|
37
50
|
def initialize(name, default, sql_type = nil, null = true)
|
38
51
|
cast_type = ActiveRecord::Base.connection.send :lookup_cast_type, sql_type
|
39
52
|
super(name, default, cast_type, sql_type, null)
|
@@ -41,15 +54,10 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
44
|
-
module
|
45
|
-
def
|
46
|
-
base.alias_method_chain :association_scope, :tableless
|
47
|
-
base.alias_method_chain :target_scope, :tableless
|
48
|
-
end
|
49
|
-
|
50
|
-
def association_scope_with_tableless
|
57
|
+
module Tableless
|
58
|
+
def association_scope
|
51
59
|
@association_scope ||= overrided_association_scope if klass < ActiveScaffold::Tableless
|
52
|
-
|
60
|
+
super
|
53
61
|
end
|
54
62
|
|
55
63
|
def overrided_association_scope
|
@@ -60,8 +68,8 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
63
|
-
def
|
64
|
-
|
71
|
+
def target_scope
|
72
|
+
super.tap do |scope|
|
65
73
|
if klass < ActiveScaffold::Tableless
|
66
74
|
class << scope; include RelationExtension; end
|
67
75
|
end
|
@@ -69,30 +77,49 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
80
|
+
module Association
|
81
|
+
def self.included(base)
|
82
|
+
base.prepend Tableless
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
module TablelessCollectionAssociation
|
87
|
+
def get_records
|
88
|
+
klass < ActiveScaffold::Tableless ? scope.to_a : super
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
72
92
|
module CollectionAssociation
|
73
93
|
def self.included(base)
|
74
|
-
base.
|
94
|
+
base.prepend TablelessCollectionAssociation if Rails.version >= '4.2'
|
75
95
|
end
|
76
|
-
|
77
|
-
|
96
|
+
end
|
97
|
+
|
98
|
+
module TablelessSingularAssociation
|
99
|
+
def get_records
|
100
|
+
klass < ActiveScaffold::Tableless ? scope.limit(1).to_a : super
|
78
101
|
end
|
79
102
|
end
|
80
103
|
|
81
104
|
module SingularAssociation
|
82
105
|
def self.included(base)
|
83
|
-
base.
|
84
|
-
end
|
85
|
-
def get_records_with_tableless
|
86
|
-
klass < ActiveScaffold::Tableless ? scope.limit(1).to_a : get_records_without_tableless
|
106
|
+
base.prepend TablelessSingularAssociation
|
87
107
|
end
|
88
108
|
end
|
89
109
|
|
90
110
|
module RelationExtension
|
91
111
|
attr_reader :conditions
|
92
112
|
|
93
|
-
|
94
|
-
|
95
|
-
|
113
|
+
if Rails.version >= '5.0'
|
114
|
+
def initialize(klass, table, predicate_builder, values = {})
|
115
|
+
super
|
116
|
+
@conditions ||= []
|
117
|
+
end
|
118
|
+
else
|
119
|
+
def initialize(klass, table)
|
120
|
+
super
|
121
|
+
@conditions ||= []
|
122
|
+
end
|
96
123
|
end
|
97
124
|
|
98
125
|
def initialize_copy(other)
|
@@ -101,7 +128,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
101
128
|
end
|
102
129
|
|
103
130
|
def where(opts, *rest)
|
104
|
-
|
131
|
+
if opts.present?
|
105
132
|
opts = opts.with_indifferent_access if opts.is_a? Hash
|
106
133
|
@conditions << (rest.empty? ? opts : [opts, *rest])
|
107
134
|
end
|
@@ -140,7 +167,9 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
140
167
|
private
|
141
168
|
|
142
169
|
def relation
|
143
|
-
|
170
|
+
args = [self, arel_table]
|
171
|
+
args << predicate_builder if Rails.version >= '5.0.0'
|
172
|
+
ActiveScaffold::Tableless::Relation.new(*args)
|
144
173
|
end
|
145
174
|
end
|
146
175
|
|
@@ -162,17 +191,28 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
162
191
|
super
|
163
192
|
end
|
164
193
|
end
|
165
|
-
|
166
|
-
self.
|
194
|
+
if Rails.version >= '5.0'
|
195
|
+
def self.initialize_find_by_cache
|
196
|
+
@find_by_statement_cache = {
|
197
|
+
true => Hash.new { |h, k| h[k] = StatementCache.new(k) },
|
198
|
+
false => Hash.new { |h, k| h[k] = StatementCache.new(k) }
|
199
|
+
}
|
200
|
+
end
|
201
|
+
else
|
202
|
+
def self.initialize_find_by_cache
|
203
|
+
self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) }
|
204
|
+
end
|
167
205
|
end
|
168
206
|
end
|
169
207
|
|
170
208
|
def self.columns
|
171
209
|
@tableless_columns ||= []
|
172
210
|
end
|
211
|
+
|
173
212
|
def self.table_name
|
174
213
|
@table_name ||= ActiveModel::Naming.plural(self)
|
175
214
|
end
|
215
|
+
|
176
216
|
def self.table_exists?
|
177
217
|
true
|
178
218
|
end
|
@@ -210,12 +250,10 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
|
|
210
250
|
def _create_record #:nodoc:
|
211
251
|
run_callbacks(:create) {}
|
212
252
|
end
|
213
|
-
|
214
|
-
alias_method :create, :_create_record # for rails3
|
253
|
+
alias create_record _create_record # for rails4 < 4.0.6, < 4.1.2
|
215
254
|
|
216
255
|
def _update_record(*) #:nodoc:
|
217
256
|
run_callbacks(:update) {}
|
218
257
|
end
|
219
|
-
|
220
|
-
alias_method :update, :_update_record # for rails3
|
258
|
+
alias update_record _update_record # for rails4 < 4.0.6, < 4.1.2
|
221
259
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2
|
+
|
3
|
+
module ActiveScaffold
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Rails::Generators::NamedBase # metagenerator
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
check_class_collision :suffix => 'Controller'
|
11
|
+
|
12
|
+
class_option :orm, :banner => 'NAME', :type => :string, :required => true,
|
13
|
+
:desc => 'ORM to generate the controller for'
|
14
|
+
|
15
|
+
desc <<-DESC.strip_heredoc
|
16
|
+
Description:
|
17
|
+
Stubs out a active_scaffolded controller. Pass the model name,
|
18
|
+
either CamelCased or under_scored.
|
19
|
+
The controller name is retrieved as a pluralized version of the model
|
20
|
+
name.
|
21
|
+
|
22
|
+
To create a controller within a module, specify the model name as a
|
23
|
+
path like 'parent_module/controller_name'.
|
24
|
+
|
25
|
+
This generates a controller class in app/controllers and invokes helper,
|
26
|
+
template engine and test framework generators.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
`rails generate active_scaffold:controller CreditCard`
|
30
|
+
|
31
|
+
Credit card controller with URLs like /credit_card/debit.
|
32
|
+
Controller: app/controllers/credit_cards_controller.rb
|
33
|
+
Functional Test: test/functional/credit_cards_controller_test.rb
|
34
|
+
Helper: app/helpers/credit_cards_helper.rb
|
35
|
+
DESC
|
36
|
+
|
37
|
+
def create_controller_files
|
38
|
+
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
39
|
+
template 'helper.rb', File.join('app/helpers', class_path, "#{controller_file_name}_helper.rb")
|
40
|
+
end
|
41
|
+
|
42
|
+
hook_for :test_framework, :as => :scaffold
|
43
|
+
|
44
|
+
def create_view_root_folder
|
45
|
+
empty_directory File.join('app/views', controller_file_path)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
# require 'generators/active_scaffold_controller/active_scaffold_controller_generator'
|
3
|
+
|
4
|
+
module ActiveScaffold
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base # metagenerator
|
7
|
+
desc 'Add concerns to routes and require lines to assets manifest files'
|
8
|
+
|
9
|
+
def add_concern_routes
|
10
|
+
route 'concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)'
|
11
|
+
route 'concern :active_scaffold_association, ActiveScaffold::Routing::Association.new'
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_to_javascript_manifest
|
15
|
+
file = 'app/assets/javascripts/application.js'
|
16
|
+
unless File.exist?(file)
|
17
|
+
say_status :missing, file, :red
|
18
|
+
return if options[:pretend]
|
19
|
+
raise Thor::Error, "JS file #{file} is required for ActiveScaffold"
|
20
|
+
end
|
21
|
+
original_js = File.binread(file)
|
22
|
+
if original_js.include?('require active_scaffold')
|
23
|
+
say_status('skipped', 'insert into app/assets/javascripts/application.js', :yellow)
|
24
|
+
else
|
25
|
+
insert_into_file 'app/assets/javascripts/application.js', :after => %r{//= require +.*ujs['"]?\n} do
|
26
|
+
"//= require active_scaffold\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_to_stylesheet_manifest
|
32
|
+
file = 'app/assets/stylesheets/application.css'
|
33
|
+
return unless File.exist?(file)
|
34
|
+
original_css = File.binread(file)
|
35
|
+
if original_css =~ /require active_scaffold$/
|
36
|
+
say_status('skipped', 'insert into app/assets/stylesheets/application.css', :yellow)
|
37
|
+
else
|
38
|
+
insert_into_file 'app/assets/stylesheets/application.css', :before => %r{[ ]*\*/} do
|
39
|
+
" *= require active_scaffold\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|