Mercurial > repo
comparison share/lua/5.2/luarocks/index.lua @ 1132:d137f631bad5
<GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
author | HackBot |
---|---|
date | Fri, 14 Dec 2012 22:24:27 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1131:ff65dfb63263 | 1132:d137f631bad5 |
---|---|
1 | |
2 --- Module which builds the index.html page to be used in rocks servers. | |
3 module("luarocks.index", package.seeall) | |
4 | |
5 local util = require("luarocks.util") | |
6 local fs = require("luarocks.fs") | |
7 local deps = require("luarocks.deps") | |
8 local persist = require("luarocks.persist") | |
9 local dir = require("luarocks.dir") | |
10 local manif = require("luarocks.manif") | |
11 | |
12 local ext_url_target = ' target="_blank"' | |
13 | |
14 local index_header = [[ | |
15 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
16 <html> | |
17 <head> | |
18 <title>Available rocks</title> | |
19 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> | |
20 <style> | |
21 body { | |
22 background-color: white; | |
23 font-family: "bitstream vera sans", "verdana", "sans"; | |
24 font-size: 14px; | |
25 } | |
26 a { | |
27 color: #0000c0; | |
28 text-decoration: none; | |
29 } | |
30 a:hover { | |
31 text-decoration: underline; | |
32 } | |
33 td.main { | |
34 border-style: none; | |
35 } | |
36 blockquote { | |
37 font-size: 12px; | |
38 } | |
39 td.package { | |
40 background-color: #f0f0f0; | |
41 vertical-align: top; | |
42 } | |
43 td.spacer { | |
44 height: 5px; | |
45 } | |
46 td.version { | |
47 background-color: #d0d0d0; | |
48 vertical-align: top; | |
49 text-align: left; | |
50 padding: 5px; | |
51 width: 100px; | |
52 } | |
53 p.manifest { | |
54 font-size: 8px; | |
55 } | |
56 </style> | |
57 </head> | |
58 <body> | |
59 <h1>Available rocks</h1> | |
60 <p> | |
61 Lua modules available from this location for use with <a href="http://www.luarocks.org">LuaRocks</a>: | |
62 </p> | |
63 <table class="main"> | |
64 ]] | |
65 | |
66 local index_package_start = [[ | |
67 <td class="package"> | |
68 <p><a name="$anchor"></a><b>$package</b> - $summary<br/> | |
69 </p><blockquote><p>$detailed<br/> | |
70 $externaldependencies | |
71 <font size="-1"><a href="$original">latest sources</a> $homepage | License: $license</font></p> | |
72 </blockquote></a></td> | |
73 <td class="version"> | |
74 ]] | |
75 | |
76 local index_package_end = [[ | |
77 </td></tr> | |
78 <tr><td colspan="2" class="spacer"></td></tr> | |
79 ]] | |
80 | |
81 local index_footer = [[ | |
82 </table> | |
83 <p class="manifest"> | |
84 <a href="manifest">manifest file</a> | |
85 </p> | |
86 </body> | |
87 </html> | |
88 ]] | |
89 | |
90 function format_external_dependencies(rockspec) | |
91 if rockspec.external_dependencies then | |
92 local deplist = {} | |
93 local listed_set = {} | |
94 local plats = nil | |
95 for name, desc in util.sortedpairs(rockspec.external_dependencies) do | |
96 if name ~= "platforms" then | |
97 table.insert(deplist, name:lower()) | |
98 listed_set[name] = true | |
99 else | |
100 plats = desc | |
101 end | |
102 end | |
103 if plats then | |
104 for plat, entries in util.sortedpairs(plats) do | |
105 for name, desc in util.sortedpairs(entries) do | |
106 if not listed_set[name] then | |
107 table.insert(deplist, name:lower() .. " (on "..plat..")") | |
108 end | |
109 end | |
110 end | |
111 end | |
112 return '<p><b>External dependencies:</b> ' .. table.concat(deplist, ', ').. '</p>' | |
113 else | |
114 return "" | |
115 end | |
116 end | |
117 | |
118 function make_index(repo) | |
119 if not fs.is_dir(repo) then | |
120 return nil, "Cannot access repository at "..repo | |
121 end | |
122 local manifest = manif.load_manifest(repo) | |
123 local out = io.open(dir.path(repo, "index.html"), "w") | |
124 | |
125 out:write(index_header) | |
126 for package, version_list in util.sortedpairs(manifest.repository) do | |
127 local latest_rockspec = nil | |
128 local output = index_package_start | |
129 for version, data in util.sortedpairs(version_list, deps.compare_versions) do | |
130 local versions = {} | |
131 output = output..version..': ' | |
132 table.sort(data, function(a,b) return a.arch < b.arch end) | |
133 for _, item in ipairs(data) do | |
134 local link = '<a href="$url">'..item.arch..'</a>' | |
135 if item.arch == 'rockspec' then | |
136 local rs = ("%s-%s.rockspec"):format(package, version) | |
137 if not latest_rockspec then latest_rockspec = rs end | |
138 link = link:gsub("$url", rs) | |
139 else | |
140 link = link:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch)) | |
141 end | |
142 table.insert(versions, link) | |
143 end | |
144 output = output .. table.concat(versions, ', ') .. '<br/>' | |
145 end | |
146 output = output .. index_package_end | |
147 if latest_rockspec then | |
148 local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) | |
149 local descript = rockspec.description or {} | |
150 local vars = { | |
151 anchor = package, | |
152 package = rockspec.package, | |
153 original = rockspec.source.url, | |
154 summary = descript.summary or "", | |
155 detailed = descript.detailed or "", | |
156 license = descript.license or "N/A", | |
157 homepage = descript.homepage and ('| <a href="'..descript.homepage..'"'..ext_url_target..'>project homepage</a>') or "", | |
158 externaldependencies = format_external_dependencies(rockspec) | |
159 } | |
160 vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ") | |
161 vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '<a href="%1"'..ext_url_target..'>%1</a>') | |
162 output = output:gsub("$(%w+)", vars) | |
163 else | |
164 output = output:gsub("$anchor", package) | |
165 output = output:gsub("$package", package) | |
166 output = output:gsub("$(%w+)", "") | |
167 end | |
168 out:write(output) | |
169 end | |
170 out:write(index_footer) | |
171 out:close() | |
172 end |