From 5bc085477a1509915b6c91b93b855976a4a540ce Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 8 Oct 2017 00:19:38 -0300 Subject: Move luarocks.index to luarocks.admin.index --- src/luarocks/admin/cmd/add.lua | 2 +- src/luarocks/admin/cmd/make_manifest.lua | 2 +- src/luarocks/admin/cmd/remove.lua | 2 +- src/luarocks/admin/index.lua | 185 +++++++++++++++++++++++++++++++ src/luarocks/index.lua | 185 ------------------------------- 5 files changed, 188 insertions(+), 188 deletions(-) create mode 100644 src/luarocks/admin/index.lua delete mode 100644 src/luarocks/index.lua diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index daf46c1d..6a6f7224 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua @@ -7,9 +7,9 @@ local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local dir = require("luarocks.dir") local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") local fs = require("luarocks.fs") local cache = require("luarocks.admin.cache") +local index = require("luarocks.admin.index") add.help_summary = "Add a rock or rockspec to a rocks server." add.help_arguments = "[--server=] [--no-refresh] {|...}" diff --git a/src/luarocks/admin/cmd/make_manifest.lua b/src/luarocks/admin/cmd/make_manifest.lua index 57851942..f0b64135 100644 --- a/src/luarocks/admin/cmd/make_manifest.lua +++ b/src/luarocks/admin/cmd/make_manifest.lua @@ -4,7 +4,7 @@ local make_manifest = {} local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") +local index = require("luarocks.admin.index") local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local deps = require("luarocks.deps") diff --git a/src/luarocks/admin/cmd/remove.lua b/src/luarocks/admin/cmd/remove.lua index 763a166f..173cc1a9 100644 --- a/src/luarocks/admin/cmd/remove.lua +++ b/src/luarocks/admin/cmd/remove.lua @@ -7,9 +7,9 @@ local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local dir = require("luarocks.dir") local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") local fs = require("luarocks.fs") local cache = require("luarocks.admin.cache") +local index = require("luarocks.admin.index") admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." admin_remove.help_arguments = "[--server=] [--no-refresh] {|...}" diff --git a/src/luarocks/admin/index.lua b/src/luarocks/admin/index.lua new file mode 100644 index 00000000..80371151 --- /dev/null +++ b/src/luarocks/admin/index.lua @@ -0,0 +1,185 @@ + +--- Module which builds the index.html page to be used in rocks servers. +local index = {} + +local util = require("luarocks.util") +local fs = require("luarocks.fs") +local vers = require("luarocks.vers") +local persist = require("luarocks.persist") +local dir = require("luarocks.dir") +local manif = require("luarocks.manif") + +local ext_url_target = ' target="_blank"' + +local index_header = [[ + + + +Available rocks + + + + +

Available rocks

+

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

+ +]] + +local index_package_begin = [[ + + + +]] + +local index_footer_begin = [[ +
+

$package - $summary
+

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

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

+manifest file +]] +local index_manifest_ver = [[ +• Lua $VER manifest file (zip) +]] +local index_footer_end = [[ +

+ + +]] + +function index.format_external_dependencies(rockspec) + if rockspec.external_dependencies then + local deplist = {} + local listed_set = {} + local plats = nil + for name, desc in util.sortedpairs(rockspec.external_dependencies) do + if name ~= "platforms" then + table.insert(deplist, name:lower()) + listed_set[name] = true + else + plats = desc + end + end + if plats then + for plat, entries in util.sortedpairs(plats) do + for name, desc in util.sortedpairs(entries) do + if not listed_set[name] then + table.insert(deplist, name:lower() .. " (on "..plat..")") + end + end + end + end + return '

External dependencies: ' .. table.concat(deplist, ', ').. '

' + else + return "" + end +end + +function index.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_begin + for version, data in util.sortedpairs(version_list, vers.compare_versions) do + local versions = {} + output = output..version..': ' + table.sort(data, function(a,b) return a.arch < b.arch end) + for _, item in ipairs(data) do + local file + if item.arch == 'rockspec' then + file = ("%s-%s.rockspec"):format(package, version) + if not latest_rockspec then latest_rockspec = file end + else + file = ("%s-%s.%s.rock"):format(package, version, item.arch) + end + table.insert(versions, ''..item.arch..'') + end + output = output .. table.concat(versions, ', ') .. '
' + end + output = output .. index_package_end + if latest_rockspec then + local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) + local descript = rockspec.description or {} + local vars = { + anchor = package, + package = rockspec.package, + original = rockspec.source.url, + summary = descript.summary or "", + detailed = descript.detailed or "", + license = descript.license or "N/A", + homepage = descript.homepage and ('| project homepage') or "", + externaldependencies = index.format_external_dependencies(rockspec) + } + vars.detailed = vars.detailed:gsub("\n\n", "

"):gsub("%s+", " ") + vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '%1') + 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_begin) + for ver in util.lua_versions() do + out:write((index_manifest_ver:gsub("$VER", ver))) + end + out:write(index_footer_end) + out:close() +end + +return index diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua deleted file mode 100644 index 80371151..00000000 --- a/src/luarocks/index.lua +++ /dev/null @@ -1,185 +0,0 @@ - ---- Module which builds the index.html page to be used in rocks servers. -local index = {} - -local util = require("luarocks.util") -local fs = require("luarocks.fs") -local vers = require("luarocks.vers") -local persist = require("luarocks.persist") -local dir = require("luarocks.dir") -local manif = require("luarocks.manif") - -local ext_url_target = ' target="_blank"' - -local index_header = [[ - - - -Available rocks - - - - -

Available rocks

-

-Lua modules available from this location for use with LuaRocks: -

- -]] - -local index_package_begin = [[ - - - -]] - -local index_footer_begin = [[ -
-

$package - $summary
-

$detailed
-$externaldependencies -latest sources $homepage | License: $license

-
-]] - -local index_package_end = [[ -
-

-manifest file -]] -local index_manifest_ver = [[ -• Lua $VER manifest file (zip) -]] -local index_footer_end = [[ -

- - -]] - -function index.format_external_dependencies(rockspec) - if rockspec.external_dependencies then - local deplist = {} - local listed_set = {} - local plats = nil - for name, desc in util.sortedpairs(rockspec.external_dependencies) do - if name ~= "platforms" then - table.insert(deplist, name:lower()) - listed_set[name] = true - else - plats = desc - end - end - if plats then - for plat, entries in util.sortedpairs(plats) do - for name, desc in util.sortedpairs(entries) do - if not listed_set[name] then - table.insert(deplist, name:lower() .. " (on "..plat..")") - end - end - end - end - return '

External dependencies: ' .. table.concat(deplist, ', ').. '

' - else - return "" - end -end - -function index.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_begin - for version, data in util.sortedpairs(version_list, vers.compare_versions) do - local versions = {} - output = output..version..': ' - table.sort(data, function(a,b) return a.arch < b.arch end) - for _, item in ipairs(data) do - local file - if item.arch == 'rockspec' then - file = ("%s-%s.rockspec"):format(package, version) - if not latest_rockspec then latest_rockspec = file end - else - file = ("%s-%s.%s.rock"):format(package, version, item.arch) - end - table.insert(versions, ''..item.arch..'') - end - output = output .. table.concat(versions, ', ') .. '
' - end - output = output .. index_package_end - if latest_rockspec then - local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) - local descript = rockspec.description or {} - local vars = { - anchor = package, - package = rockspec.package, - original = rockspec.source.url, - summary = descript.summary or "", - detailed = descript.detailed or "", - license = descript.license or "N/A", - homepage = descript.homepage and ('| project homepage') or "", - externaldependencies = index.format_external_dependencies(rockspec) - } - vars.detailed = vars.detailed:gsub("\n\n", "

"):gsub("%s+", " ") - vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '%1') - 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_begin) - for ver in util.lua_versions() do - out:write((index_manifest_ver:gsub("$VER", ver))) - end - out:write(index_footer_end) - out:close() -end - -return index -- cgit v1.2.3-55-g6feb