diff options
author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-04 16:09:00 +0000 |
---|---|---|
committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-04 16:09:00 +0000 |
commit | d339f03ff7e8c7b1ca922aa75bb1461fb5faa97d (patch) | |
tree | 4c6b5250c5f5c73d8574f3aba9fd9242de2feca0 /src | |
parent | 34131f1c7f6740f87f4f3120ee7142b07d25bbf3 (diff) | |
download | luarocks-d339f03ff7e8c7b1ca922aa75bb1461fb5faa97d.tar.gz luarocks-d339f03ff7e8c7b1ca922aa75bb1461fb5faa97d.tar.bz2 luarocks-d339f03ff7e8c7b1ca922aa75bb1461fb5faa97d.zip |
Separate index.html generation in its own module
git-svn-id: http://luarocks.org/svn/luarocks/trunk@59 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/add.lua | 3 | ||||
-rw-r--r-- | src/luarocks/index.lua | 139 |
2 files changed, 141 insertions, 1 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index 66afe1f3..ed995d98 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua | |||
@@ -8,6 +8,7 @@ local util = require("luarocks.util") | |||
8 | local fetch = require("luarocks.fetch") | 8 | local fetch = require("luarocks.fetch") |
9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
10 | local manif = require("luarocks.manif") | 10 | local manif = require("luarocks.manif") |
11 | local index = require("luarocks.index") | ||
11 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
12 | 13 | ||
13 | help_summary = "Add a rock or rockpec to a rocks server." | 14 | help_summary = "Add a rock or rockpec to a rocks server." |
@@ -83,7 +84,7 @@ local function add_file_to_server(refresh, rockfile, server) | |||
83 | print("Updating manifest...") | 84 | print("Updating manifest...") |
84 | manif.make_manifest(local_cache) | 85 | manif.make_manifest(local_cache) |
85 | print("Updating index.html...") | 86 | print("Updating index.html...") |
86 | manif.make_index(local_cache) | 87 | index.make_index(local_cache) |
87 | 88 | ||
88 | local login_info = "" | 89 | local login_info = "" |
89 | if user then login_info = " -u "..user end | 90 | if user then login_info = " -u "..user end |
diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua new file mode 100644 index 00000000..1ea18b6c --- /dev/null +++ b/src/luarocks/index.lua | |||
@@ -0,0 +1,139 @@ | |||
1 | |||
2 | module("luarocks.index", package.seeall) | ||
3 | |||
4 | local util = require("luarocks.util") | ||
5 | local fs = require("luarocks.fs") | ||
6 | local deps = require("luarocks.deps") | ||
7 | local persist = require("luarocks.persist") | ||
8 | local dir = require("luarocks.dir") | ||
9 | local manif = require("luarocks.manif") | ||
10 | |||
11 | local index_header = [[ | ||
12 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||
13 | <html> | ||
14 | <head> | ||
15 | <title>Available rocks</title> | ||
16 | <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> | ||
17 | <style> | ||
18 | body { | ||
19 | background-color: white; | ||
20 | font-family: "bitstream vera sans", "verdana", "sans"; | ||
21 | font-size: 14px; | ||
22 | } | ||
23 | a { | ||
24 | color: #0000c0; | ||
25 | text-decoration: none; | ||
26 | } | ||
27 | a:hover { | ||
28 | text-decoration: underline; | ||
29 | } | ||
30 | td.main { | ||
31 | border-style: none; | ||
32 | } | ||
33 | blockquote { | ||
34 | font-size: 12px; | ||
35 | } | ||
36 | td.package { | ||
37 | background-color: #f0f0f0; | ||
38 | vertical-align: top; | ||
39 | } | ||
40 | td.spacer { | ||
41 | height: 5px; | ||
42 | } | ||
43 | td.version { | ||
44 | background-color: #d0d0d0; | ||
45 | vertical-align: top; | ||
46 | text-align: left; | ||
47 | padding: 5px; | ||
48 | width: 100px; | ||
49 | } | ||
50 | p.manifest { | ||
51 | font-size: 8px; | ||
52 | } | ||
53 | </style> | ||
54 | </head> | ||
55 | <body> | ||
56 | <h1>Available rocks</h1> | ||
57 | <p> | ||
58 | Lua modules avaliable from this location for use with <a href="http://www.luarocks.org">LuaRocks</a>: | ||
59 | </p> | ||
60 | <table class="main"> | ||
61 | ]] | ||
62 | |||
63 | local index_package_start = [[ | ||
64 | <td class="package"> | ||
65 | <p><a name="$anchor"></a><b>$package</b> - $summary<br/> | ||
66 | </p><blockquote><p>$detailed<br/> | ||
67 | <font size="-1"><a href="$original">latest sources</a> $homepage | License: $license</font></p> | ||
68 | </blockquote></a></td> | ||
69 | <td class="version"> | ||
70 | ]] | ||
71 | |||
72 | local index_package_end = [[ | ||
73 | </td></tr> | ||
74 | <tr><td colspan="2" class="spacer"></td></tr> | ||
75 | ]] | ||
76 | |||
77 | local index_footer = [[ | ||
78 | </table> | ||
79 | <p class="manifest"> | ||
80 | <a href="manifest">manifest file</a> | ||
81 | </p> | ||
82 | </body> | ||
83 | </html> | ||
84 | ]] | ||
85 | |||
86 | function make_index(repo) | ||
87 | if not fs.is_dir(repo) then | ||
88 | return nil, "Cannot access repository at "..repo | ||
89 | end | ||
90 | local manifest = manif.load_manifest(repo) | ||
91 | local out = io.open(dir.path(repo, "index.html"), "w") | ||
92 | |||
93 | out:write(index_header) | ||
94 | for package, version_list in util.sortedpairs(manifest.repository) do | ||
95 | local latest_rockspec = nil | ||
96 | local output = index_package_start | ||
97 | for version, data in util.sortedpairs(version_list, deps.compare_versions) do | ||
98 | local out_versions = {} | ||
99 | local arches = 0 | ||
100 | output = output..version | ||
101 | local sep = ': ' | ||
102 | for _, item in ipairs(data) do | ||
103 | output = output .. sep .. '<a href="$url">'..item.arch..'</a>' | ||
104 | sep = ', ' | ||
105 | if item.arch == 'rockspec' then | ||
106 | local rs = ("%s-%s.rockspec"):format(package, version) | ||
107 | if not latest_rockspec then latest_rockspec = rs end | ||
108 | output = output:gsub("$url", rs) | ||
109 | else | ||
110 | output = output:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch)) | ||
111 | end | ||
112 | end | ||
113 | output = output .. '<br/>' | ||
114 | output = output:gsub("$na", arches) | ||
115 | end | ||
116 | output = output .. index_package_end | ||
117 | if latest_rockspec then | ||
118 | local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) | ||
119 | local vars = { | ||
120 | anchor = package, | ||
121 | package = rockspec.package, | ||
122 | original = rockspec.source.url, | ||
123 | summary = rockspec.description.summary or "", | ||
124 | detailed = rockspec.description.detailed or "", | ||
125 | license = rockspec.description.license or "N/A", | ||
126 | homepage = rockspec.description.homepage and ("| <a href="..rockspec.description.homepage..">project homepage</a>") or "" | ||
127 | } | ||
128 | vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ") | ||
129 | output = output:gsub("$(%w+)", vars) | ||
130 | else | ||
131 | output = output:gsub("$anchor", package) | ||
132 | output = output:gsub("$package", package) | ||
133 | output = output:gsub("$(%w+)", "") | ||
134 | end | ||
135 | out:write(output) | ||
136 | end | ||
137 | out:write(index_footer) | ||
138 | out:close() | ||
139 | end | ||