cgi-bin/tek/class/loona.lua
changeset 219 7cb83473b4dd
parent 213 44bbb49bd40c
child 222 cb91d3398f6e
     1.1 --- a/cgi-bin/tek/class/loona.lua	Tue Nov 27 14:36:00 2007 +0100
     1.2 +++ b/cgi-bin/tek/class/loona.lua	Sat Dec 15 02:35:05 2007 +0100
     1.3 @@ -12,9 +12,7 @@
     1.4  local cgi = require "tek.class.cgi"
     1.5  local Request = require "tek.class.cgi.request"
     1.6  local util = require "tek.class.loona.util"
     1.7 -local markup = require "tek.class.loona.markup"
     1.8 --- local db = require "tek.lib.debug"
     1.9 --- db.level = 4
    1.10 +local Markup = require "tek.class.markup"
    1.11  
    1.12  local boxed_G = {
    1.13  	string = string, table = table,
    1.14 @@ -39,7 +37,49 @@
    1.15  -------------------------------------------------------------------------------
    1.16  
    1.17  module("tek.class.loona", Class)
    1.18 -_VERSION = "LOona Class 5.0"
    1.19 +_VERSION = "LOona Class 5.1"
    1.20 +
    1.21 +-------------------------------------------------------------------------------
    1.22 +--	Markup:
    1.23 +-------------------------------------------------------------------------------
    1.24 +
    1.25 +Markup = Markup:newClass()
    1.26 +
    1.27 +function Markup:init()
    1.28 +	self.depth = 1
    1.29 +	return ''
    1.30 +end
    1.31 +
    1.32 +function Markup:exit()
    1.33 +	return ''
    1.34 +end
    1.35 +
    1.36 +function Markup:argument(name, text)
    1.37 +	return ', function()%>', '<%end'
    1.38 +end
    1.39 +
    1.40 +function Markup:func(is_dynamic, args)
    1.41 +	if is_dynamic then
    1.42 +		self.is_dynamic_content = true
    1.43 +	end
    1.44 +	local t = { '<%loona:include("', args[1], '"' }
    1.45 +	table.remove(args, 1)
    1.46 +	for _, v in ipairs(args) do
    1.47 +		insert(t, ',' .. v)
    1.48 +	end
    1.49 +	return table.concat(t), ')%>'
    1.50 +end
    1.51 +
    1.52 +function Markup:link(link)
    1.53 +	local func = link:match("^(.*)%(%)$")
    1.54 +	if func then
    1.55 +		return '<%=loona:link("' .. '#' .. self:encodeurl(func, true) .. '", [[', ']])%>'
    1.56 +	elseif link:match("^%a*://.*$") then
    1.57 +		return '<%=loona:elink("' .. self:encodeurl(link, true) .. '", [[', ']])%>'
    1.58 +	else
    1.59 +		return '<%=loona:link("' .. link .. '", [[', ']])%>'
    1.60 +	end
    1.61 +end
    1.62  
    1.63  -------------------------------------------------------------------------------
    1.64  --	class Session:
    1.65 @@ -526,7 +566,7 @@
    1.66  		table.insert(href, arg.name .. "=" .. cgi.encodeurl(arg.value))
    1.67  	end
    1.68  	if anch then
    1.69 -		insert(href, anch)
    1.70 +		table.insert(href, anch)
    1.71  	end
    1.72  	return table.concat(href)
    1.73  end
    1.74 @@ -1544,7 +1584,11 @@
    1.75  
    1.76  
    1.77  function Loona:domarkup(s)
    1.78 -	return markup.load(s)
    1.79 +	local t = { }
    1.80 +	local is_dynamic = Markup:new {
    1.81 +		input = s, features = "hespcadlintf",
    1.82 +		indentchar = " ", wrfunc = function(s) table.insert(t, s) end }:run()
    1.83 +	return table.concat(t), is_dynamic
    1.84  end
    1.85  
    1.86  
    1.87 @@ -1682,17 +1726,23 @@
    1.88  	self.document = self.requestdocument .. "/" .. self.sectionpath
    1.89  	if self.authuser then
    1.90  		self.getdocname = function(self, path)
    1.91 -			return self.requestdocument .. "/" .. (path or self.sectionpath)
    1.92 +			local url, anch = path:match("^([^#]*)(#?.*)$")
    1.93 +			path = url ~= "" and url
    1.94 +			anch = anch or ""
    1.95 +			return self.requestdocument .. "/" .. (path or self.sectionpath) .. anch
    1.96  		end
    1.97  	else
    1.98  		self.getdocname = function(self, path, haveargs)
    1.99 +			local url, anch = path:match("^([^#]*)(#?.*)$")
   1.100 +			path = url ~= "" and url
   1.101 +			anch = anch or ""
   1.102  			local dyn, exists
   1.103  			dyn, path, exists = self:isdynamic(path or self.sectionpath)
   1.104  			if dyn or haveargs or not exists then
   1.105 -				return self.requestdocument .. "/" .. path
   1.106 +				return self.requestdocument .. "/" .. path .. anch
   1.107  			end
   1.108  			path = path == self.config.defname and "index" or path
   1.109 -			return "/" .. path:gsub("/", "_") .. ".html"
   1.110 +			return "/" .. path:gsub("/", "_") .. ".html" .. anch
   1.111  		end
   1.112  	end
   1.113