Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Pages flavor #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/edown_doclet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ gen(Sources, App, Modules, Ctxt) ->
%% CSS = stylesheet(Options),
{Modules1, Error} = sources(Sources, Dir, Modules, Env, Options),
Data = overview(Dir, Title, Env, Options)
++ lists:concat([modules_frame(Modules1) || Modules1 =/= []]),
++ lists:concat([modules_frame(Modules1, Options) || Modules1 =/= []]),
Text = edown_lib:export(Data, Options),
write_file(Text, Dir, right_suffix(?INDEX_FILE, Options)),
write_info_file(App, Modules1, Dir),
Expand Down Expand Up @@ -169,12 +169,11 @@ target(Options) ->
%% make_top_level_README(Data, Dir, F, BaseHRef, Branch).

make_top_level_README(Data, Dir, F, BaseHRef, Branch, Options) ->
Target = target(Options),
Exp = [xmerl_lib:expand_element(D) || D <- Data],
New = [xmerl_lib:mapxml(
fun(#xmlElement{name = a,
attributes = Attrs} = E) ->
case redirect_href(Attrs, Branch, BaseHRef, Target) of
case redirect_href(Attrs, Branch, BaseHRef, Options) of
{true, Attrs1} ->
E#xmlElement{attributes = Attrs1};
false ->
Expand All @@ -186,7 +185,8 @@ make_top_level_README(Data, Dir, F, BaseHRef, Branch, Options) ->
Text = edown_lib:export(New, Options),
write_file(Text, Dir, F).

redirect_href(Attrs, Branch, BaseHRef, Target) ->
redirect_href(Attrs, Branch, BaseHRef, Options) ->
Target = target(Options),
{Prefix, URIArgs} = href_redirect_parts(Target, BaseHRef, Branch),
case lists:keyfind(href, #xmlAttribute.name, Attrs) of
false ->
Expand All @@ -198,12 +198,13 @@ redirect_href(Attrs, Branch, BaseHRef, Target) ->
{match, _} ->
false;
nomatch ->
Dir = proplists:get_value(dir, Options, "dir/"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the default be "doc/"?

case Href of
[$# | _] ->
HRef1 = do_redirect(?INDEX_FILE ++ Href,
Prefix, URIArgs);
Prefix, URIArgs, Dir);
_Else ->
HRef1 = do_redirect(Href, Prefix, URIArgs)
HRef1 = do_redirect(Href, Prefix, URIArgs, Dir)
end,
{true,
lists:keyreplace(
Expand All @@ -212,6 +213,8 @@ redirect_href(Attrs, Branch, BaseHRef, Target) ->
end
end.

href_redirect_parts(github_pages, BaseHRef, Branch) ->
{BaseHRef ++ "/blob/" ++ Branch ++ "/", ?DEFAULT_FILE_SUFFIX};
href_redirect_parts(github, BaseHRef, Branch) ->
{BaseHRef ++ "/blob/" ++ Branch ++ "/", []};
href_redirect_parts(stash, BaseHRef, Branch) ->
Expand All @@ -220,10 +223,10 @@ href_redirect_parts(gitlab, BaseHRef, Branch) ->
{BaseHRef ++ "/tree/" ++ Branch ++ "/", []}.


do_redirect(Href, Prefix, Args) ->
do_redirect(Href, Prefix, Args, Dir) ->
case filename:split(Href) of
[_] ->
Prefix ++ "doc/" ++ Href ++ Args;
Prefix ++ Dir ++ Href ++ Args;
_ ->
Prefix ++ Href ++ Args
end.
Expand Down Expand Up @@ -364,20 +367,26 @@ check_name(M, M0, File) ->
end
end.

modules_frame(Ms) ->
modules_frame(Ms, Options) ->
[{h2, [{class, "indextitle"}], ["Modules"]},
{table, [{width, "100%"}, {border, 0},
{summary, "list of modules"}],
lists:concat(
[[?NL,
{tr, [{td, [],
[{a, [{href, module_ref(M)},
[{a, [{href, module_ref(M, Options)},
{class, "module"}],
[atom_to_list(M)]}]}]}]
|| M <- Ms])}].

module_ref(M) ->
atom_to_list(M) ++ ?DEFAULT_FILE_SUFFIX.
module_ref(M, Options) ->
case target(Options) of
github_pages ->
atom_to_list(M);
_ ->
atom_to_list(M) ++ ?DEFAULT_FILE_SUFFIX
end.



%% NEW-OPTIONS: overview
Expand Down