/dylan/tag.dylan

http://github.com/cgay/wiki · Unknown · 47 lines · 40 code · 7 blank · 0 comment · 0 complexity · 17985f6497db315ef265467993641a97 MD5 · raw file

  1. Module: %wiki
  2. // Pages can have a set of tags associated with them, which are
  3. // arbitrary strings and are stored in the "categories" slot of
  4. // the <entry> superclass of <wiki-page>. The idea is apparently
  5. // to use them for search filters. e.g., there is some evidence
  6. // that the News sections of the wiki was going to be implemented
  7. // via <wiki:list-pages tags="news" order-by="published"/>.
  8. define wf/object-test (tag) in wiki end;
  9. define function parse-tags
  10. (tag-string :: <string>) => (tags :: <sequence>)
  11. choose(complement(empty?),
  12. remove-duplicates!(map(strip, split(tag-string, ",")), test: \=));
  13. end;
  14. define function unparse-tags
  15. (tags :: <sequence>) => (tags :: <string>)
  16. join(tags, ", ")
  17. end;
  18. define tag show-tag in wiki
  19. (page :: <wiki-dsp>)
  20. ()
  21. if (*tag*)
  22. output("%s", escape-xml(*tag*));
  23. end if;
  24. end;
  25. define named-method query-tagged? in wiki
  26. (page :: <wiki-dsp>)
  27. get-query-value("tagged");
  28. end;
  29. define body tag list-query-tags in wiki
  30. (page :: <wiki-dsp>, do-body :: <function>)
  31. ()
  32. let tagged = get-query-value("tagged");
  33. if (instance?(tagged, <string>))
  34. for (tag in parse-tags(tagged))
  35. dynamic-bind(*tag* = tag)
  36. do-body();
  37. end;
  38. end for;
  39. end if;
  40. end;