From 999121f44710151c8ac8a9c0a223e76ed6859ede Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 19 Mar 2015 19:48:53 -0700 Subject: Compile 3/19 --- compile.lua | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'compile.lua') diff --git a/compile.lua b/compile.lua index 765f348..c02566e 100644 --- a/compile.lua +++ b/compile.lua @@ -5,9 +5,8 @@ -- ((OR WHATEVER YOU CALL IT, GAHD)) -- vim: fdm=indent -dir = "/d/Copy/writing/autocento/" - function filterout (list, filter) + -- Remove elements that match filter local output = {} for _,v in ipairs(list) do if not string.match(v, filter) then @@ -18,12 +17,14 @@ function filterout (list, filter) return output end function intable (table, item) + -- Find out if an element's in a table for k,v in pairs(table) do if v == item then return k end end return false end function tabsub (table, pattern, replace) + -- Replace a pattern in all table values local output = {} for k,v in pairs(table) do output[k] = v:gsub(pattern, replace) @@ -32,6 +33,7 @@ function tabsub (table, pattern, replace) end function compile (files, output_fmt, extension, template, args) + -- Run pandoc on file list local errors = {} if template then table.insert(args, 'template="'..template..'"') end for _, file in pairs(files) do @@ -50,6 +52,7 @@ function compile (files, output_fmt, extension, template, args) end function move (files, new_dir) + -- Move files to destinations local exe = {} for _,file in pairs(files) do print("Moving "..file.." to "..new_dir.."/ ..") @@ -60,16 +63,20 @@ function move (files, new_dir) end function lozenge (files) + -- Update lozenge.js file list local output = 'var files=[' for _,file in pairs(files) do output = output .. file:gsub('.*', '"%0",') end + output = output:gsub('"",','') output = output:gsub(',$', ']') return output end - +-- BEGIN MAIN STUFF HERE local files = filterout(arg, '^%-') if not files or #files == 0 then + -- Error: need files to work on! + -- TODO: don't need files if only arg is -lozenge print("> No file list. WUT?") os.exit(1) end @@ -98,5 +105,24 @@ if intable(args, '-river') then end if intable(args, '-lozenge') then print("Updating lozenge.js with file list ... ") - -- TODO + local f = assert(io.open("js/lozenge.js", "r")) + local tloz = {} + local HTMLs = io.popen("ls *.html") + local lozfs = {} + for line in HTMLs:lines() do + table.insert(lozfs, line) + end + for line in f:lines() do + if line:find("var files=") then + table.insert(tloz, lozenge(lozfs)) + else + table.insert(tloz, line) + end + end + f:close() + -- And write the file we've just read + local _f = assert(io.open("js/lozenge.js", "w")) + _f:write(table.concat(tloz, "\n")) + _f:close() + print("Done.") end -- cgit 1.4.1-21-gabe81