annotate mod_http_index/mod_http_index.lua @ 1826:ae2235d6c3f8

mod_http_index: Remove unused CSS (it was copied as-is from mod_http_muc_log)
author Kim Alvefur <zash@zash.se>
date Fri, 04 Sep 2015 00:12:13 +0200
parents 1b5c817cb642
children 9376e870f0e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local url = require"socket.url";
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
2 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape);
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 module:depends"http";
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- TODO Move templates into files
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
7 local base_template = [[
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 <!DOCTYPE html>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 <html>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 <head>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 <meta charset="utf-8">
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 <meta name="viewport" content="width=device-width, initial-scale=1">
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 <meta name="generator" value="prosody/{prosody_version} mod_{mod_name}">
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 <link rel="canonical" href="{canonical}">
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 <title>{title}</title>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 <style>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 body{background-color:#eeeeec;margin:1ex 0;padding-bottom:3em;font-family:Arial,Helvetica,sans-serif;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 header,footer{margin:1ex 1em;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 footer{font-size:smaller;color:#babdb6;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 .content{background-color:white;padding:1em;list-style-position:inside;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 nav{font-size:large;margin:1ex 1ex;clear:both;line-height:1.5em;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 nav a{padding: 1ex;text-decoration:none;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 @media screen and (min-width: 460px) {
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 nav{font-size:x-large;margin:1ex 1em;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 }
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 a:link,a:visited{color:#2e3436;text-decoration:none;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 a:link:hover,a:visited:hover{color:#3465a4;}
1826
ae2235d6c3f8 mod_http_index: Remove unused CSS (it was copied as-is from mod_http_muc_log)
Kim Alvefur <zash@zash.se>
parents: 1825
diff changeset
28 ul{padding:0;}
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 li{list-style:none;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 hr{visibility:hidden;clear:both;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 br{clear:both;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 li:hover time{opacity:1;}
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 </style>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 </head>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 <body>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 <header>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 <h1>{title}</h1>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 </header>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 <hr>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 <div class="content">
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
41 <nav>
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
42 <ul>{items#
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
43 <li><a href="{item.url}" title="{item.module}">{item.name}</a></li>}
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
44 </ul>
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
45 </nav>
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 </div>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 <hr>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 <footer>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 <br>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 <div class="powered-by">Prosody {prosody_version?}</div>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 </footer>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 </body>
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 </html>
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
54 ]];
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 local canonical = module:http_url(nil, "/");
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 local function relative(base, link)
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 base = url.parse(base);
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 link = url.parse(link);
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 for k,v in pairs(base) do
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 if link[k] == v then
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 link[k] = nil;
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 return url.build(link);
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 local function handler(event)
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
70 local host_items = module:get_host_items("http-provider");
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
71 local http_apps = {}
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
72 for _, item in ipairs(host_items) do
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 if module.name ~= item._provided_by then
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
74 table.insert(http_apps, {
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 name = item.name;
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 module = "mod_" .. item._provided_by;
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 url = relative(canonical, module:http_url(item.name, item.default_path));
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
78 });
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 event.response.headers.content_type = "text/html";
1825
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
82 return render(base_template, {
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
83 title = "HTTP Apps";
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
84 items = http_apps;
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
85 prosody_version = prosody.version;
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
86 mod_name = module.name;
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
87 canonical = canonical;
1b5c817cb642 mod_http_index: Update to use util.interpolation (makes it depend on 0.10+)
Kim Alvefur <zash@zash.se>
parents: 1573
diff changeset
88 });
1573
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 end
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 module:provides("http", {
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 route = {
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 ["GET /"] = handler;
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 };
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 default_path = "/";
0d8cc6971cdb mod_http_index: Generates an index of local HTTP apps
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 });