diff -r e2face1be50e -r 3975fa5ed630 handlers/render.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/handlers/render.lua Sat Sep 12 21:27:57 2009 +0300 @@ -0,0 +1,104 @@ + +module("handlers.render", package.seeall) + +require('markdown') +require('etree') +require('err') +require('environment') +require('config') + +-- +-- Phase 1: load & markup +-- + +local phase1_cache={} + +function phase1(file, env) + --local dir = string.match(file, "(.*)/[^/]*") + --local env = get_environment(dir) + local f = io.open(file, 'r') + local data = '' + local in_meta = false + local linenum=1 + + for l in f:lines() do + if string.match(l, config.meta_marker) then + in_meta = not in_meta + elseif in_meta then + local key, val = string.match(l, "%s*([^:]*)%s*:%s*(.*)%s*") + if key and val then + env[key] = val + else + err.file_pos(file, linenum, "meta data syntax error") + end + else + data = data.."\n"..l + end + linenum = linenum+1 + end + + f:close() + + local data2=markdown(data) + + phase1_cache[file]=data2 +end + + +-- +-- Phase 2: Tag processing +-- + +-- Vaiko silti toistepäin? Inlinejen tagit pitää +-- prosessoida ennen inlinetystä. Mutta toisaalta +-- templateen myös prosessointi. + +local function tag_lgen_inline(env, t) + a.tag="div" + -- todo: get inlineable stuff from attrs + a.attr.class="lgen:inline" + --table.insert(a, get_inline(env, a) +end + +local function tag_lgen_a(env, t) +end + + +local operations={ + ["lgen:inline"] = tag_lgen_inline, + ["a"] = tag_lgen_a, +} + +local function scan(env, et) + for _, v in ipairs(et) do + if type(v)=="table" then + operations[v.tag](env, v) + end + end +end + +setmetatable(operations, { __index = function() return scan end }) + +function phase2(file, env) + local data=phase1_cache[file] + --print(data) + --print("----------") + local et, msg, line, col, pos = etree.fromstring([[
]]..data..'') + --local et, msg, line, col, pos = lom.parse("