handlers/render.lua

changeset 7
038275cd92ed
parent 4
4cb0d1dbc65b
child 15
82d254b8f01e
--- a/handlers/render.lua	Sun May 07 20:02:53 2017 +0100
+++ b/handlers/render.lua	Tue Jan 16 16:39:48 2018 +0000
@@ -1,18 +1,21 @@
 
-module("handlers.render", package.seeall)
+--@module handlers.render
+
+local handlers_render={}
 
 local ltp=require('ltp.template')
-require('markdown')
-require('config')
-require('path')
-require('filecache')
-require('log')
+local markdown=require('markdown')
+local config=require('config')
+local path=require('path')
+local filecache=require('filecache')
+local log=require('log')
+local dependency=require('dependency')
 
 --
 -- Phase 1: load & markup
 --
 
-function phase1(file, env)
+function handlers_render.phase1(file, env)
     local f = io.open(path.join(env.paths.src, file), 'r')
     local data = nil
     local in_meta = false
@@ -63,14 +66,14 @@
     env.pages[file]=page
 end
 
-function process_lua(template, env)
+function handlers_render.process_lua(template, env)
     env=table.join(env, {env=env}) -- TODO: should use __index
     --return ltp.render(nil, 1, template, env, {}, "<%", "%>", {})
     return ltp.render_template(template, "<%", "%>", 
                                ltp.merge_index(env, _G))
 end
 
-function env_for(file, env, path_prefix)
+function handlers_render.env_for(file, env, path_prefix)
     local newenv=table.copy(env)
     
     newenv.base_url=path.to_root(file)
@@ -80,16 +83,16 @@
     return newenv
 end
 
-function render(file, env, path_prefix)
+function handlers_render.render(file, env, path_prefix)
     local data=env.pages[file].data
     if data then
-        local newenv=env_for(file, env, path_prefix)
-        local data2=process_lua(data, newenv)
+        local newenv=handlers_render.env_for(file, env, path_prefix)
+        local data2=handlers_render.process_lua(data, newenv)
         return markdown(data2)
     end
 end
 
-function phase2(file, env)
+function handlers_render.phase2(file, env)
     local page=env.pages[file]
     local src = path.join(env.paths.src, file)
     local dst = path.join(env.paths.dst, page.destination)
@@ -112,11 +115,11 @@
     
     if build then 
         log.log("Render "..file.."\n")
-        local content=render(file, env)
+        local content=handlers_render.render(file, env)
         local page_template=filecache.get(tmpl)
 
-        local newenv=table.join({content=content}, env_for(file, env))
-        local data2=process_lua(page_template, newenv)
+        local newenv=table.join({content=content}, handlers_render.env_for(file, env))
+        local data2=handlers_render.process_lua(page_template, newenv)
         
         log.log("Write "..page.destination.."\n")
         local f=io.openX(dst, "w")
@@ -124,3 +127,4 @@
     end
 end
 
+return handlers_render

mercurial