Permalink
Browse files

include apps in index

  • Loading branch information...
1 parent 6a5e3ed commit 5fc3e1e6265cb65110481098008fcbe76340e6b2 @etrepum etrepum committed Jul 18, 2010
Showing with 38 additions and 23 deletions.
  1. +23 −14 priv/static/erldocs.js
  2. +15 −9 src/erldocs.erl
View
@@ -42,14 +42,19 @@ var ErlDocs = (function(index) {
$("#funwrapper").animate({"top":details.fTop}, "normal", fun);
};
- function scrollIntoView($parent, $child) {
+ function scrollIntoView($parent, $child, force) {
var childTop = $child.position().top - RESULT_OFFSET_Y,
scrollTop = $parent[0].scrollTop,
childHeight = $child.height(),
parentHeight = $parent.height(),
newTop = null;
+ if (force) {
+ $parent[0].scrollTop = scrollTop + childTop;
+ return;
+ }
+
if (childTop < 0) {
newTop = scrollTop + childTop;
} else if (childTop + childHeight > parentHeight) {
@@ -65,7 +70,7 @@ var ErlDocs = (function(index) {
}
};
- function setSelected(x) {
+ function setSelected(x, force) {
var sel, children = $results.children("li");
@@ -76,7 +81,7 @@ var ErlDocs = (function(index) {
selected = x;
sel = children.eq(x).addClass("selected");
if (sel.length > 0) {
- scrollIntoView($results, sel);
+ scrollIntoView($results, sel, force);
}
}
};
@@ -115,7 +120,7 @@ var ErlDocs = (function(index) {
for (i = 0; i < len; i += 1) {
item = index[i];
- if (item[0] === "mod") {
+ if (item[0] === "mod" || item[0] === "app") {
results.push(item);
}
}
@@ -143,23 +148,27 @@ var ErlDocs = (function(index) {
function formatResults(results, str) {
- var i, item, hash, url, html = "",
+ var i, item, hash, url, path, html = "",
len = results.length,
searchStr = isSearchStr(str) ? "&search="+str : "";
for (i = 0; i < len; i += 1) {
item = results[i];
- hash = (item[0] === "fun") ? "#" + item[2].split(":")[1] : "";
-
- url = CURRENT_ROOT + item[1] + "/" + item[2].split(":")[0]
- + ".html?i=" + i + searchStr + hash ;
+ if (item[0] === "app") {
+ hash = "#" + item[1];
+ path = "index";
+ } else {
+ hash = (item[0] === "fun") ? "#" + item[2].split(":")[1] : "";
+ path = item[1] + "/" + item[2].split(":")[0];
+ }
+ url = CURRENT_ROOT + path + ".html?i=" + i + searchStr + hash;
- html += '<li class="' + item[0] + '"><a href="' + url + '">'
- + '<span class="name">' + item[2] + "</span>"
- + '<br /><span class="sub">' + item[3] + '</span>'
- + '</a></li>';
+ html += '<li class="' + item[0] + '"><a href="' + url + '">'
+ + '<span class="name">' + item[2] + "</span>"
+ + '<br /><span class="sub">' + item[3] + '</span>'
+ + '</a></li>';
}
return html;
@@ -223,7 +232,7 @@ var ErlDocs = (function(index) {
}
if (qs && qs.i) {
- setSelected(parseInt(qs.i, 10));
+ setSelected(parseInt(qs.i, 10), true);
} else {
setSelected(0);
}
View
@@ -44,7 +44,8 @@ build_apps(Conf, Tpl, App, Index) ->
AppName = bname(App),
log("Building ~s (~p files)~n", [AppName, length(Files)]),
Map = fun (F) -> build_file_map(Conf, Tpl, AppName, F) end,
- pmapreduce(Map, fun lists:append/2, [], Files) ++ Index.
+ [["app", AppName, AppName, "(application)"] |
+ pmapreduce(Map, fun lists:append/2, [], Files) ++ Index].
build_file_map(Conf, Tpl, AppName, File) ->
@@ -133,7 +134,7 @@ module_index(Conf, Index) ->
log("Creating index.html ...~n"),
Html = "<h1>Module Index</h1><hr /><br /><div>"
- ++ lists:flatten(io_lib:format("<!--~n~p~n-->~n", [Index]))
+ %% ++ lists:flatten(io_lib:format("<!--~n~p~n-->~n", [Index]))
++ xml_to_str(emit_apps([X || X = ["mod"|_] <- lists:sort(Index)]))
++ "</div>",
@@ -153,18 +154,23 @@ emit_apps([], _App) ->
emit_apps([X=["mod", App | _] | Rest], App) ->
[mod(X) | emit_apps(Rest, App)];
emit_apps(L=[["mod", App | _] | _], _OtherApp) ->
- [{h1, [], [App]} | emit_apps(L, App)].
+ [{a, [{name, App}], []}, {h1, [], [App]} | emit_apps(L, App)].
mod(["mod", App, Mod, Sum]) ->
Url = App ++ "/" ++ Mod ++ ".html",
{p,[], [{a, [{href, Url}], [Mod]}, {br,[],[]}, Sum]}.
-sort_index(["app" | _], ["mod" | _]) -> true;
-sort_index(["app" | _], ["fun" | _]) -> true;
-sort_index(["mod" | _], ["fun" | _]) -> true;
-sort_index(["mod", _, M1, _], ["mod", _, M2, _]) ->
- string:to_lower(M1) < string:to_lower(M2);
-sort_index(_, _) -> false.
+type_ordering("app") -> 1;
+type_ordering("mod") -> 2;
+type_ordering("fun") -> 3.
+
+index_ordering([Type, App, Mod, _Sum]) ->
+ [string:to_lower(App),
+ type_ordering(Type),
+ string:to_lower(Mod)].
+
+sort_index(A, B) ->
+ index_ordering(A) =< index_ordering(B).
javascript_index(Conf, FIndex) ->

0 comments on commit 5fc3e1e

Please sign in to comment.