1-module(wiki_plugin_menu).
2
3%%% File    : wiki_plugin_menu.erl
4%%% Author  : Mickal Remond <mickael.remond@erlang-fr.org>
5%%% Description : Allows the selection and display of a menu Links are
6%%%               selected base on first word of the page name (Menu,
7%%%               Category, ...). The other part of the title is the
8%%%               name of the menu entry.
9%%% Created : 22 Oct 2003 by Mickael Remond
10%%%                          <mickael.remond@erlang-fr.org>
11
12-export([run/2]).
13
14run(_Page, ArgList) ->
15    %% TODO: Fixme
16    %% This is working if there is only one virtual server.
17    %% A way to handle this cleanly is needed.
18    {ok, _Gconf, [[Sconf|_Others]]} = yaws_api:getconf(),
19    Root = yaws:sconf_docroot(Sconf),
20
21    Prefix = get_prefix(ArgList),
22
23    %% Get all page starting with a given word
24    Pages = wiki_utils:getpages_by_prefix(Prefix, Root),
25
26    lists:map(fun(F) ->
27                [wiki_to_html:format_menu_link(Prefix, F, Root),"<br>"] end,
28        Pages).
29
30
31%% Get the category to use in the menu If not passed as parameter, use
32%% "Category"
33%% Be careful: plugin syntax is for the moment case sensitive
34get_prefix(ArgList) ->
35    case lists:keysearch("prefix", 1, ArgList) of
36        {value, {"prefix", Prefix}} ->
37            Prefix;
38        _Other ->
39            "Category"
40    end.
41
42%% TODO: is it relevant to be able to handle several category in
43%% the menu ?
44