Rename path.lua mypath.lua not conflict with other lua path modules.

Mon, 06 Jul 2020 12:35:38 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 06 Jul 2020 12:35:38 -0500
changeset 26
77cd7b8fb6a6
parent 25
11ae9103f59d
child 27
8f40424fb02e
child 28
9b75d0f5e042

Rename path.lua mypath.lua not conflict with other lua path modules.

handlers.lua file | annotate | diff | comparison | revisions
handlers/copy.lua file | annotate | diff | comparison | revisions
handlers/render.lua file | annotate | diff | comparison | revisions
lgen.lua file | annotate | diff | comparison | revisions
mypath.lua file | annotate | diff | comparison | revisions
path.lua file | annotate | diff | comparison | revisions
plugin/breadcrumb.lua file | annotate | diff | comparison | revisions
plugin/inline.lua file | annotate | diff | comparison | revisions
scan.lua file | annotate | diff | comparison | revisions
--- a/handlers.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/handlers.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -9,7 +9,9 @@
 
 local available={
     { pattern = "%.lg$", handler = handlers.render},
+    { pattern = "%.md$", handler = handlers.render},
     { pattern = "%.note$", handler = handlers.ignore},
+    { pattern = "%.hg/", handler = handlers.ignore},
     { pattern = "",      handler = handlers.copy},
 }
 
--- a/handlers/copy.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/handlers/copy.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -1,7 +1,7 @@
 
 --@module handlers.copy
 
-local path=require("path")
+local path=require("mypath")
 
 local handlers_copy={}
 
--- a/handlers/render.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/handlers/render.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -6,7 +6,7 @@
 local ltp=require('ltp.template')
 local markdown=require('markdown')
 local config=require('config')
-local path=require('path')
+local path=require('mypath')
 local filecache=require('filecache')
 local log=require('log')
 local dependency=require('dependency')
--- a/lgen.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/lgen.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -16,7 +16,7 @@
 -- globally add missing stuff 
 local luaext=require('luaext')
 local lfs=require('lfs')
-local path=require('path')
+local path=require('mypath')
 
 --
 -- Main
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mypath.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -0,0 +1,113 @@
+
+--@module path
+local path={}
+
+local tuple=require("tuple")
+local lfs=require("lfs")
+local err=require("err")
+local config=require("config")
+
+local sep=config.dirsep
+
+function path.join(p, f)
+    if p=="" then
+        return f
+    else
+        return p..sep..f
+    end
+end
+
+function path.dirbasename(p)
+    local d, b = string.match(p,
+        "^(.*)"..sep.."+([^"..sep.."]+)"..sep.."*$")
+    if not b then
+        return "", p
+    else
+        return d, b
+    end
+end
+
+function path.dirname(p)
+    return tuple.fst(dirbasename(p))
+end
+
+function path.dirname_slash(p)
+    local dn=dirname(p)
+    if dn=="" then
+        return dn
+    else
+        return dn..sep
+    end
+end
+
+function path.basename(p)
+    return tuple.snd(dirbasename(p))
+end
+
+function path.rmext(p)
+    return string.gsub(p, "%.[^.]*$", "")
+end
+
+-- would rather do this as an iterator, but can't
+-- coroutine.yield from gsub handler
+function path.split(p)
+    local t={}
+    local head=""
+    local s, p2 = string.match(p, "^("..sep.."+)(.*)$")
+    if s then
+        table.insert(t, "/.") -- root
+        p=p2
+    end
+    string.gsub(p, "([^"..sep.."]+)", --..sep.."+", 
+            function(d) table.insert(t, d); end)
+    return t
+end
+
+--[[
+function path.parts(p)
+    local s={i=1, t=split(p)}
+    local function g(s)
+        local v=s.t[s.i]
+        s.i=s.i+1
+        return v
+    end
+    return g, s
+end
+
+function path.makepath(p, head)
+    head=head or ""
+    for d in parts(p) do
+        head=head..d
+        local a=lfs.attributes(head)
+        if not a then
+            local success, e = lfs.mkdir(head)
+            if not success then
+                err.file(head, e)
+            end
+        elseif a.mode~="directory" then
+            err.file(head, "not a directory")
+        end
+        head=head..sep
+    end
+end
+]]
+
+function path.simplify(p)
+    local capts={}
+    local start=string.match(p, "^(/)")
+    string.gsub(p, "([^/]+)",
+    function(e)
+        if e==".." and #capts > 1 then
+            capts[#capts]=nil
+        elseif e~="." then
+            table.insert(capts, e)
+        end  
+    end)
+    return (start or "")..table.concat(capts, "/")
+end
+
+function path.to_root(p)
+    return string.rep("../",#(path.split(p))-1)
+end
+
+return path
--- a/path.lua	Mon Jul 06 12:35:23 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-
---@module path
-local path={}
-
-local tuple=require("tuple")
-local lfs=require("lfs")
-local err=require("err")
-local config=require("config")
-
-local sep=config.dirsep
-
-function path.join(p, f)
-    if p=="" then
-        return f
-    else
-        return p..sep..f
-    end
-end
-
-function path.dirbasename(p)
-    local d, b = string.match(p,
-        "^(.*)"..sep.."+([^"..sep.."]+)"..sep.."*$")
-    if not b then
-        return "", p
-    else
-        return d, b
-    end
-end
-
-function path.dirname(p)
-    return tuple.fst(dirbasename(p))
-end
-
-function path.dirname_slash(p)
-    local dn=dirname(p)
-    if dn=="" then
-        return dn
-    else
-        return dn..sep
-    end
-end
-
-function path.basename(p)
-    return tuple.snd(dirbasename(p))
-end
-
-function path.rmext(p)
-    return string.gsub(p, "%.[^.]*$", "")
-end
-
--- would rather do this as an iterator, but can't
--- coroutine.yield from gsub handler
-function path.split(p)
-    local t={}
-    local head=""
-    local s, p2 = string.match(p, "^("..sep.."+)(.*)$")
-    if s then
-        table.insert(t, "/.") -- root
-        p=p2
-    end
-    string.gsub(p, "([^"..sep.."]+)", --..sep.."+", 
-            function(d) table.insert(t, d); end)
-    return t
-end
-
---[[
-function path.parts(p)
-    local s={i=1, t=split(p)}
-    local function g(s)
-        local v=s.t[s.i]
-        s.i=s.i+1
-        return v
-    end
-    return g, s
-end
-
-function path.makepath(p, head)
-    head=head or ""
-    for d in parts(p) do
-        head=head..d
-        local a=lfs.attributes(head)
-        if not a then
-            local success, e = lfs.mkdir(head)
-            if not success then
-                err.file(head, e)
-            end
-        elseif a.mode~="directory" then
-            err.file(head, "not a directory")
-        end
-        head=head..sep
-    end
-end
-]]
-
-function path.simplify(p)
-    local capts={}
-    local start=string.match(p, "^(/)")
-    string.gsub(p, "([^/]+)",
-    function(e)
-        if e==".." and #capts > 1 then
-            capts[#capts]=nil
-        elseif e~="." then
-            table.insert(capts, e)
-        end  
-    end)
-    return (start or "")..table.concat(capts, "/")
-end
-
-function path.to_root(p)
-    return string.rep("../",#(path.split(p))-1)
-end
-
-return path
--- a/plugin/breadcrumb.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/plugin/breadcrumb.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -3,7 +3,7 @@
 
 local plugin_breadcrumb={}
 
-local path=require("path")
+local path=require("mypath")
 
 function plugin_breadcrumb.trail(env)
     return "(TODO)"
--- a/plugin/inline.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/plugin/inline.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -3,7 +3,7 @@
 
 local plugin_inline={}
 
-local path=require('path')
+local path=require('mypath')
 local handlers_render=require('handlers.render')
 local filecache=require('filecache')
 
--- a/scan.lua	Mon Jul 06 12:35:23 2020 -0500
+++ b/scan.lua	Mon Jul 06 12:35:38 2020 -0500
@@ -3,7 +3,7 @@
 local scan={}
 
 local lfs=require('lfs')
-local path=require('path')
+local path=require('mypath')
 
 local function filtered_dir(d) 
     local f, s_, v_ = lfs.dir(d)

mercurial