diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6be554a2..521b1e9a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,10 @@ - Add note about linking/using templates (html and latex) with pandoc. - Add references to argmap specs spreadsheet? +## argmap 20.0.2 + +- `src/lua`: Fix #18 and other lint errors, mainly by making functions local or adding them to an object. + ## argmap 20.0.1 - `mapjs/package.json`: Update dev dependencies to latest version. diff --git a/src/lua/argmap2mup.lua b/src/lua/argmap2mup.lua index 91e0c619..ab451a28 100755 --- a/src/lua/argmap2mup.lua +++ b/src/lua/argmap2mup.lua @@ -457,7 +457,7 @@ local function default_to_nil(var) return var end -function pipe_in_out(cmd, s) +local function pipe_in_out(cmd, s) -- a function for piping through unix commands local tmp = os.tmpname() local tmpout = os.tmpname() @@ -480,14 +480,14 @@ local function trim(s) return (s:gsub("\n", "")) end -function markdown_to_plain(s) +local function markdown_to_plain(s) if Script_context == 'client' then return s end return trim(pipe_in_out("pandoc --wrap=none -t plain -f markdown", s)) end -function parse_special(t, s) +local function parse_special(t, s) -- a function for parsing notes, labels, and strengths for i, v in pairs(t) do if string.match(i, "^" .. s .. "$") then @@ -541,7 +541,7 @@ function a2m.parse_claims(t) ["title"] = claim, ["id"] = gid, ["attr"] = default_to_nil(attr), -- default_to_nil(attr) stops empty attr breaking json output. - ["ideas"] = parse_reasons(v) + ["ideas"] = a2m.parse_reasons(v) } end end @@ -550,7 +550,7 @@ function a2m.parse_claims(t) return default_to_nil(o) end -function parse_reasons(t) +function a2m.parse_reasons(t) local o = {} local n = 0 for i, v in pairs(t) do @@ -578,7 +578,7 @@ function parse_reasons(t) return default_to_nil(o) end -function help() +local function help() return [[argmap2mup -u, --upload : upload to Google Drive -g ID, --gdrive_id ID : update file with ID on Google Drive @@ -588,7 +588,7 @@ function help() -h, --help]] end -function parse_options(a) +local function parse_options(a) local opts = {} local flags, args = pl.app.parse_args(a, { g = true, gdrive_id = true, n = true, name = true, f = true, folder = true }) @@ -621,7 +621,7 @@ function parse_options(a) return opts end -function main() +local function main() -- print(args) -- What is this line for? Debugging? Logger:debug("arg: ") Logger:debug(arg) diff --git a/src/lua/argmap2tikz.lua b/src/lua/argmap2tikz.lua index f36e2f50..a5219692 100755 --- a/src/lua/argmap2tikz.lua +++ b/src/lua/argmap2tikz.lua @@ -17,6 +17,8 @@ local pl = require 'pl.import_into' () -- uses lyaml to parse yaml local lyaml = require "lyaml" +local a2t = {} + -- initialize a global counter for providing unique ids for each node local gn = 0 -- initialize an indent so our output is human readable @@ -69,8 +71,8 @@ local styles = [=[ implicit/.style={dashed} ]=] -function pipe_in_out(cmd, s) - -- a function for piping through unix commands +-- a function for piping through unix commands +local function pipe_in_out(cmd, s) local tmp = os.tmpname() local tmpout = os.tmpname() local f = assert(io.open(tmp, 'w')) @@ -88,13 +90,13 @@ local function trim(s) return (s:gsub("\n", "")) end -function markdown_to_latex(s) +local function markdown_to_latex(s) return trim(pipe_in_out("pandoc --wrap=none -t latex -f markdown", s)) end --- TODO: enable parsing of notes -function parse_special(t, s) - -- a function for parsing notes, labels, and strengths +-- a function for parsing notes, labels, and strengths +-- TODO: enable parsing of notes +local function parse_special(t, s) for i, v in pairs(t) do if string.match(i, "^" .. s .. "$") then return v @@ -103,8 +105,8 @@ function parse_special(t, s) return nil end -function parse_claims(t) - -- a function that parses claims +-- a function that parses claims +local function parse_claims(t) local o = "" indent = indent + 2 for i, v in pairs(t) do @@ -131,15 +133,15 @@ function parse_claims(t) -- construct the claim in tikz, e.g,: c1/"Eating meat is morally acceptable"[claim, implicit] local claimline = string.rep(" ", indent) .. "c" .. gid .. "/\"" .. claim .. "\"[" .. attr .. "]" -- parse the reasons for the claim, and add the result to output. - o = o .. parse_reasons(v, claimline) + o = o .. a2t.parse_reasons(v, claimline) end end indent = indent - 2 return o end -function parse_reasons(t, claimline) - -- function that parses reasons for a claim and returns the appropriate tikz +-- function that parses reasons for a claim and returns the appropriate tikz +function a2t.parse_reasons(t, claimline) -- initialize output string local o = "" indent = indent + 2 @@ -200,8 +202,8 @@ function parse_reasons(t, claimline) return o end -function create_graph(t) - -- parse the map and generate the tikz \graph +-- parse the map and generate the tikz \graph +local function create_graph(t) local o = string.rep(" ", indent) .. "\\graph [layered layout, " .. "grow down, " .. "level distance=5em, " .. @@ -214,8 +216,8 @@ function create_graph(t) return o end -function create_tikzpicture(t) - -- generate the tikz \graph and wrap in a tikzpicture environment +-- generate the tikz \graph and wrap in a tikzpicture environment +local function create_tikzpicture(t) -- TODO: is there more appropriate way to specify rounded corners other than calling pdfsetcornerarced? indent = indent + 2 local o = "\\begin{tikzpicture}\n" .. @@ -228,8 +230,8 @@ function create_tikzpicture(t) return o end -function create_texdocument(t) - -- generate a the tikzpicture and wrap it in a standalone tex document +-- generate a the tikzpicture and wrap it in a standalone tex document +local function create_texdocument(t) local documentclass = [[\documentclass[tikz]{standalone}]] return "\\documentclass[tikz]{standalone}\n" .. includes .. "\n" .. @@ -238,7 +240,7 @@ function create_texdocument(t) "\\end{document}" end -function help() +local function help() return [[argmap2tikz -s, --standalone: generate standalone tex file -i, --includes: dump includes required for tex preamble @@ -246,7 +248,7 @@ function help() -h, --help: help]] end -function parse_options(a) +local function parse_options(a) local opts = {} local flags, args = pl.app.parse_args(a) opts["standalone"] = flags["s"] or flags["standalone"] @@ -259,7 +261,7 @@ function parse_options(a) return opts end -function main() +local function main() local opts = parse_options(arg) if opts["help"] then return help() @@ -288,3 +290,5 @@ function main() end print(main()) + +return a2t diff --git a/src/lua/mup2argmap.lua b/src/lua/mup2argmap.lua index cc298a65..62e9ced7 100755 --- a/src/lua/mup2argmap.lua +++ b/src/lua/mup2argmap.lua @@ -11,6 +11,8 @@ local lyaml = require 'lyaml' local json = require 'rxi-json-lua' local logging = require 'logging' +local m2a = {} + -- [LuaLogging: A simple API to use logging features in Lua](https://neopallium.github.io/lualogging/manual.html#introduction) local logger = logging.new(function(self, level, message) io.stderr:write(message) @@ -24,7 +26,7 @@ end) -- https://www.lua.org/manual/5.3/manual.html#6.10 logger:setLevel(logging.ERROR) -function dig_in(table, fields) +local function dig_in(table, fields) local t = table local result = true for _, f in pairs(fields) do @@ -42,7 +44,7 @@ function dig_in(table, fields) end end -function parse_claims(claims, strength, label) +local function parse_claims(claims, strength, label) local argmap = {} if strength then argmap["strength"] = strength @@ -59,7 +61,7 @@ function parse_claims(claims, strength, label) local note = dig_in(items, { "attr", "note", "text" }) local reasons = {} if items["ideas"] then - reasons = parse_reasons(items["ideas"], note) + reasons = m2a.parse_reasons(items["ideas"], note) elseif note then reasons = reasons["note"] end @@ -68,7 +70,7 @@ function parse_claims(claims, strength, label) return argmap end -function parse_reasons(reasons, note) +function m2a.parse_reasons(reasons, note) local argmap = {} argmap["note"] = note for index, items in pairs(reasons) do @@ -90,14 +92,14 @@ function parse_reasons(reasons, note) return argmap end -function help() +local function help() return [[mup2argmap -e, --embed: wrap in code block for embedding in pandoc markdown -g, --gdrive_id: parse mup file with corresponding Google Drive ID -h: show this help]] end -function parse_options(a) +local function parse_options(a) local opts = {} local flags, args = pl.app.parse_args(a, { g = true, gdrive_id = true }) opts["help"] = flags["h"] or flags["help"] @@ -112,7 +114,7 @@ function parse_options(a) return opts end -function main() +local function main() local opts = parse_options(arg) if opts["help"] then return help() @@ -150,3 +152,5 @@ end -- TODO is print best practice for this purpose? print(main()) + +return m2a \ No newline at end of file