| 1 |
# Copyright (c) 2006 Matthew Draper |
|---|
| 2 |
# Released under the MIT License. See the LICENSE file for more details. |
|---|
| 3 |
|
|---|
| 4 |
require 'auto_admin' |
|---|
| 5 |
|
|---|
| 6 |
class ActionController::Routing::RouteSet |
|---|
| 7 |
alias draw_without_admin draw |
|---|
| 8 |
def draw_with_admin |
|---|
| 9 |
draw_without_admin do |map| |
|---|
| 10 |
prefix = AutoAdmin::AutoAdminConfiguration.url_prefix rescue 'admin' |
|---|
| 11 |
map.connect "#{prefix}", :controller => 'auto_admin', :action => 'index' |
|---|
| 12 |
map.connect "#{prefix}/-/:action/:id", :controller => 'auto_admin', :action => 'index', |
|---|
| 13 |
:requirements => { :model => nil } |
|---|
| 14 |
map.connect "#{prefix}/asset/*path", :controller => 'auto_admin', :action => 'asset' |
|---|
| 15 |
|
|---|
| 16 |
map.connect "#{prefix}/:model/:action", :controller => 'auto_admin', :action => 'list', |
|---|
| 17 |
:requirements => { :action => /[^0-9].*/, :id => nil } |
|---|
| 18 |
map.connect "#{prefix}/:model/:id/:action", :controller => 'auto_admin', :action => 'edit', |
|---|
| 19 |
:requirements => { :id => /\d+/ } |
|---|
| 20 |
yield map |
|---|
| 21 |
end |
|---|
| 22 |
end |
|---|
| 23 |
alias draw draw_with_admin |
|---|
| 24 |
end |
|---|
| 25 |
|
|---|
| 26 |
class ::Object |
|---|
| 27 |
def to_label |
|---|
| 28 |
return label if respond_to? :label |
|---|
| 29 |
return name if respond_to? :name |
|---|
| 30 |
return to_s if respond_to? :to_s |
|---|
| 31 |
inspect |
|---|
| 32 |
end |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
# We want AssociationProxy to forward #to_label on to its target, but |
|---|
| 36 |
# because we're adding the above to Object after AssociationProxy |
|---|
| 37 |
# flushes its instance methods, we have to do it manually. |
|---|
| 38 |
ActiveRecord::Associations::AssociationProxy.send :undef_method, :to_label |
|---|
| 39 |
|
|---|
| 40 |
class ::Array; def to_label; map {|m| m.to_label }.join(', '); end; end |
|---|
| 41 |
class ::TrueClass; def to_label; 'Yes'; end; end |
|---|
| 42 |
class ::FalseClass; def to_label; 'No'; end; end |
|---|
| 43 |
class ::NilClass; def to_label; '(none)'; end; end |
|---|
| 44 |
|
|---|