myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2126] trunk: added model aliases to config file


From: noreply
Subject: [myexperiment-hackers] [2126] trunk: added model aliases to config file
Date: Wed, 18 Mar 2009 09:55:47 -0400 (EDT)

Revision
2126
Author
dgc
Date
2009-03-18 09:55:47 -0400 (Wed, 18 Mar 2009)

Log Message

added model aliases to config file

Modified Paths

Diff

Modified: trunk/app/helpers/application_helper.rb (2125 => 2126)


--- trunk/app/helpers/application_helper.rb	2009-03-17 14:28:04 UTC (rev 2125)
+++ trunk/app/helpers/application_helper.rb	2009-03-18 13:55:47 UTC (rev 2126)
@@ -880,37 +880,46 @@
   end
   
   def visible_name(entity)
+
+    # Accept a string, the class object of a model or an instance of a model
+
     if (entity.instance_of?(String))
-      type = entity
+      name = entity
     elsif (entity.class == Class)
-      type = entity.to_s
+      name = entity.to_s
     else
-      type = entity.class.to_s
+      name = entity.class.to_s
     end
 
-    case type
-      when "Blob"
-        return "File"
-      when "Network"
-        return "Group"
-      else
-        return type
+    # special case for a Session object, though I'm not convinced that it's
+    # still used anywhere (Don)
+
+    exit if name == "Session"
+
+    # substitute model alias in singular form
+
+    if Conf.model_aliases.value?(name)
+      Conf.model_aliases.each do |al, model|
+        name = al if name == model
+      end
     end
+        
+    name
   end
   
   def controller_visible_name(humanized_controller_for)
-    case humanized_controller_for
-    when "Blobs"
-      return "Files"
-    when "Networks"
-      return "Groups"
-    when "Simple pages"
-      return "Info"
-    when "Session"
-      return "Log in"
-    else
-      return humanized_controller_for
+
+    # special case for Session, though I don't think it's needed any more (Don)
+
+    return "Log in" if humanized_controller_for == "Session"
+
+    # substitute model alias in plural form
+
+    Conf.model_aliases.each do |al, model|
+      humanized_controller_for = al.pluralize if humanized_controller_for == model.pluralize
     end
+
+    humanized_controller_for
   end
 
   def sharing_mode_text(contributable, mode)

Modified: trunk/lib/conf.rb (2125 => 2126)


--- trunk/lib/conf.rb	2009-03-17 14:28:04 UTC (rev 2125)
+++ trunk/lib/conf.rb	2009-03-18 13:55:47 UTC (rev 2126)
@@ -47,6 +47,10 @@
     @vars['search_categories']
   end
 
+  def self.model_aliases
+    @vars['model_aliases']
+  end
+
   # This method is required to create an administrator in the test fixtures
 
   def self.admins=(value)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]