Permalink
Browse files

Prefix overrides with record class name, it fixes #77

  • Loading branch information...
1 parent 4c7c166 commit 8d60d2bda5b67086aa7e9f2db4efc26a7995e3d8 scambra committed Jul 21, 2010
@@ -256,24 +256,27 @@ def override_subform_partial(column, subform_partial)
File.join(active_scaffold_controller_for(column.association.klass).controller_path, subform_partial) if column_renders_as(column) == :subform
end
- def override_form_field_partial?(column)
- path, partial_name = partial_pieces(override_form_field_partial(column))
+ def override_form_field_partial?(column, old = false)
+ path, partial_name = partial_pieces(override_form_field_partial(column, old))
template_exists?(File.join(path, "_#{partial_name}"), true)
end
- # the naming convention for overriding form fields with partials
- def override_form_field_partial(column)
- "#{column.name}_form_column"
- end
-
- def override_form_field?(column)
- respond_to?(override_form_field(column))
+ def override_form_field(column)
+ method = override_form_field_name(column)
+ return method if respond_to?(method)
+ old_method = override_form_field_name(column, true)
+ if respond_to?(old_method)
+ ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}")
+ old_method
+ end
end
+ alias_method :override_form_field?, :override_form_field
# the naming convention for overriding form fields with helpers
- def override_form_field(column)
- "#{column.name}_form_column"
+ def override_form_field_name(column, old = false)
+ "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_form_column"
end
+ alias_method :override_form_field_partial, :override_form_field_name
def override_input?(form_ui)
respond_to?(override_input(form_ui))
@@ -287,6 +290,10 @@ def override_input(form_ui)
def form_partial_for_column(column)
if override_form_field_partial?(column)
override_form_field_partial(column)
+ # try old override partial naming
+ elsif override_form_field_partial?(column, true)
+ ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the partial #{override_form_field_partial(column)} instead of #{override_form_field_partial(column, true)}")
+ override_form_field_partial(column, true)
elsif column_renders_as(column) == :field or override_form_field?(column)
"form_attribute"
elsif column_renders_as(column) == :subform
@@ -134,13 +134,20 @@ def active_scaffold_column_checkbox(column, record)
end
end
- def column_override(column)
- "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227)
+ def column_override_name(column, old = false)
+ "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_column"
end
- def column_override?(column)
- respond_to?(column_override(column))
+ def column_override(column)
+ method = column_override_name(column)
+ return method if respond_to?(method)
+ old_method = column_override_name(column, true)
+ if respond_to?(old_method)
+ ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}")
+ old_method
+ end
end
+ alias_method :column_override?, :column_override
def override_column_ui?(list_ui)
respond_to?(override_column_ui(list_ui))
@@ -200,13 +200,20 @@ def active_scaffold_search_time(column, options)
## Search column override signatures
##
- def override_search_field?(column)
- respond_to?(override_search_field(column))
+ def override_search_field(column)
+ method = override_search_field_name(column)
+ return method if respond_to?(method)
+ old_method = override_search_field_name(column, true)
+ if respond_to?(old_method)
+ ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}")
+ old_method
+ end
end
+ alias_method :override_search_field?, :override_search_field
# the naming convention for overriding form fields with helpers
- def override_search_field(column)
- "#{column.name}_search_column"
+ def override_search_field_name(column, old = false)
+ "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_search_column"
end
def override_search?(search_ui)
@@ -25,13 +25,20 @@ def active_scaffold_show_text(column, record)
simple_format(clean_column_value(record.send(column.name)))
end
- def show_column_override(column)
- "#{column.name.to_s.gsub('?', '')}_show_column" # parse out any question marks (see issue 227)
+ def show_column_override_name(column, old = false)
+ "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_show_column"
end
- def show_column_override?(column)
- respond_to?(show_column_override(column))
+ def show_column_override(column)
+ method = show_column_override_name(column)
+ return method if respond_to?(method)
+ old_method = show_column_override_name(column, true)
+ if respond_to?(old_method)
+ ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}")
+ old_method
+ end
end
+ alias_method :show_column_override?, :show_column_override
def override_show_column_ui?(list_ui)
respond_to?(override_show_column_ui(list_ui))
@@ -217,6 +217,14 @@ def column_show_add_new(column, associated, record)
def controller_class
"#{h params[:controller]}-view"
end
+
+ def clean_column_name(name)
+ name.to_s.gsub('?', '')
+ end
+
+ def clean_class_name(name)
+ name.underscore.gsub('/', '_')
+ end
end
end
end

0 comments on commit 8d60d2b

Please sign in to comment.