diff options
Diffstat (limited to 'compile.lua')
-rw-r--r-- | compile.lua | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/compile.lua b/compile.lua index 765f348..c02566e 100644 --- a/compile.lua +++ b/compile.lua | |||
@@ -5,9 +5,8 @@ | |||
5 | -- ((OR WHATEVER YOU CALL IT, GAHD)) | 5 | -- ((OR WHATEVER YOU CALL IT, GAHD)) |
6 | -- vim: fdm=indent | 6 | -- vim: fdm=indent |
7 | 7 | ||
8 | dir = "/d/Copy/writing/autocento/" | ||
9 | |||
10 | function filterout (list, filter) | 8 | function filterout (list, filter) |
9 | -- Remove elements that match filter | ||
11 | local output = {} | 10 | local output = {} |
12 | for _,v in ipairs(list) do | 11 | for _,v in ipairs(list) do |
13 | if not string.match(v, filter) then | 12 | if not string.match(v, filter) then |
@@ -18,12 +17,14 @@ function filterout (list, filter) | |||
18 | return output | 17 | return output |
19 | end | 18 | end |
20 | function intable (table, item) | 19 | function intable (table, item) |
20 | -- Find out if an element's in a table | ||
21 | for k,v in pairs(table) do | 21 | for k,v in pairs(table) do |
22 | if v == item then return k end | 22 | if v == item then return k end |
23 | end | 23 | end |
24 | return false | 24 | return false |
25 | end | 25 | end |
26 | function tabsub (table, pattern, replace) | 26 | function tabsub (table, pattern, replace) |
27 | -- Replace a pattern in all table values | ||
27 | local output = {} | 28 | local output = {} |
28 | for k,v in pairs(table) do | 29 | for k,v in pairs(table) do |
29 | output[k] = v:gsub(pattern, replace) | 30 | output[k] = v:gsub(pattern, replace) |
@@ -32,6 +33,7 @@ function tabsub (table, pattern, replace) | |||
32 | end | 33 | end |
33 | 34 | ||
34 | function compile (files, output_fmt, extension, template, args) | 35 | function compile (files, output_fmt, extension, template, args) |
36 | -- Run pandoc on file list | ||
35 | local errors = {} | 37 | local errors = {} |
36 | if template then table.insert(args, 'template="'..template..'"') end | 38 | if template then table.insert(args, 'template="'..template..'"') end |
37 | for _, file in pairs(files) do | 39 | for _, file in pairs(files) do |
@@ -50,6 +52,7 @@ function compile (files, output_fmt, extension, template, args) | |||
50 | end | 52 | end |
51 | 53 | ||
52 | function move (files, new_dir) | 54 | function move (files, new_dir) |
55 | -- Move files to destinations | ||
53 | local exe = {} | 56 | local exe = {} |
54 | for _,file in pairs(files) do | 57 | for _,file in pairs(files) do |
55 | print("Moving "..file.." to "..new_dir.."/ ..") | 58 | print("Moving "..file.." to "..new_dir.."/ ..") |
@@ -60,16 +63,20 @@ function move (files, new_dir) | |||
60 | end | 63 | end |
61 | 64 | ||
62 | function lozenge (files) | 65 | function lozenge (files) |
66 | -- Update lozenge.js file list | ||
63 | local output = 'var files=[' | 67 | local output = 'var files=[' |
64 | for _,file in pairs(files) do | 68 | for _,file in pairs(files) do |
65 | output = output .. file:gsub('.*', '"%0",') | 69 | output = output .. file:gsub('.*', '"%0",') |
66 | end | 70 | end |
71 | output = output:gsub('"",','') | ||
67 | output = output:gsub(',$', ']') | 72 | output = output:gsub(',$', ']') |
68 | return output | 73 | return output |
69 | end | 74 | end |
70 | 75 | -- BEGIN MAIN STUFF HERE | |
71 | local files = filterout(arg, '^%-') | 76 | local files = filterout(arg, '^%-') |
72 | if not files or #files == 0 then | 77 | if not files or #files == 0 then |
78 | -- Error: need files to work on! | ||
79 | -- TODO: don't need files if only arg is -lozenge | ||
73 | print("> No file list. WUT?") | 80 | print("> No file list. WUT?") |
74 | os.exit(1) | 81 | os.exit(1) |
75 | end | 82 | end |
@@ -98,5 +105,24 @@ if intable(args, '-river') then | |||
98 | end | 105 | end |
99 | if intable(args, '-lozenge') then | 106 | if intable(args, '-lozenge') then |
100 | print("Updating lozenge.js with file list ... ") | 107 | print("Updating lozenge.js with file list ... ") |
101 | -- TODO | 108 | local f = assert(io.open("js/lozenge.js", "r")) |
109 | local tloz = {} | ||
110 | local HTMLs = io.popen("ls *.html") | ||
111 | local lozfs = {} | ||
112 | for line in HTMLs:lines() do | ||
113 | table.insert(lozfs, line) | ||
114 | end | ||
115 | for line in f:lines() do | ||
116 | if line:find("var files=") then | ||
117 | table.insert(tloz, lozenge(lozfs)) | ||
118 | else | ||
119 | table.insert(tloz, line) | ||
120 | end | ||
121 | end | ||
122 | f:close() | ||
123 | -- And write the file we've just read | ||
124 | local _f = assert(io.open("js/lozenge.js", "w")) | ||
125 | _f:write(table.concat(tloz, "\n")) | ||
126 | _f:close() | ||
127 | print("Done.") | ||
102 | end | 128 | end |