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
|