From 14fca7d45604d46d51e135279d3d5873b1f57f68 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 23 Mar 2015 23:36:28 -0700 Subject: Makefile v.01 is alive --- README.md | 4 +- apollo11.html | 8 ++ compile.lua | 128 -------------------------------- lua/compile-uff.lua | 208 ---------------------------------------------------- src/makefile | 5 +- 5 files changed, 15 insertions(+), 338 deletions(-) delete mode 100644 compile.lua delete mode 100644 lua/compile-uff.lua diff --git a/README.md b/README.md index 0972f11..80d5d0d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ project: ... ```` -To compile all the markdown into glorious, glorious HTML (visible at ), run `compile.lua` (`bash compile.lua` in Windows) in the root directory of this git repository. +To compile all the markdown into glorious, glorious HTML (visible at ), run `make all` in the src directory of this repository. +(Windows users: get a UNIX shell. +I'm over it.) [pandoc]: http://johnmacfarlane.net/pandoc/ diff --git a/apollo11.html b/apollo11.html index 9be4c25..1ac9258 100644 --- a/apollo11.html +++ b/apollo11.html @@ -39,6 +39,14 @@ +
+ + Big deal. + +

So it’s the fucking moon. Big deal. As if
you haven’t seen it before, hanging in the sky
like a piece of rotten meat nailed to the wall,

a maudlin love letter (the i’s dotted with hearts)
tacked to the sky’s door like ninety-eight theses.
Don’t stare at it like it means anything.

diff --git a/compile.lua b/compile.lua deleted file mode 100644 index c02566e..0000000 --- a/compile.lua +++ /dev/null @@ -1,128 +0,0 @@ -#!/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 - -function filterout (list, filter) - -- Remove elements that match 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) - -- 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) - end - return output -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 - 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) - -- Move files to destinations - 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) - -- 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 -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", - "section-divs", - }) - -- 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 ... ") - 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 diff --git a/lua/compile-uff.lua b/lua/compile-uff.lua deleted file mode 100644 index 9da70b8..0000000 --- a/lua/compile-uff.lua +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/env lua --- A compiler for "Autocento of the breakfast table" by Case Duckworth --- check it in action at: www.autocento.me --- Usage: `lua compile.lua [options] --- Where [options] are --- -- -html: compiles html files --- -- -river: compiles river files (only words, one per line) --- -- -lozenge: updates lozenge.js file --- vim: fdm=indent - -defaults = {} - defaults.dirs = { - root = "/d/Copy/projects/autocento/", - src = "/d/Copy/projects/autocento/src/", - lua = "/d/Copy/projects/autocento/lua/", - js = "/d/Copy/projects/autocento/js/", - css = "/d/Copy/projects/autocento/css/", - } - defaults.files = { - lozenge = defaults.dirs.js .. "lozenge.js", - } - defaults.formats = { - html = { - output_dir = defaults.dirs.root, - extension = "html", - pandoc_args = { - from = "markdown", - to = "html5", - template = ".template.html", - "smart", - "mathml", - "section-divs", - } - }, - river = { - output_dir = defaults.dirs.root .. "river/", - extension = "river", - pandoc_args = { - from = "markdown", - to = defaults.dirs.lua.."river.lua", - }, - }, - } - defaults.compile_args = { - '-html', - '-river', - '-lozenge', - } -helpers = { - -- Little helper functions - filter = function (list, filter) - -- Filter a list. - -- 1st return is list of terms that match. - -- 2nd return is list of terms that don't match. - local output_match = {} - local output_nomatch = {} - for _,v in ipairs(list) do - if string.match(v, filter) then - output_match[#output_match+1] = v - else - output_nomatch[#output_nomatch+1] = v - end - end - return output_match, output_nomatch - end, - in_table = function (table, term) - -- Search for term in table - for k,v in pairs(table) do - if v == term then - return k - end - end - return nil - end, - tsub = function (table, pattern, replace, i) - -- gsub on every term in a table - local output = {} - if i then -- 'i' option just does ipair part of table - for k,v in ipairs(table) do - output[k] = v:gsub(pattern, replace) - end - else - for k,v in pairs(table) do - output[k] = v:gsub(pattern, replace) - end - end - return output - end, - scandir = function (directory) - -- Find all files in a directory - local i, t, popen = 0, {}, io.popen - for filename in popen('ls -a "'..directory..'"'):lines() do - i = i+1 - t[i] = filename - end - return t - end -} - -function compile (files, format_args) - -- Run pandoc on , producing , with [pandoc_args]. - local errors = 0 - if not format_args then - format_args = defaults.formats[output_format] - end - print("Compiling files to "..format_args.extension.." ...") - args = format_args.pandoc_args - for _, file in pairs(files) do - local pandoc_run = { - 'pandoc', - '-f', args.from, - '-t', args.to, - '-o', - file:gsub('%.%a+$', "."..format_args.extension) - } - if args.template then - table.insert(pandoc_run, '--template="'..args.template..'"') - end - for _,a in ipairs(args) do - pandoc_run[#pandoc_run+1] = a:gsub("^", "--") - end - table.insert(pandoc_run, file) - for k,v in pairs(pandoc_run) do - print(k, v) - end - if not os.execute(table.concat(pandoc_run, " ")) then - errors = errors+1 - end - io.write(".") - end - print("Compiling "..#files.." files completed with "..errors.." errors.") -end - -function move (files, destination) - -- Move files to destination - print("Moving files to "..destination.." ...") - local errors = 0 - for _, file in pairs(files) do - if not os.execute("mv "..file.." "..destination) then - errors = errors+1 - end - end - print("Moving "..#files.." completed with "..errors.." errors.") -end - -function lozenge_list (files, blacklist) - -- Produce list for placement in lozenge.js - local output = {} - for _,file in pairs(files) do - -- table.insert(output, #output+1, file:gsub('.*', '"%0"')) - output[#output+1] = file:gsub(".*", '"%0",') - end - if blacklist then - for _,unwanted in pairs(blacklist) do - _,output = helpers.filter(files, unwanted) - end - end - output = table.concat(output, " ") - output = "var files = ["..output - output = output:gsub('"",', '') - output = output:gsub(",$", "]") - print(output) -end - -local args, files = helpers.filter(arg, "^%-") -if not files or #files == 0 then - -- Error: need files to work on! - -- TODO: don't technically need file list for -lozenge - print("ERROR: No file list.") - os.exit(1) -end -basenames = helpers.tsub(files, "^.*/", "") -basenames = helpers.tsub(files, "%.%a+$", "") -if not args or #args == 0 or args == { "-all" } then - args = defaults.compile_args -end --- Option parsing -if helpers.in_table(args, "-html") then - compile(files, defaults.formats.html) - move(helpers.tsub(basenames, "$", "%0.html"), - defaults.formats.html.output_dir) -end -if helpers.in_table(args, "-river") then - compile(files, defaults.formats.river) - move(helpers.tsub(basenames, ".*", "%0.river"), - defaults.formats.river.output_dir) -end -if helpers.in_table(args, "-lozenge") then - -- TODO: should probably break this out into a function - print("Updating lozenge.js file list...") - local htmls = helpers.filter(helpers.scandir(defaults.dirs.root), - "html$") - local f = assert(io.open(defaults.files.lozenge, "r")) - local buffer = {} - for line in f:lines() do - if line:find("var files=") then - table.insert(buffer, lozenge_list(htmls)) - else - table.insert(buffer, line) - end - end - f:close() - -- Write the file we've just read - local F = assert(io.open(defaults.files.lozenge, "w")) - F:write(table.concat(buffer, "\n")) - F:close() - print("Done.") -end diff --git a/src/makefile b/src/makefile index eefa4a3..800f8a0 100644 --- a/src/makefile +++ b/src/makefile @@ -17,8 +17,11 @@ all : $(HTMLs) $(RIVERs) # Generic rule for HTML targets and Markdown sources %.html : %.txt - pandoc $< -f markdown -t html5 $(HTMLopts) -o $(HTMLdir)/$@ + pandoc $< -f markdown -t html5 $(HTMopts) -o $(HTMLdir)/$@ # Generic rule for RIVER targets and Markdown sources %.river : %.txt pandoc $< -f markdown -t $(LUAdir)/river.lua $(RIVopts) -o $(RIVdir)/$@ + +# TODO: add lozenge updating +# AND compiling hapax -- cgit 1.4.1-21-gabe81