Skip to content

Commit

Permalink
Removed sys.conf; erldocs now accepts list of source paths and one de…
Browse files Browse the repository at this point in the history
…stination path
  • Loading branch information
dreverri committed Nov 28, 2010
1 parent 1f29c42 commit 32a2790
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 48 deletions.
15 changes: 0 additions & 15 deletions priv/sys.conf

This file was deleted.

49 changes: 18 additions & 31 deletions src/erldocs.erl
Expand Up @@ -3,44 +3,31 @@

%% @doc Called automatically by escript
-spec main(list()) -> ok.
main([]) ->
Conf = [{apps, ["."]}, {dest, "doc/erldocs"}],
run(Conf);

main([Dest]) ->
Conf = [{apps, ["."]}, {dest, Dest}],
run(Conf);

main(Args) ->
Conf = create_conf(Args),
main(Args, []).

main([Dest], Apps) ->
Conf = [{apps, Apps}, {dest, Dest}],
run(Conf);

main([App|Rest], Apps) ->
main(Rest, [App|Apps]).

run(Conf) ->
try erldocs_core:dispatch(Conf)
catch Type:Error ->
log("Error running script:~n~p~n~p~n",
[erlang:get_stacktrace(), {Type, Error}])
end.

-spec parse_options([string()]) -> [{atom(), _}].
parse_options(Args) ->
lists:flatmap(fun (Arg) -> parse_option(Arg) end, Args).

-spec parse_option(string()) -> [{atom(), _}].
parse_option("--sys-conf=" ++ Path) ->
[{sys_conf, Path}];
parse_option("--name=" ++ Name) ->
[{name, Name}];
parse_option(Unknown) ->
throw({unknown_option, Unknown}).

-spec getopt(atom(), [{atom(), _}], _) -> _.
getopt(Key, Opts, Default) ->
case lists:keyfind(Key, 1, Opts) of
false ->
Default;
{_, V} ->
V
end.

-spec create_conf([string()]) -> [{atom(), _}].
create_conf(Args) ->
Opts = parse_options(Args),
Path = getopt(sys_conf, Opts, "priv/sys.conf"),
{ok, [Config]} = file:consult(Path),
{erldocs, Conf} = lists:keyfind(erldocs, 1, Config),
{ok, Root} = file:get_cwd(),
Opts ++ [{root, Root} | Conf].

-spec log(string(), [_]) -> ok.
log(Str, Args) ->
io:format(Str, Args).
4 changes: 2 additions & 2 deletions src/erldocs_core.erl
Expand Up @@ -207,7 +207,7 @@ render(erlref, App, Mod, Xml, Conf) ->
|| X <- lists:reverse(Funs) ],

Args = [{base, "../"},
{title, Mod ++ " (" ++ App ++ ") - " ++ kf(name, Conf)},
{title, Mod ++ " (" ++ App ++ ") - "},
{content, xml_to_str(NXml)},
{funs, xml_to_str({ul, [{id, "funs"}], XmlFuns})}],

Expand Down Expand Up @@ -459,7 +459,7 @@ kf(Key, Conf) ->
%% @doc path to the destination folder
-spec dest(list()) -> list().
dest(Conf) ->
[kf(root, Conf), "/priv/www/", kf(name, Conf), "/"].
[kf(dest, Conf)].

bname(Name) ->
filename:basename(Name).
Expand Down

0 comments on commit 32a2790

Please sign in to comment.