Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (81 sloc) 2.959 kb
eeabdc87 »
2009-12-09 first ever version of library
1 %% Copyright (c) 2006-2009 Joe Armstrong
2 %% See MIT-LICENSE for licensing information.
3
4 -module(simple_web_server).
5
6 -compile(export_all).
7 -import(elib1_webkit, [pre/1]).
8 -import(lists, [sort/1]).
9
10 %% START:start
11 start() ->
12 elib1_webkit:start_static_server(2246, fun server/3),
13 elib1_misc:forever().
14 %% END:start
15
16 server(_,"/cgi/start_irc", _) ->
17 spawn(fun() -> chat_widget:test1() end),
18 {response,html,"<h1>Irc running in another window</h1>"};
19 server(_,"/cgi/elib1_webquery", Args) ->
20 elib1_webquery:qu(Args, elib1_misc:root_dir() ++ "/supported/indexer");
21 server(Tag, Uri, Args) ->
22 io:format("Uri=~p~n",[Uri]),
23 Root = elib1_misc:root_dir(),
24 FullName = Root ++ Uri,
25 %% if the file extension is .ehtml then call the expander
26 case filename:extension(Uri) of
27 ".ehtml" ->
28 case filelib:is_file(FullName) of
29 true ->
30 Str = elib1_expand:expand_file(FullName),
31 {response, html, [Str]};
32 false ->
33 {response, html, pre({missing,file,FullName})}
34 end;
35 _ ->
36 %% just serve the file
37 elib1_webkit:serve_static_file_report_error(FullName)
38 end.
39
40 %% the header uses jquery to add some standard stuff to the html body
41
42 header() ->
43 ["<link href='/include/elib1.css' type='text/css' rel='stylesheet'/>\n",
44 "<script language='JavaScript'
45 SRC='/include/jquery-1.3.2.min.js'></script>
46 <script>
47 $(document).ready(function(){
48 $('body').prepend('<img width=\"100\" src=\"/include/images/ring.gif\"><img width=\"200\" src=\"/include/images/ringtxt.jpg\">');
49 });
50 </script>"].
51
52 supported() ->
53 Dir = elib1_misc:root_dir() ++ "/supported",
54 V = elib1_misc:ls(Dir),
55 Ds = [D || {D,dir,_} <- V] -- [".svn"],
56 ["<ul>", [mk_link(I) || I <- sort(Ds)], "</ul>"].
57
58 mk_link(L) ->
59 ["<li><a href='/supported/",L,"/doc.ehtml'>",L,"</a></li>"].
60
61 unsupported() ->
62 Dir = elib1_misc:root_dir() ++ "/unsupported",
63 V = elib1_misc:ls(Dir),
64 Ds = [D || {D,dir,_} <- V] -- [".svn"],
65 ["<ul>", [mk_link1(I) || I <- sort(Ds)], "</ul>"].
66
67 mk_link1(L) ->
68 ["<li><a href='/unsupported/",L,"/doc.ehtml'>",L,"</a></li>"].
69
70 library() ->
71 Root = elib1_misc:root_dir(),
72 Dir = Root ++ "/lib/src",
73 L = elib1_find:files(Dir,"*.erl",false),
74 L1 = sort([filename:basename(filename:rootname(I)) || I <- L]),
75 ["<ul>", [mk_link1(I, Root) || I <- L1], "</ul>"].
76
77 mk_link1(I, Root) ->
78 L1 = ["<a href='",
79 "/supported/tagger/html/",I,".html'>",I,"</a>"],
80 L2 = ["<a href='",
81 "/lib/doc/",I,".html'>edoc</a>"],
82 ["<li>", L1, " ", L2, "</li>"].
83
84 notes() ->
85 Root = elib1_misc:root_dir(),
86 Dir = Root ++ "/wanted/notes",
87 L = elib1_find:files(Dir,"*.ehtml",false),
88 io:format("L=~p~n",[L]),
89 L1 = sort([filename:basename(filename:rootname(I)) || I <- L]),
90 ["<ul>", [mk_link3(I) || I <- L1], "</ul>"].
91
92 mk_link3(I) ->
93 L1 = ["<a href='",
94 "/wanted/notes/",I,".ehtml'>",I,"</a>"],
95 ["<li>", L1,"</li>"].
96
97
98
Something went wrong with that request. Please try again.