PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/dylan/feed.dylan

http://github.com/cgay/wiki
Unknown | 103 lines | 93 code | 10 blank | 0 comment | 0 complexity | 84e70f4c18e4241976ec88d3022ec0e7 MD5 | raw file
  1Module: %wiki
  2
  3/*
  4TODO...
  5
  6define method atom-feed-responder
  7    (#key type, name)
  8  let name = name & percent-decode(name);
  9  let (changes, description)
 10    = select (type by \=)
 11        "users" =>
 12          values(wiki-changes(change-type: <wiki-user-change>, name: name),
 13                 iff(name, concatenate("user ", name), "all users"));
 14        "groups" =>
 15          values(wiki-changes(change-type: <wiki-group-change>, name: name),
 16                 iff(name, concatenate("group ", name), "all groups"));
 17        "pages" =>
 18          values(wiki-changes(change-type: <wiki-page-change>, name: name),
 19                 iff(name, concatenate("page ", name), "all pages"));
 20        "tags" =>
 21          values(wiki-changes(change-type: <wiki-page-change>, tag: name),
 22                 iff(name, concatenate("pages tagged ", name), "all pages"));
 23        otherwise =>
 24          values(wiki-changes(), "");
 25      end;
 26  if (~empty?(description))
 27    description := concatenate(" to ", description);
 28  end;
 29  let changes = sort(changes,
 30                     test: method (change1, change2)
 31                             change1.creation-date > change2.creation-date
 32                           end);
 33  let date-updated = iff(empty?(changes),
 34                         current-date(),
 35                         changes.first.creation-date);
 36  let feed-authors = #[];
 37  for (change in changes)
 38    for (author in change.authors)
 39      feed-authors := add-new!(feed-authors, author, test: \=);
 40    end for;
 41  end for;
 42  let feed = make(<feed>,
 43                  generator: make(<generator>,
 44                                  text: *site-name*,
 45                                  version: $wiki-version,
 46                                  uri: *site-url*),
 47                  title: *site-name*,
 48                  subtitle: concatenate("Recent changes", description),
 49                  updated: date-updated,
 50                  author: feed-authors,
 51                  categories: #[]);
 52  let url = current-request().request-url;
 53  feed.identifier := url;
 54  feed.links["self"] := make(<link>, rel: "self", href: url);
 55
 56  set-header(current-response(), "Content-Type", "application/atom+xml");
 57  output("%s", generate-atom(feed, entries: changes));
 58end method atom-feed-responder;
 59
 60define method generate-atom (change :: <wiki-change>, #key)
 61  // todo -- enforce at least one author when any <entry> is created.
 62  let authors = change.authors;
 63  let author = ~empty?(authors) & find-user(first(authors));
 64  with-xml()
 65    entry { 
 66      title(change.title),
 67//      do(do(method(x) collect(generate-atom(x)) end, entry.links)),
 68      id(build-uri(change-identifier(change))),
 69      published(generate-atom(change.creation-date)),
 70      updated(generate-atom(change.creation-date)),
 71      do(if (author) generate-atom(author) end if),
 72//      do(do(method(x) collect(generate-atom(x)) end, entry.contributors)),
 73      do(collect(generate-atom(change.comments[0].content)))
 74    } //missing: category, summary
 75  end;
 76end;
 77
 78define sideways method generate-atom (user :: <wiki-user>, #key)
 79  with-xml()
 80    author {
 81      name(user.user-name),
 82      uri(build-uri(permanent-link(user)))
 83    }
 84  end;
 85end;
 86
 87
 88define method change-identifier (change :: <wiki-page-change>)
 89  let location = page-permanent-link(change.title);
 90  push-last(location.uri-path, "versions");
 91  push-last(location.uri-path, integer-to-string(change.change-version));
 92  location;
 93end;
 94
 95define method change-identifier (change :: <wiki-group-change>)
 96  group-permanent-link(change.title)
 97end;
 98
 99define method change-identifier (change :: <wiki-user-change>)
100  user-permanent-link(change.title)
101end;
102*/
103