From e01ed83975933e4c8eafcda7950db98342ddfd63 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 6 Mar 2015 22:08:20 -0700 Subject: Switch to compile.lua for reasons --- compile.lua | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 compile.lua (limited to 'compile.lua') diff --git a/compile.lua b/compile.lua new file mode 100644 index 0000000..f70cfbc --- /dev/null +++ b/compile.lua @@ -0,0 +1,98 @@ +#!/usr/bin/env lua +-- A compiler for Autocento of the breakfast table +-- written in Lua (because we can, and because +-- it's good practice for Functional Programming) +-- ((OR WHATEVER YOU CALL IT, GAHD)) +-- vim: fdm=indent + +dir = "/d/Copy/writing/autocento/" + +function filterout (list, filter) + local output = {} + for _,v in ipairs(list) do + if not string.match(v, filter) then + -- table.insert Y U NO WORK? + output[#output + 1] = v + end + end + return output +end +function intable (table, item) + for k,v in pairs(table) do + if v == item then return k end + end + return false +end +function tabsub (table, pattern, replace) + local output = {} + for k,v in pairs(table) do + output[k] = v:gsub(pattern, replace) + end + return output +end + +function compile (files, output_fmt, extension, template, args) + local errors = {} + if template then table.insert(args, 'template="'..template..'"') end + for _, file in pairs(files) do + local pandoc_run = { + 'pandoc', + '-f markdown', + '-t '..output_fmt, + table.concat(tabsub(args, "^", "--"), ' '), + '-o '..file:gsub('^.*/(.-)%.%a+', '%1.'..extension), + file + } + print("Compiling "..file.." to ".. extension) + -- print(table.concat(pandoc_run, ' ')) + os.execute(table.concat(pandoc_run, ' ')) + end +end + +function move (files, new_dir) + local exe = {} + for _,file in pairs(files) do + print("Moving "..file.." to "..new_dir.."/ ..") + table.insert(exe, 'mv '..file..' '..new_dir..'/') + end + os.execute(table.concat(exe, ' && ')) + -- print(table.concat(exe, '; ')) +end + +function lozenge (files) + local output = 'var files=[' + for _,file in pairs(files) do + output = output .. file:gsub('.*', '"%0",') + end + output = output:gsub(',$', ']') + return output +end + +local files = filterout(arg, '^%-') +if not files or #files == 0 then + print("> No file list. WUT?") + os.exit(1) +end +local args = filterout(arg, '^[^%-]') +if not args or #args == 0 or args == {'-all'} then + args = { + '-html', + '-river', + '-lozenge', + } +end + +if intable(args, '-html') then + print("Compiling HTML ... ") + compile(files, "html5", "html", ".template.html", { "smart", "mathml" }) + -- move(tabsub(files,'^.*/(.*)%.txt','%1.html'), ".") +end +if intable(args, '-river') then + print("Compiling RIVER ... ") + compile(files, "lua/river.lua", "river", nil, {}) + move(tabsub(files,'^.*/(.*)%.txt','%1.river'), "river") +end +if intable(args, '-lozenge') then + print("Updating lozenge.js with file list ... ") + -- TODO +end -- cgit 1.4.1-21-gabe81