[Gd-chatter] r10911 - in trunk: fundev/sources/system libraries/koala/sources/koala libraries/web-framework libraries/xml-parser
turbo24prg at gwydiondylan.org
turbo24prg at gwydiondylan.org
Sat Sep 30 14:26:27 CEST 2006
Author: turbo24prg
Date: Sat Sep 30 14:26:22 2006
New Revision: 10911
Modified:
trunk/fundev/sources/system/date.dylan
trunk/fundev/sources/system/library.dylan
trunk/libraries/koala/sources/koala/dsp.dylan
trunk/libraries/koala/sources/koala/library-unix.dylan
trunk/libraries/koala/sources/koala/library.dylan
trunk/libraries/koala/sources/koala/log.dylan
trunk/libraries/koala/sources/koala/response.dylan
trunk/libraries/koala/sources/koala/static-files.dylan
trunk/libraries/web-framework/changes.dylan
trunk/libraries/web-framework/library.dylan
trunk/libraries/xml-parser/simple-xml.dylan
Log:
Job: minor
* implemented format-date
* cleaned up dependencies
* fixed rss-2.0 support
Modified: trunk/fundev/sources/system/date.dylan
==============================================================================
--- trunk/fundev/sources/system/date.dylan (original)
+++ trunk/fundev/sources/system/date.dylan Sat Sep 30 14:26:22 2006
@@ -313,43 +313,126 @@
time-zone-offset: date-time-zone-offset(date))
end function clone-date;
-
///
+define table *short-day-of-week-names* = {
+ #"monday" => "Mon", #"tuesday" => "Tue",
+ #"wednesday" => "Wed", #"thursday" => "Thu",
+ #"friday" => "Fri", #"saturday" => "Sat",
+ #"sunday" => "Sun" };
+
+define table *day-of-week-names* = {
+ #"monday" => "Monday", #"tuesday" => "Tuesday",
+ #"wednesday" => "Wednesday", #"thursday" => "Thursday",
+ #"friday" => "Friday", #"saturday" => "Saturday",
+ #"sunday" => "Sunday" };
+
+define variable *short-month-names* =
+ #["Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+
+define variable *month-names* =
+ #["January", "February", "March", "April",
+ "May", "June", "July", "August", "September",
+ "October", "November", "December"];
define constant $digits = #['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
+define generic append (string :: <string>, appendant :: <object>)
+ => (result :: <string>);
+
+define method append (string :: <string>, appendant :: <string>)
+ => (result :: <string>);
+ string := concatenate(string, appendant);
+ string;
+end;
+
+define method append (string :: <string>, appendant :: <character>)
+ => (result :: <string>);
+ string := add!(string, appendant);
+ string;
+end;
+
+define method format-date (format :: <string>, date :: <date>)
+ => (date-string :: <string>);
+ let (year, month, day, hours, minutes, seconds,
+ day-of-week, time-zone-offset) = decode-date(date);
+ let absolute-time-zone-offset :: <integer> = abs(time-zone-offset);
+ local method wrap (wrap :: <string>, i :: <integer>) => (string :: <string>)
+ if (i < 10) concatenate(wrap, integer-to-string(i));
+ else integer-to-string(i) end;
+ end;
+ local method format-integer (integer :: <integer>, length :: <integer>) => (string :: <string>)
+ let string = make(<byte-string>, size: length, fill: '0');
+ for (position from 0 below length)
+ string[length - position - 1] := $digits[modulo(integer, 10)];
+ integer := floor/(integer, 10);
+ end;
+ string
+ end;
+ let date-string :: <string> = "";
+ let format? :: <boolean> = #f;
+ let use-dots? :: <boolean> = #f;
+ for (char in format)
+ if (char = '%' & ~ format?)
+ format? := #t;
+ elseif (char = ':' & format?)
+ use-dots? := #t;
+ elseif (format?)
+ date-string := append(date-string, select (char)
+ 'Y' => integer-to-string(year);
+ 'y' => format-integer(year, 2);
+ 'H' => wrap("0", hours);
+ 'k' => integer-to-string(hours);
+ 'M' => wrap("0", minutes);
+ 'S' => wrap("0", seconds);
+ 'm' => wrap("0", month);
+ 'd' => wrap("0", day);
+ 'e' => wrap(" ", day);
+ 'A' => *day-of-week-names*[day-of-week];
+ 'a' => *short-day-of-week-names*[day-of-week];
+ 'B' => *month-names*[month - 1];
+ 'b' => *short-month-names*[month - 1];
+ 'z' => concatenate(if (negative?(time-zone-offset))
+ "-" else "+"
+ end if, wrap("0", floor/(absolute-time-zone-offset, 60)),
+ if (use-dots?) ":" else "" end if,
+ wrap("0", modulo(absolute-time-zone-offset, 60)));
+ 'n' => '\n';
+ '%' => '%';
+ otherwise => char;
+ end select);
+ format? := #f;
+ use-dots? := #f;
+ else
+ date-string := append(date-string, char);
+ end if;
+ end for;
+ date-string;
+end;
+
+define function as-rfc822-string (date :: <date>)
+ => (rfc822-date :: <string>);
+ format-date("%a, %d %b %y %H:%M:%S %z", date);
+end;
+
+define function as-rfc1123-string (date :: <date>)
+ => (rfc822-date :: <string>);
+ format-date("%a, %d %b %Y %H:%M:%S %z", date);
+end;
+
define function as-iso8601-string (date :: <date>, #key precision :: <integer> = 0)
=> (iso8601-string :: <string>)
- local method format-integer (x :: <integer>, n :: <integer>) => (s :: <string>)
- let s = make(<byte-string>, size: n, fill: '0');
- for (i from 0 below n)
- s[n - i - 1] := $digits[modulo(x, 10)];
- x := floor/(x, 10);
- end;
- s
- end method format-integer;
- let old-tz = date-time-zone-offset(date);
- block ()
- date-time-zone-offset(date) := 0;
- concatenate(format-integer(date-year(date), 4),
- format-integer(date-month(date), 2),
- format-integer(date-day(date), 2),
- "T",
- format-integer(date-hours(date), 2),
- format-integer(date-minutes(date), 2),
- format-integer(date-seconds(date), 2),
- if (precision > 0)
+/*
+ if (precision > 0)
concatenate(".", format-integer(round/(date-microseconds(date),
10 ^ (6 - precision)),
precision))
else
""
- end,
- "Z")
- cleanup
- date-time-zone-offset(date) := old-tz;
- end
-end function as-iso8601-string;
+ end;
+*/
+ format-date("%Y-%m-%dT%H:%M:%S%:z", date);
+end;
///---*** Doesn't yet parse all legitimate forms of ISO 8601 strings.
///---*** For now, just parse a small superset of the strings produced above ...
Modified: trunk/fundev/sources/system/library.dylan
==============================================================================
--- trunk/fundev/sources/system/library.dylan (original)
+++ trunk/fundev/sources/system/library.dylan Sat Sep 30 14:26:22 2006
@@ -85,7 +85,10 @@
date-time-zone-offset, date-time-zone-offset-setter,
<day-of-week>,
date-day-of-week,
+ format-date,
as-iso8601-string,
+ as-rfc822-string,
+ as-rfc1123-string,
current-date,
current-timestamp,
local-time-zone-offset,
Modified: trunk/libraries/koala/sources/koala/dsp.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/dsp.dylan (original)
+++ trunk/libraries/koala/sources/koala/dsp.dylan Sat Sep 30 14:26:22 2006
@@ -1033,6 +1033,7 @@
scan-pos, end-tag);
block (return)
while (scan-pos < epos)
+
let tag-start :: false-or(<integer>) = char-position('<', buffer, scan-pos, epos);
if (~tag-start)
// put the remainder of the buffer in the template as a string.
Modified: trunk/libraries/koala/sources/koala/library-unix.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/library-unix.dylan (original)
+++ trunk/libraries/koala/sources/koala/library-unix.dylan Sat Sep 30 14:26:22 2006
@@ -128,7 +128,7 @@
log-error, log-warning, log-info, log-debug, log-debug-if, log-verbose, log-copious,
log, log-raw,
log-level, log-level-setter,
- as-common-logfile-date, as-rfc-1123-date;
+ as-common-logfile-date;
end module utilities;
Modified: trunk/libraries/koala/sources/koala/library.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/library.dylan (original)
+++ trunk/libraries/koala/sources/koala/library.dylan Sat Sep 30 14:26:22 2006
@@ -128,7 +128,7 @@
log-error, log-warning, log-info, log-debug, log-debug-if, log-verbose, log-copious,
log, log-raw,
log-level, log-level-setter,
- as-common-logfile-date, as-rfc-1123-date;
+ as-common-logfile-date;
end module utilities;
Modified: trunk/libraries/koala/sources/koala/log.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/log.dylan (original)
+++ trunk/libraries/koala/sources/koala/log.dylan Sat Sep 30 14:26:22 2006
@@ -171,32 +171,6 @@
end;
end;
-define method as-rfc-1123-date (date :: <date>) => (rfc1123-date :: <string>)
- //Tue, 15 Nov 1994 08:12:31 GMT
- let $month-names
- = #["Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
- date-time-zone-offset-setter(0, date);
- let (iyear, imonth, iday, ihours, iminutes, iseconds, dow) = decode-date(date);
- local method wrap0 (int :: <integer>) => (string :: <string>)
- if (int < 10)
- concatenate("0", integer-to-string(int));
- else
- integer-to-string(int);
- end if;
- end;
- let day-of-week = substring(as(<string>, dow), 0, 3);
- day-of-week[0] := as-uppercase(day-of-week[0]);
- let day = wrap0(iday);
- let month = $month-names[imonth - 1];
- let year = integer-to-string(iyear);
- let hours = wrap0(ihours);
- let minutes = wrap0(iminutes);
- let seconds = wrap0(iseconds);
- concatenate(day-of-week, ", ", day, " ", month, " ", year, " ",
- hours, ":", minutes, ":", seconds, " GMT");
-end method as-rfc-1123-date;
-
define method as-common-logfile-date (date :: <date>) => (common-logfile-date :: <string>)
let $month-names
= #["Jan", "Feb", "Mar", "Apr", "May", "Jun",
Modified: trunk/libraries/koala/sources/koala/response.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/response.dylan (original)
+++ trunk/libraries/koala/sources/koala/response.dylan Sat Sep 30 14:26:22 2006
@@ -195,7 +195,7 @@
if (generate-server-header?(*virtual-host*))
add-header(response, "Server", $server-header-value);
end if;
- add-header(response, "Date", as-rfc-1123-date(current-date()));
+ add-header(response, "Date", as-rfc1123-string(current-date()));
let content-length :: <string> = "0";
unless (response.response-code == $not-modified)
Modified: trunk/libraries/koala/sources/koala/static-files.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/static-files.dylan (original)
+++ trunk/libraries/koala/sources/koala/static-files.dylan Sat Sep 30 14:26:22 2006
@@ -170,7 +170,7 @@
add-header(response, "Content-Type", mime-type);
let props = file-properties(locator);
add-header(response, "Last-Modified",
- as-rfc-1123-date(props[#"modification-date"]));
+ as-rfc1123-string(props[#"modification-date"]));
//---TODO: optimize this
write(output-stream(response), stream-contents(in-stream));
end;
@@ -214,7 +214,7 @@
subdirectory-locator(locator-directory(locator), locator-name(locator)));
let directory-properties = file-properties(locator);
add-header(response, "Last-Modified",
- as-rfc-1123-date(directory-properties[#"modification-date"]));
+ as-rfc1123-string(directory-properties[#"modification-date"]));
let stream = output-stream(response);
local
method show-file-link (directory, name, type)
Modified: trunk/libraries/web-framework/changes.dylan
==============================================================================
--- trunk/libraries/web-framework/changes.dylan (original)
+++ trunk/libraries/web-framework/changes.dylan Sat Sep 30 14:26:22 2006
@@ -1,9 +1,9 @@
module: changes
author: Hannes Mehnert <hannes at mehnert.org>
-define class <feed> (<object>)
+define open class <feed> (<object>)
/* slot CommonAttributes */
- slot authors :: <list>,
+ slot authors :: <list> = #(),
init-keyword: authors:;
slot categories :: <list> = #(),
init-keyword: categories:;
@@ -28,13 +28,13 @@
slot updated :: <date>,
init-keyword: updated:;
/* repeated slot extensionElement */
- slot entries :: <list> = #(),
+ slot entries :: <string-table> = make(<string-table>),
init-keyword: entries:;
slot language :: <text>,
init-keyword: language:;
slot description :: <text>,
init-keyword: description:;
- slot published :: <date>,
+ slot published :: <date> = current-date(),
init-keyword: published:;
end;
@@ -67,18 +67,27 @@
init-keyword: title:;
slot updated :: false-or(<date>) = #f,
init-keyword: updated:;
- slot comments :: <list> = #(),
+ slot comments :: <table> = make(<table>),
init-keyword: comments:;
+ slot %comments-count :: <integer> = 0;
/* repeated slot extensionElement */
end;
+define method comments-count (entry :: <entry>)
+ => (res :: <integer>);
+ entry.%comments-count := entry.%comments-count + 1;
+ entry.%comments-count;
+end;
+
define class <comment> (<object>)
- slot commenter :: <string>,
- init-keyword: commenter:;
- slot email :: <email>,
- init-keyword: email:;
+ slot name :: <string>,
+ required-init-keyword: name:;
+ slot website :: false-or(<uri>) = #f,
+ init-keyword: website:;
slot content :: <content>,
- init-keyword: content:;
+ required-init-keyword: content:;
+ slot published :: <date> = current-date(),
+ init-keyword: published:;
end;
define abstract class <content> (<object>)
@@ -164,14 +173,17 @@
define generic generate-rss (object :: <object>);
define method generate-rss (feed :: <feed>)
with-xml-builder()
- rss (version => "2.0") {
+ rss (version => "2.0",
+ xmlns :: content => "http://purl.org/rss/1.0/modules/content/",
+ xmlns :: wfw => "http://wellformedweb.org/CommentAPI/",
+ xmlns :: dc => "http://purl.org/dc/elements/1.1/") {
channel {
title(feed.title),
link(first(feed.links)),
description(feed.description),
language(feed.language),
copyright(feed.rights),
- pubDate(as-iso8601-string(feed.published)),
+ pubDate(as-rfc822-string(feed.published)),
image {
url(feed.logo),
title(feed.title),
@@ -187,9 +199,10 @@
with-xml()
item {
title(entry.title),
- description(entry.content.content),
+ description(escape-xml(entry.content.content)),
link(entry.identifier),
- author("food00d")
+ guid(entry.identifier),
+ pubDate(as-iso8601-string(entry.published)),
}
end;
end method generate-rss;
Modified: trunk/libraries/web-framework/library.dylan
==============================================================================
--- trunk/libraries/web-framework/library.dylan (original)
+++ trunk/libraries/web-framework/library.dylan Sat Sep 30 14:26:22 2006
@@ -162,7 +162,8 @@
summary, summary-setter,
title, title-setter,
updated, updated-setter,
- comments, comments-setter;
+ comments, comments-setter,
+ comments-count;
export <category>,
term, term-setter,
@@ -185,7 +186,11 @@
<remove-command>,
<edit-command>;
- export <comment>;
+ export <comment>,
+ name, name-setter,
+ website, website-setter,
+ body, body-setter,
+ published, published-setter;
end;
Modified: trunk/libraries/xml-parser/simple-xml.dylan
==============================================================================
--- trunk/libraries/xml-parser/simple-xml.dylan (original)
+++ trunk/libraries/xml-parser/simple-xml.dylan Sat Sep 30 14:26:22 2006
@@ -177,7 +177,10 @@
=> { make(<attribute>, name: ?"key", value: ?value) }
{ ?key:name => ?value:expression, ... }
=> { make(<attribute>, name: ?"key", value: ?value), ... }
-
+ { ?ns:name :: ?key:name => ?value:expression }
+ => { make(<attribute>, name: concatenate(?"ns" ## ":", ?"key"), value: ?value) }
+ { ?ns:name :: ?key:name => ?value:expression, ... }
+ => { make(<attribute>, name: concatenate(?"ns" ## ":", ?"key"), value: ?value), ... }
end;
define method add-attribute (element :: <element>, attribute :: <attribute>)
More information about the chatter
mailing list