summaryrefslogtreecommitdiff
path: root/src/lua-script/script.h
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-01-04 15:05:41 -0600
committersanine <sanine.not@pm.me>2022-01-04 15:05:41 -0600
commitcc82d13a4f80a5a2483581dd679f06772a9e3a19 (patch)
tree6cb096ade3e7db59cc91cd836d6e7de95a01cec4 /src/lua-script/script.h
parenta026db7389c15eb5a8905e6f04eb3a92bf31f9bc (diff)
add layout loading
Diffstat (limited to 'src/lua-script/script.h')
-rw-r--r--src/lua-script/script.h59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/lua-script/script.h b/src/lua-script/script.h
index 6bd07bb..0bb6451 100644
--- a/src/lua-script/script.h
+++ b/src/lua-script/script.h
@@ -47,6 +47,40 @@ const char *argent_script =
" end\n"
"\n"
"\n"
+ " function load_layouts(directory, parent, layouts)\n"
+ " local directory = add_end_slash(directory) or ''\n"
+ " local parent = parent or ''\n"
+ " local layouts = layouts or {}\n"
+ "\n"
+ " local fullpath = parent..directory\n"
+ " local dirs, files = argent.scanDirectory(argent.config.layout_directory..fullpath)\n"
+ "\n"
+ " for _, file in ipairs(files) do\n"
+ " if string.match(file, '%.lua$') then\n"
+ " local basename = string.gsub(file, '%.lua$', '')\n"
+ " local id = string.gsub(fullpath..basename, '/', '.')\n"
+ " argent.log('debug', fmt('loading layout %q', id))\n"
+ " success, result = pcall(loadfile(argent.config.layout_directory..fullpath..file), 0, 1)\n"
+ " if not success then\n"
+ " argent.log('error', result)\n"
+ " argent.log('warn', fmt('layout %q will not be available', id))\n"
+ " else\n"
+ " layouts[id] = result\n"
+ " end\n"
+ " end\n"
+ " end\n"
+ "\n"
+ " for _, dir in ipairs(dirs) do\n"
+ " if dir ~= '.' and dir ~= '..' then\n"
+ " argent.log('debug', fmt('loading layouts from %q', parent..directory))\n"
+ " load_layouts(dir, parent..directory, layouts)\n"
+ " end\n"
+ " end\n"
+ "\n"
+ " return layouts\n"
+ " end\n"
+ "\n"
+ "\n"
" function setup(config)\n"
" argent.log('debug', 'begin setup')\n"
" \n"
@@ -73,6 +107,13 @@ const char *argent_script =
" argent.log('info', 'noprocess: '..set_tostring(argent.config.noprocess))\n"
" argent.log('info', 'rss files: '..set_tostring(argent.config.rss_include))\n"
"\n"
+ " if argent.config.layout_directory then\n"
+ " argent.layouts = load_layouts()\n"
+ " else\n"
+ " argent.layouts = {}\n"
+ " end\n"
+ " argent.log('info', fmt('available layouts: %s', set_tostring(argent.layouts)))\n"
+ " \n"
" if argent.config.plugin_directory then\n"
" package.path = argent.config.plugin_directory..'?.lua;'..package.path\n"
" end\n"
@@ -116,11 +157,11 @@ const char *argent_script =
"\n"
" function obliterate_file(file, parent)\n"
" if argent.config.keep[file] then\n"
- " argent.log('debug', fmt('retaining file %q', file))\n"
+ " argent.log('debug', fmt('retaining file %q', parent..file))\n"
" return true\n"
" end\n"
"\n"
- " argent.log('debug', fmt('removing file %q', file))\n"
+ " argent.log('debug', fmt('removing file %q', parent..file))\n"
" os.remove(argent.config.output_directory..parent..file)\n"
" return false\n"
" end\n"
@@ -128,7 +169,7 @@ const char *argent_script =
"\n"
" function obliterate_dir(dir, parent)\n"
" if argent.config.keep[strip_end_slash(dir)] then\n"
- " argent.log('debug', fmt('retaining directory %q', dir))\n"
+ " argent.log('debug', fmt('retaining directory %q', parent..dir))\n"
" return true\n"
" end\n"
"\n"
@@ -173,11 +214,16 @@ const char *argent_script =
" function process_file(filename, parent)\n"
" if (is_dotfile(filename) and not argent.config.include[filename])\n"
" or argent.config.exclude[filename]\n"
- " then return end\n"
+ " then\n"
+ " argent.log('debug', fmt('will not process file %q', parent..filename))\n"
+ " return\n"
+ " end\n"
"\n"
" if string.match(filename, '%.lua$') and not argent.config.noprocess[filename] then\n"
+ " argent.log('debug', fmt('processing %q as lua file', parent..filename))\n"
" process_lua_file(filename, parent)\n"
" else\n"
+ " argent.log('debug', fmt('processing %q as regular file', parent..filename))\n"
" argent.copyFile(\n"
" argent.config.site_directory..parent..filename,\n"
" argent.config.output_directory..parent..filename\n"
@@ -200,7 +246,10 @@ const char *argent_script =
" function process_dir(directory, parent)\n"
" if (is_dotfile(directory) and not argent.config.include[strip_end_slash(directory)])\n"
" or argent.config.exclude[strip_end_slash(directory)]\n"
- " then return end\n"
+ " then\n"
+ " argent.log('debug', fmt('will not process directory %q', parent..directory))\n"
+ " return\n"
+ " end\n"
"\n"
" if not directory_exists(directory, parent) then\n"
" argent.createDirectory(argent.config.output_directory..parent..directory)\n"