Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #11 from akaspin/master

UTF-8 compatibility.
  • Loading branch information...
commit 1ce84d9eb216a403d913c77d2211ec970c38e788 2 parents c6f4e90 + aabb6ca
Dale  Harvey authored October 11, 2011
2  .gitignore
@@ -5,3 +5,5 @@ deps
5 5
 ebin
6 6
 priv/www
7 7
 !/priv/www/index.html
  8
+/.settings
  9
+/.project
BIN  erldocs 100755 → 100644
Binary file not shown
50  src/erldocs_core.erl
@@ -3,6 +3,14 @@
3 3
 -export([mapreduce/4, pmapreduce/4, pmapreduce/5]).
4 4
 -include_lib("kernel/include/file.hrl").
5 5
 
  6
+-ifdef(DEBUG).
  7
+-define(LOG(Str, Args), io:format(Str, Args)).
  8
+-define(LOG(Str), io:format(Str)).
  9
+-else.
  10
+-define(LOG(_Str, _Args), ok).
  11
+-define(LOG(_Str), ok).
  12
+-endif.
  13
+
6 14
 %% @doc Copy static files
7 15
 -spec copy_static_files(list()) -> ok.
8 16
 copy_static_files(Conf) ->
@@ -61,7 +69,7 @@ build_file_map(Conf, AppName, File) ->
61 69
                        erlref ->
62 70
                            {modulesummary, [], Sum}
63 71
                                = lists:keyfind(modulesummary,1, Xml),
64  
-                           Sum;
  72
+                           unicode:characters_to_list(Sum);
65 73
                        cref ->
66 74
                            {libsummary, [], Sum}
67 75
                                = lists:keyfind(libsummary, 1, Xml),
@@ -112,7 +120,9 @@ gen_docsrc(AppDir, SrcFiles, Dest) ->
112 120
     Includes = filelib:wildcard(AppDir ++ "/include"),
113 121
     lists:foldl(fun(File, Acc) ->
114 122
                         log("Generating XML - ~s~n", [bname(File, ".erl")]),
115  
-                        case (catch docb_gen:module(File, [{includes, Includes}])) of
  123
+                        case (catch docb_gen:module(
  124
+                                File, [{includes, Includes},
  125
+                                       {sort_functions,false}])) of
116 126
                             ok ->
117 127
                                 [filename:join([Dest, bname(File, ".erl")]) ++ ".xml"|Acc];
118 128
                             Error ->
@@ -188,11 +198,20 @@ javascript_index(Conf, FIndex) ->
188 198
     log("Creating erldocs_index.js ...~n"),
189 199
 
190 200
     F = fun([Else, App, NMod, Sum]) ->
191  
-                [Else, App, NMod, string:substr(Sum, 1, 50)]
  201
+                [Else, App, NMod, fmt("~ts", [string:substr(Sum, 1, 50)])]
192 202
         end,
193 203
 
194  
-    Index = lists:sort(fun sort_index/2, lists:map(F, FIndex)),
195  
-    Js    = fmt("var index = ~p;", [Index]),
  204
+    Index = 
  205
+        lists:map(
  206
+              fun([A,B,C,[]]) ->
  207
+                      fmt("['~s','~s','~s',[]]", [A,B,C]);
  208
+                 ([A,B,C,D]) ->
  209
+                      fmt("['~s','~s','~s','~s']", [A,B,C,D])
  210
+              end, 
  211
+              lists:sort(fun sort_index/2, lists:map(F, FIndex))),
  212
+    
  213
+    Js    = re:replace(fmt("var index = [~s];", [string:join(Index, ",")]), 
  214
+                       "\\n|\\r", "", [{return,list}]),
196 215
 
197 216
     ok = file:write_file([dest(Conf), "/erldocs_index.js"], Js).
198 217
 
@@ -406,7 +425,7 @@ strip_whitespace(Else) ->
406 425
 is_whitespace(X) when is_tuple(X); is_number(X) ->
407 426
     true;
408 427
 is_whitespace(X) ->
409  
-    nomatch == re:run(X, "^[ \n\t]*$"). %"
  428
+    nomatch == re:run(X, "^[ \n\t]*$", [unicode]). %"
410 429
 
411 430
 %% rather basic xml to string converter, takes xml of the form
412 431
 %% {tag, [{listof, "attributes"}], ["list of children"]}
@@ -416,15 +435,15 @@ xml_to_str(Xml) ->
416 435
 
417 436
 xml_to_html({Tag, Attr}) ->
418 437
     %% primarily for cases such as <a name="">
419  
-    fmt("<~s ~s>", [Tag, atos(Attr)]);
  438
+    fmt("<~ts ~ts>", [Tag, atos(Attr)]);
420 439
 xml_to_html({Tag, Attr, []}) ->
421  
-    fmt("<~s ~s />", [Tag, atos(Attr)]);
  440
+    fmt("<~ts ~ts />", [Tag, atos(Attr)]);
422 441
 xml_to_html({Tag, [], []}) ->
423  
-    fmt("<~s />", [Tag]);
  442
+    fmt("<~ts />", [Tag]);
424 443
 xml_to_html({Tag, [], Child}) ->
425  
-    fmt("<~s>~s</~s>", [Tag, xml_to_html(Child), Tag]);
  444
+    fmt("<~ts>~ts</~ts>", [Tag, xml_to_html(Child), Tag]);
426 445
 xml_to_html({Tag, Attr, Child}) ->
427  
-    fmt("<~s ~s>~s</~s>", [Tag, atos(Attr), xml_to_html(Child), Tag]);
  446
+    fmt("<~ts ~ts>~ts</~ts>", [Tag, atos(Attr), xml_to_html(Child), Tag]);
428 447
 xml_to_html(List) when is_list(List) ->
429 448
     case io_lib:char_list(List) of
430 449
         true  -> htmlchars(List);
@@ -452,8 +471,9 @@ htmlchars([Else | Rest], Acc) -> htmlchars(Rest, [Else | Acc]).
452 471
 -spec read_xml(list(), list()) -> tuple().
453 472
 read_xml(_Conf, XmlFile) ->
454 473
 
455  
-    Opts  = [{fetch_path, [code:lib_dir(docbuilder, dtd)]},
456  
-             {encoding,   "latin1"}],
  474
+%%     Opts  = [{fetch_path, [code:lib_dir(docbuilder, dtd)]},
  475
+%%              {encoding, "utf-8"}],
  476
+    Opts  = [{fetch_path, [code:lib_dir(docbuilder, dtd)]}],
457 477
 
458 478
     {Xml, _}  = xmerl_scan:file(XmlFile, Opts),
459 479
     xmerl_lib:simplify_element(Xml).
@@ -463,9 +483,9 @@ fmt(Format, Args) ->
463 483
     lists:flatten(io_lib:format(Format, Args)).
464 484
 
465 485
 log(Str) ->
466  
-    io:format(Str).
  486
+    ?LOG(Str).
467 487
 log(Str, Args) ->
468  
-    io:format(Str, Args).
  488
+    ?LOG(Str, Args).
469 489
 
470 490
 %% @doc shorthand for lists:keyfind
471 491
 -spec kf(term(), list()) -> term().
2  templates/erldocs.dtl
@@ -2,7 +2,7 @@
2 2
 <html lang="en">
3 3
 
4 4
   <head>
5  
-    <meta charset="latin1" />
  5
+    <meta charset="utf-8" />
6 6
     <title>{{ title }} - erldocs.com (Erlang Documentation)</title>
7 7
     <link rel="search" type="application/opensearchdescription+xml"
8 8
           title="erldocs" href="/search.xml">

0 notes on commit 1ce84d9

Please sign in to comment.
Something went wrong with that request. Please try again.