| 1 |
1 |
| 2 module("plugin.inline", package.seeall) |
2 --@ module plugin.inline |
| 3 |
3 |
| 4 require('handlers.render') |
4 local plugin_inline={} |
| 5 |
5 |
| 6 function find(env, opts) |
6 local path=require('path') |
| |
7 local handlers_render=require('handlers.render') |
| |
8 local filecache=require('filecache') |
| |
9 |
| |
10 function plugin_inline.find(env, opts) |
| 7 local found={} |
11 local found={} |
| 8 for name, _ in pairs(env.pages) do |
12 for name, _ in pairs(env.pages) do |
| 9 if string.match(name, opts.pattern) then |
13 if string.match(name, opts.pattern) then |
| 10 table.insert(found, name) |
14 table.insert(found, name) |
| 11 end |
15 end |
| 61 end |
65 end |
| 62 |
66 |
| 63 inlinepages[i]=table.copy(inlinepage) |
67 inlinepages[i]=table.copy(inlinepage) |
| 64 -- TODO: env väärin? |
68 -- TODO: env väärin? |
| 65 if not opts.no_content then |
69 if not opts.no_content then |
| 66 inlinepages[i].content=handlers.render.render(file, env, path_prefix) |
70 inlinepages[i].content=handlers_render.render(file, env, path_prefix) |
| 67 end |
71 end |
| 68 inlinepages[i].location=location |
72 inlinepages[i].location=location |
| 69 end |
73 end |
| 70 |
74 |
| 71 local tmplfile=path.join(env.paths.tmpl, opts.template or "inline.template") |
75 local tmplfile=path.join(env.paths.tmpl, opts.template or "inline.template") |
| 72 local inline_template=filecache.get(tmplfile) |
76 local inline_template=filecache.get(tmplfile) |
| 73 |
77 |
| 74 local newenv=table.join(env, { inlinepages=inlinepages }) |
78 local newenv=table.join(env, { inlinepages=inlinepages }) |
| 75 return handlers.render.process_lua(inline_template, newenv) |
79 return handlers_render.process_lua(inline_template, newenv) |
| 76 end |
80 end |
| 77 |
81 |
| 78 function inline(env, opts) |
82 function plugin_inline.inline(env, opts) |
| 79 return render(env, opts, find(env, opts)) |
83 return plugin_inline.render(env, opts, plugin_inline.find(env, opts)) |
| 80 end |
84 end |
| |
85 |
| |
86 return plugin_inline |