logo       


r9959 - trunk/libraries/koala/sources/examples/buddha: msg#00018

Subject: r9959 - trunk/libraries/koala/sources/examples/buddha
Author: hannes
Date: Tue Sep  6 15:44:15 2005
New Revision: 9959

Modified:
   trunk/libraries/koala/sources/examples/buddha/buddha.dylan
   trunk/libraries/koala/sources/examples/buddha/class-browser.dylan
Log:
Bug: 7257
*enhanced class-browser to call generic function
  show(obj :: <object>, name :: <string>) instead of using
  one big if..elseif..elseif..end statement
*moved get-reference to buddha.dylan, because $obj-table is
  also defined there...


Modified: trunk/libraries/koala/sources/examples/buddha/buddha.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/buddha.dylan  (original)
+++ trunk/libraries/koala/sources/examples/buddha/buddha.dylan  Tue Sep  6 
15:44:15 2005
@@ -47,7 +47,6 @@
 define page browse end;
 
 
-
 define macro with-buddha-template
   { with-buddha-template(?stream:variable, ?title:expression)
       ?body:*
@@ -100,6 +99,14 @@
     end;
   end;
 end;
+
+define method get-reference (object :: <object>) => (res :: <string>)
+  let address = copy-sequence(format-to-string("%=", address-of(object)),
+                              start: 1);
+  $obj-table[address] := object;
+  address;
+end;
+
 
 define method respond-to-get
     (page == #"save", request :: <request>, response :: <response>)

Modified: trunk/libraries/koala/sources/examples/buddha/class-browser.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/class-browser.dylan   
(original)
+++ trunk/libraries/koala/sources/examples/buddha/class-browser.dylan   Tue Sep 
 6 15:44:15 2005
@@ -1,110 +1,78 @@
 module: buddha
 
-/*
-define method browse (s, o, os)
-  map(method(x)
-          with-xml()
-            li{ a("fpp", href => "/") }
-          end;
-      end, range(to: 10));
-//  make(<element>, name: "foo");
-end;*/
-
-define method get-reference (object :: <object>) => (res :: <string>)
-  let address = copy-sequence(format-to-string("%=", address-of(object)),
-                              start: 1);
-  $obj-table[address] := object;
-  address;
-end;
 
 define method browse (object :: <object>) => (res :: <list>)
   let class = object.object-class;
   let res = make(<list>);
   for (slot in class.slot-descriptors)
     if (slot-initialized?(object, slot))
+      let slot-object = slot.slot-getter(object);
       let name = slot.slot-getter.debug-name;
-      let type = slot.slot-type;
-      if (type = <string>)
-        res := add!(res,
-                    with-xml()
-                      li(concatenate(name,
-                                     ": ",
-                                     slot.slot-getter(object)))
-                    end);
-      elseif (subtype?(type, <sequence>))
-        for (ele in slot.slot-getter(object),
-             i from 0)
-          res := add!(res,
-                      with-xml ()
-                        li{ a(concatenate(name, " ",
-                                          integer-to-string(i)),
-                              href => concatenate("/browse?obj=",
-                                                  get-reference(ele))) }
-                      end);
-        end;
-      elseif (type = <table>)
-        for (ele in slot.slot-getter(object),
-             i in slot.slot-getter(object).key-sequence)
-          res := add!(res,
-                      with-xml()
-                        li{ a(format-to-string("%s %=", name, i),
-                              href => concatenate("/browse?obj=",
-                                                  get-reference(ele))) }
-                      end);
-        end;
-      elseif (type = <integer>)
-        res := add!(res,
-                    with-xml()
-                      li(concatenate
-                           (name,
-                            ": ",
-                            integer-to-string(slot.slot-getter(object))))
-                    end);
-      elseif (type = <boolean>)  
-        res := add!(res,
-                    with-xml()
-                      li(concatenate(name,
-                                     ": ",
-                                     if (slot.slot-getter(object))
-                                       "true"
-                                     else
-                                       "false"
-                                     end))
-                    end);
-      else 
-        let string = format-to-string("%= %=", name, slot.slot-getter(object));
-        res := add!(res, with-xml()
-                           li {
-                               a(string,
-                                 href => concatenate
-                                   ("/browse?obj=",
-                                    get-reference(slot.slot-getter(object)))) }
-                         end);
-      end;
+      res := concatenate(res, show(slot-object, name));
     end;
   end;
   res;
 end;
 
-define method find-slot (slot-name :: <string>, object :: <object>)
-  => (slot)
-  let class = object.object-class;
-  let number = #f;
-  if (any?(method(x) x = '[' end, slot-name))
-    let (all, real-slot-name, element-number)
-      = regexp-match(slot-name, "(.*)\\[(.*)\\]");
-    slot-name := real-slot-name;
-    number := string-to-integer(element-number);
+define method show (object :: <string>, slot-name :: <string>)
+  list(with-xml()
+         li(concatenate(slot-name, ": ", object))
+       end)
+end;
+
+define method show (object :: <sequence>, slot-name :: <string>)
+  let res = make(<list>);
+  for (ele in object,
+       i from 0)
+    res := add!(res,
+                with-xml ()
+                  li{ a(concatenate(slot-name, " ",
+                                    integer-to-string(i)),
+                        href => concatenate("/browse?obj=",
+                                            get-reference(ele))) }
+                end);
   end;
-  block (found)
-    for (slot in class.slot-descriptors)
-      if (slot.slot-getter.debug-name = slot-name)
-        if (number)
-          found(slot.slot-getter(object)[number]);
-        else
-          found(slot.slot-getter(object));
-        end;
-      end;
-    end;
+  res;
+end;
+
+define method show (object :: <table>, slot-name :: <string>)
+  let res = make(<list>);
+  for (ele in object,
+       i in object.key-sequence)
+    res := add!(res,
+                with-xml()
+                  li{ a(format-to-string("%s %=", slot-name, i),
+                        href => concatenate("/browse?obj=",
+                                            get-reference(ele))) }
+                end);
   end;
-end;
\ No newline at end of file
+  res;
+end;
+
+define method show (object :: <integer>, slot-name :: <string>)
+  list(with-xml()
+         li(concatenate(slot-name, ": ",
+                        integer-to-string(object)))
+       end)
+end;
+
+define method show (object :: <boolean>, slot-name :: <string>)
+  list(with-xml()
+         li(concatenate(slot-name, ": ",
+                        if (object)
+                          "true"
+                        else
+                          "false"
+                        end))
+       end)
+end;
+
+define method show (object :: <object>, slot-name :: <string>)
+  let string = format-to-string("%= %=", slot-name, object);
+  list(with-xml()
+         li { a(string,
+                href => concatenate("/browse?obj=",
+                                    get-reference(object)))
+               }
+       end)
+end;
-- 
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
https://gauss.gwydiondylan.org/mailman/listinfo/gd-chatter



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe