PageRenderTime 7ms CodeModel.GetById 4ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/dylan/tag.dylan

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