From d339f03ff7e8c7b1ca922aa75bb1461fb5faa97d Mon Sep 17 00:00:00 2001 From: hisham Date: Sun, 4 Oct 2009 16:09:00 +0000 Subject: Separate index.html generation in its own module git-svn-id: http://luarocks.org/svn/luarocks/trunk@59 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/add.lua | 3 +- src/luarocks/index.lua | 139 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/luarocks/index.lua (limited to 'src') 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") local fetch = require("luarocks.fetch") local dir = require("luarocks.dir") local manif = require("luarocks.manif") +local index = require("luarocks.index") local fs = require("luarocks.fs") help_summary = "Add a rock or rockpec to a rocks server." @@ -83,7 +84,7 @@ local function add_file_to_server(refresh, rockfile, server) print("Updating manifest...") manif.make_manifest(local_cache) print("Updating index.html...") - manif.make_index(local_cache) + index.make_index(local_cache) local login_info = "" 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 @@ + +module("luarocks.index", package.seeall) + +local util = require("luarocks.util") +local fs = require("luarocks.fs") +local deps = require("luarocks.deps") +local persist = require("luarocks.persist") +local dir = require("luarocks.dir") +local manif = require("luarocks.manif") + +local index_header = [[ + + + +Available rocks + + + + +

Available rocks

+

+Lua modules avaliable from this location for use with LuaRocks: +

+ +]] + +local index_package_start = [[ + + + +]] + +local index_footer = [[ +
+

$package - $summary
+

$detailed
+latest sources $homepage | License: $license

+
+]] + +local index_package_end = [[ +
+

+manifest file +

+ + +]] + +function make_index(repo) + if not fs.is_dir(repo) then + return nil, "Cannot access repository at "..repo + end + local manifest = manif.load_manifest(repo) + local out = io.open(dir.path(repo, "index.html"), "w") + + out:write(index_header) + for package, version_list in util.sortedpairs(manifest.repository) do + local latest_rockspec = nil + local output = index_package_start + for version, data in util.sortedpairs(version_list, deps.compare_versions) do + local out_versions = {} + local arches = 0 + output = output..version + local sep = ': ' + for _, item in ipairs(data) do + output = output .. sep .. ''..item.arch..'' + sep = ', ' + if item.arch == 'rockspec' then + local rs = ("%s-%s.rockspec"):format(package, version) + if not latest_rockspec then latest_rockspec = rs end + output = output:gsub("$url", rs) + else + output = output:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch)) + end + end + output = output .. '
' + output = output:gsub("$na", arches) + end + output = output .. index_package_end + if latest_rockspec then + local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) + local vars = { + anchor = package, + package = rockspec.package, + original = rockspec.source.url, + summary = rockspec.description.summary or "", + detailed = rockspec.description.detailed or "", + license = rockspec.description.license or "N/A", + homepage = rockspec.description.homepage and ("| project homepage") or "" + } + vars.detailed = vars.detailed:gsub("\n\n", "

"):gsub("%s+", " ") + output = output:gsub("$(%w+)", vars) + else + output = output:gsub("$anchor", package) + output = output:gsub("$package", package) + output = output:gsub("$(%w+)", "") + end + out:write(output) + end + out:write(index_footer) + out:close() +end -- cgit v1.2.3-55-g6feb