scaffolding_extensions 1.1.8 → 1.1.9
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.
@@ -48,9 +48,9 @@ module ScaffoldingExtensions
|
|
48
48
|
def scaffold_redirect(action, suffix, notice=nil, oid=nil)
|
49
49
|
action_suffix = "#{action}#{suffix}"
|
50
50
|
meth = "scaffold_#{action_suffix}_redirect"
|
51
|
-
return send(meth, notice) if respond_to?(meth)
|
51
|
+
return send(meth, notice) if respond_to?(meth, true)
|
52
52
|
meth = "scaffold_#{action}_redirect"
|
53
|
-
return send(meth, suffix, notice) if respond_to?(meth)
|
53
|
+
return send(meth, suffix, notice) if respond_to?(meth, true)
|
54
54
|
scaffold_flash[:notice] = notice if notice
|
55
55
|
scaffold_redirect_to(scaffold_url(action_suffix, oid ? {:id=>oid} : {}))
|
56
56
|
end
|
@@ -48,6 +48,8 @@ module ScaffoldingExtensions::MetaModel
|
|
48
48
|
# for fields of type text (iv: @scaffold_convert_text_to_string)
|
49
49
|
# - :table_classes: Set the default table classes for different scaffolded HTML tables
|
50
50
|
# (iv: @scaffold_table_classes)
|
51
|
+
# - :column_type_options: Override the default options for a given column type
|
52
|
+
# (iv: @scaffold_column_type_options)
|
51
53
|
# - :column_types: Override the default column type for a given attribute
|
52
54
|
# (iv: @scaffold_column_types)
|
53
55
|
# - :column_options: Override the default column options for a given attribute
|
@@ -71,6 +73,7 @@ module ScaffoldingExtensions::MetaModel
|
|
71
73
|
# autocompleter (iv: @scaffold_auto_complete_options)
|
72
74
|
SCAFFOLD_OPTIONS = {:text_to_string=>false,
|
73
75
|
:table_classes=>{:form=>'formtable', :list=>'sortable', :show=>'sortable'},
|
76
|
+
:column_type_options=>{},
|
74
77
|
:column_types=>{},
|
75
78
|
:column_options=>{},
|
76
79
|
:association_list_class=>''.freeze,
|
@@ -220,8 +223,10 @@ module ScaffoldingExtensions::MetaModel
|
|
220
223
|
# @scaffold_column_names, a hash with the column name as a symbol key and the human name
|
221
224
|
# string as the value.
|
222
225
|
def scaffold_column_name(column_name)
|
223
|
-
@scaffold_column_names ||=
|
224
|
-
@scaffold_column_names[column_name] ||= if
|
226
|
+
@scaffold_column_names ||= {}
|
227
|
+
@scaffold_column_names[column_name] ||= if n = SCAFFOLD_OPTIONS[:column_names][column_name]
|
228
|
+
n
|
229
|
+
elsif scaffold_association(column_name)
|
225
230
|
scaffold_associated_human_name(column_name)
|
226
231
|
else
|
227
232
|
column_name.to_s.humanize
|
@@ -232,8 +237,9 @@ module ScaffoldingExtensions::MetaModel
|
|
232
237
|
# @scaffold_column_options_hash, a hash with the column name as a symbol key and the html
|
233
238
|
# options hash as the value.
|
234
239
|
def scaffold_column_options(column_name)
|
235
|
-
@scaffold_column_options_hash ||=
|
236
|
-
@
|
240
|
+
@scaffold_column_options_hash ||= {}
|
241
|
+
@scaffold_column_options ||= {}
|
242
|
+
@scaffold_column_options[column_name] ||= scaffold_merge_hashes(@scaffold_column_options_hash[column_name], SCAFFOLD_OPTIONS[:column_options][column_name], scaffold_column_type_options(scaffold_column_type(column_name)))
|
237
243
|
end
|
238
244
|
|
239
245
|
# Returns the column type for the given scaffolded column name. Can be set via the instance
|
@@ -241,8 +247,8 @@ module ScaffoldingExtensions::MetaModel
|
|
241
247
|
# type symbol as a value. Associations have the :association type, and other types are looked
|
242
248
|
# up via columns_hash[column_name].type. If no type is provided, :string is used by default.
|
243
249
|
def scaffold_column_type(column_name)
|
244
|
-
@scaffold_column_types ||=
|
245
|
-
if type =
|
250
|
+
@scaffold_column_types ||= {}
|
251
|
+
@scaffold_column_types[column_name] ||= if type = SCAFFOLD_OPTIONS[:column_types][column_name]
|
246
252
|
type
|
247
253
|
elsif scaffold_association(column_name)
|
248
254
|
:association
|
@@ -253,6 +259,15 @@ module ScaffoldingExtensions::MetaModel
|
|
253
259
|
end
|
254
260
|
end
|
255
261
|
|
262
|
+
# The HTML options for a given column type, affecting all columns of that type.
|
263
|
+
# Can be set with the @scaffold_column_type_options instance variable, which should
|
264
|
+
# be a hash with the column type as a symbol key and the html options hash
|
265
|
+
# as the value.
|
266
|
+
def scaffold_column_type_options(type)
|
267
|
+
@scaffold_column_type_options ||= {}
|
268
|
+
@scaffold_column_type_options[type] ||= SCAFFOLD_OPTIONS[:column_type_options][type] || {}
|
269
|
+
end
|
270
|
+
|
256
271
|
# Returns the foreign key for the field if it is an association, or the field
|
257
272
|
# as a string if it is not.
|
258
273
|
def scaffold_field_id(field)
|
@@ -445,8 +460,8 @@ module ScaffoldingExtensions::MetaModel
|
|
445
460
|
# the instance variable @scaffold_table_classes, a hash with the type as the symbol key
|
446
461
|
# and the value as the html class string.
|
447
462
|
def scaffold_table_class(type)
|
448
|
-
@scaffold_table_classes ||=
|
449
|
-
@scaffold_table_classes[type]
|
463
|
+
@scaffold_table_classes ||= {}
|
464
|
+
@scaffold_table_classes[type] ||= SCAFFOLD_OPTIONS[:table_classes][type]
|
450
465
|
end
|
451
466
|
|
452
467
|
# Run the block inside a database transaction
|
@@ -548,6 +563,14 @@ module ScaffoldingExtensions::MetaModel
|
|
548
563
|
scaffold_associated_class(association).scaffold_include(:association)
|
549
564
|
end
|
550
565
|
|
566
|
+
# Merge all given hashes in order of preference, so earlier hashes are considered more important.
|
567
|
+
# A nil value is treated the same as the empty hash.
|
568
|
+
def scaffold_merge_hashes(*hashes)
|
569
|
+
h = {}
|
570
|
+
hashes.reverse.each{|hash| h.merge!(hash) if hash}
|
571
|
+
h
|
572
|
+
end
|
573
|
+
|
551
574
|
# Condition to ensure field is not NULL
|
552
575
|
def scaffold_notnull_condition(field)
|
553
576
|
["#{scaffold_table_name}.#{field} IS NOT NULL"]
|
@@ -15,7 +15,7 @@ module ScaffoldingExtensions
|
|
15
15
|
def scaffold_method_iv_override(m, action)
|
16
16
|
return nil unless action
|
17
17
|
meth = "scaffold_#{action}_#{m}"
|
18
|
-
if respond_to?(meth)
|
18
|
+
if respond_to?(meth, true)
|
19
19
|
Proc.new{send(meth)}
|
20
20
|
elsif instance_variables.include?(meth = "@#{meth}")
|
21
21
|
Proc.new{instance_variable_get(meth)}
|
@@ -27,7 +27,7 @@ module ScaffoldingExtensions
|
|
27
27
|
def scaffold_method_override(m, action, *args)
|
28
28
|
return nil unless action
|
29
29
|
meth = "scaffold_#{action}_#{m}"
|
30
|
-
Proc.new{send(meth, *args)} if respond_to?(meth)
|
30
|
+
Proc.new{send(meth, *args)} if respond_to?(meth, true)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -24,8 +24,8 @@ class Test::Unit::TestCase
|
|
24
24
|
# Test that getting all display actions for the scaffold returns success
|
25
25
|
def scaffold_test(model, options = {})
|
26
26
|
klass = @controller.class
|
27
|
-
methods = options[:only] ? klass.scaffold_normalize_options
|
28
|
-
methods -= klass.scaffold_normalize_options
|
27
|
+
methods = options[:only] ? klass.send(:scaffold_normalize_options, options[:only]) : ScaffoldingExtensions::DEFAULT_METHODS
|
28
|
+
methods -= klass.send(:scaffold_normalize_options, options[:except]) if options[:except]
|
29
29
|
methods.each do |action|
|
30
30
|
assert_nothing_raised("Error requesting scaffolded action #{action} for model #{model.name}") do
|
31
31
|
get "#{action}_#{model.scaffold_name}", nil, scaffold_session
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffolding_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|