Markup: link() got an additional argument for passing extra attributes,
authorTimm S. Mueller <tmueller@neoscientists.org>
Sun, 21 Feb 2010 01:14:21 +0100
changeset 2568cd1538fbd18
parent 255 63e76b4e3956
child 257 058f96953252
Markup: link() got an additional argument for passing extra attributes,
image() now composes an alt tag from the file name if no extra argument is
given, the parser now recognizes an additional syntax for passing extra
arguments to links and images, respectively; the contactform extension script
now additionally handles a phone number; Loona: the overridden Markup:link()
function now propagates the extra arguments to the HTML output; table
extension script added
README
cgi-bin/tek/class/loona.lua
cgi-bin/tek/class/markup.lua
extensions/contactform.lua
extensions/table.lua
locale/de
locale/en
     1.1 --- a/README	Tue Aug 11 15:24:02 2009 +0200
     1.2 +++ b/README	Sun Feb 21 01:14:21 2010 +0100
     1.3 @@ -26,10 +26,6 @@
     1.4  example, LOona has recently been tailored to a telephony system under
     1.5  resource-constrained conditions.
     1.6  
     1.7 -LOona was originally created during an employment at the LSE Leading
     1.8 -Security Experts GmbH, and thanks to LSE's friendly support, it has
     1.9 -been continued as an Open Source effort.
    1.10 -
    1.11  
    1.12  === Selected features ===
    1.13  
    1.14 @@ -160,8 +156,8 @@
    1.15     index.html.jp
    1.16  
    1.17   - 8. You should now be able to login to an empty LOona site at
    1.18 - {{http://mycompany.com/}}, and complete your setup using a
    1.19 - browser.
    1.20 + {{http://mycompany.com/index.lua/login}}, and complete your setup
    1.21 + using a browser.
    1.22  
    1.23  
    1.24  === Completing the site setup using a browser ===
    1.25 @@ -267,7 +263,6 @@
    1.26   [[http://www.keplerproject.org/]]
    1.27   - LOona homepage:
    1.28   [[http://loona.neoscientists.org/]]
    1.29 - - Originally developed at:
    1.30 - [[http://www.lsexperts.de/]]
    1.31   - Project hosted at:
    1.32   [[http://www.neoscientists.org/]]
    1.33 +
     2.1 --- a/cgi-bin/tek/class/loona.lua	Tue Aug 11 15:24:02 2009 +0200
     2.2 +++ b/cgi-bin/tek/class/loona.lua	Sun Feb 21 01:14:21 2010 +0100
     2.3 @@ -41,7 +41,7 @@
     2.4  -------------------------------------------------------------------------------
     2.5  
     2.6  module("tek.class.loona", tek.class)
     2.7 -_VERSION = "LOona Class 5.10"
     2.8 +_VERSION = "LOona Class 6.0"
     2.9  
    2.10  -------------------------------------------------------------------------------
    2.11  --	Markup:
    2.12 @@ -74,13 +74,23 @@
    2.13  	return concat(t), ')%>'
    2.14  end
    2.15  
    2.16 -function Markup:link(link)
    2.17 +function Markup:link(link, extraargs)
    2.18  	local func = link:match("^(.*)%(%)$")
    2.19  	if func then
    2.20  		return '<%=loona:link("' .. '#' .. self:encodeurl(func, true) .. '", [[', ']])%>'
    2.21 -	elseif link:match("^%a*://.*$") then
    2.22 +	elseif link:match("^%a*://.*$") or link:match("^mailto:") then
    2.23 +		if extraargs then
    2.24 +			extraargs = " " .. extraargs .. " "
    2.25 +			return '<%=loona:extraelink("' .. self:encodeurl(link, true) .. '", [[',
    2.26 +				']], [[' .. extraargs .. ']])%>'
    2.27 +		end
    2.28  		return '<%=loona:elink("' .. self:encodeurl(link, true) .. '", [[', ']])%>'
    2.29  	else
    2.30 +		if extraargs then
    2.31 +			extraargs = " " .. extraargs .. " "
    2.32 +			return '<%=loona:extralink("' .. link .. '", [[',
    2.33 +				']], [[' .. extraargs .. ']])%>'
    2.34 +		end
    2.35  		return '<%=loona:link("' .. link .. '", [[', ']])%>'
    2.36  	end
    2.37  end
    2.38 @@ -619,6 +629,14 @@
    2.39  	' class="intlink"')
    2.40  end
    2.41  
    2.42 +function Loona:extralink(section, text, extraargs, ...)
    2.43 +	if extraargs then
    2.44 +		return self:ilink(self:href(section, ...), text or section,
    2.45 +		' ' .. extraargs .. ' class="intlink"')
    2.46 +	end
    2.47 +	return self:link(section, text, ...)
    2.48 +end
    2.49 +
    2.50  
    2.51  --	external link (opens in a new window), no argument propagation
    2.52  
    2.53 @@ -626,6 +644,10 @@
    2.54  	return self:ilink(target, text or target, self.config.extlinkextra)
    2.55  end
    2.56  
    2.57 +function Loona:extraelink(target, text, extraargs)
    2.58 +	return self:ilink(target, text or target, extraargs or self.config.extlinkextra)
    2.59 +end
    2.60 +
    2.61  
    2.62  --	plain link, no implicit argument propagation
    2.63  
     3.1 --- a/cgi-bin/tek/class/markup.lua	Tue Aug 11 15:24:02 2009 +0200
     3.2 +++ b/cgi-bin/tek/class/markup.lua	Sun Feb 21 01:14:21 2010 +0100
     3.3 @@ -563,7 +563,7 @@
     3.4  	end
     3.5  end
     3.6  
     3.7 -function Markup:link(link)
     3.8 +function Markup:link(link, extraargs)
     3.9  	--local isurl = link:match("^%a*://.*$")
    3.10  	local func = link:match("^(.*)%(%)$")
    3.11  	if func then
    3.12 @@ -590,8 +590,10 @@
    3.13  end
    3.14  
    3.15  function Markup:image(link, extra)
    3.16 -	return '<img src="' .. self:encodeurl(link, true) .. '" ' ..
    3.17 -		(extra or "") .. ' alt="image" />'
    3.18 +	if not extra or extra == "" then
    3.19 +		extra = 'alt="' .. (link:match("/([^/]+)$") or "image") .. '"'
    3.20 +	end
    3.21 +	return '<img src="' .. self:encodeurl(link, true) .. '" ' .. extra .. ' />'
    3.22  end
    3.23  
    3.24  function Markup:document()
    3.25 @@ -1024,6 +1026,14 @@
    3.26  										title = link:match("^#?(.*)$")
    3.27  									end
    3.28  								end
    3.29 +								local extraargs
    3.30 +								if not link then
    3.31 +									a, title, link, extraargs, b = -- [[text][...][extraargs]]
    3.32 +										line:match("^(.-)%[%[([^%]]-)%]%[([^%]]-)%](%b[])%](.*)%s*$")
    3.33 +									if extraargs then
    3.34 +										extraargs = extraargs:match("^%[(.*)%]$")
    3.35 +									end
    3.36 +								end
    3.37  								if not link then -- class:function()
    3.38  									a, link, b = line:match("^(.-)(%a[%w_:.]-%(%))(.*)%s*$")
    3.39  								end
    3.40 @@ -1039,12 +1049,16 @@
    3.41  										if self.context.firstfragment then
    3.42  											doout("gettext", "")
    3.43  										end
    3.44 -										push("link", link)
    3.45 +										push("link", link, extraargs)
    3.46  										if b == "" then b = " " end
    3.47  										pushfragment(b)
    3.48  										pushcontext("link", title or link)
    3.49  									else
    3.50 -										pushfragment("[[", title or link, "][", link, "]]", b)
    3.51 +										if extraargs then
    3.52 +											pushfragment("[[", title or link, "][", link, "](", extraargs, ")]", b)
    3.53 +										else
    3.54 +											pushfragment("[[", title or link, "][", link, "]]", b)
    3.55 +										end
    3.56  										pushfragment(a)
    3.57  										pushcontext()
    3.58  									end
    3.59 @@ -1054,6 +1068,15 @@
    3.60  						end
    3.61  
    3.62  						if feature["i"] then
    3.63 +							
    3.64 +							-- imglink with extra arguments: @@...@ extraargs @
    3.65 +							line = line:gsub("@@(.*)(%b@@)", function(link, extra)
    3.66 +								extra = extra:match("^@(.*)@$")
    3.67 +								push("image", link, extra)
    3.68 +								pop()
    3.69 +								return ""
    3.70 +							end)
    3.71 +						
    3.72  							-- imglink (@@...@@), (@<...<@), (@>...>@)
    3.73  							line = line:gsub("@([@<>])(.*)([@<>])@", function(s1, link, s2)
    3.74  								local extra
     4.1 --- a/extensions/contactform.lua	Tue Aug 11 15:24:02 2009 +0200
     4.2 +++ b/extensions/contactform.lua	Sun Feb 21 01:14:21 2010 +0100
     4.3 @@ -15,7 +15,7 @@
     4.4  	return s
     4.5  end
     4.6  
     4.7 -local function sendmail(fromadr, toadr, prefix, name, subject, body)
     4.8 +local function sendmail(fromadr, toadr, prefix, name, subject, phone, body)
     4.9  	if fromadr and toadr then
    4.10  		fromadr = purify(fromadr or "", 60):match("^%S+@%w+[%w._%-]*%.%w+$")
    4.11  		toadr = purify(toadr or "", 60):match("^%S+@%w+[%w._%-]*%.%w+$")
    4.12 @@ -23,6 +23,7 @@
    4.13  			name = purify(name or "", 80)
    4.14  			subject = purify(subject or "", 120)
    4.15  			body = body:sub(1, 2000):gsub("\r", "")
    4.16 +			phone = purify(phone or "", 80)
    4.17  			prefix = prefix and prefix .. " " or ""
    4.18  			local f = io.popen("sendmail -t", "w")
    4.19  			if f then
    4.20 @@ -30,6 +31,9 @@
    4.21  				f:write("Reply-To: ", fromadr, "\n")
    4.22  				f:write("To: ", toadr, "\n")
    4.23  				f:write("Subject: ", prefix, subject, "\n\n")
    4.24 +				if phone ~= "" then
    4.25 +					f:write("Phone-Number: ", phone, "\n\n")
    4.26 +				end
    4.27  				f:write(body)
    4.28  				return 1 -- success
    4.29  			end
    4.30 @@ -57,25 +61,26 @@
    4.31  name = args.mailname
    4.32  subject = args.mailsubject
    4.33  body = args.mailbody
    4.34 +phone = args.mailphone
    4.35  
    4.36  
    4.37  assert(to, "No destination mail address specified")
    4.38  
    4.39  ret = not args.sendform and 0
    4.40 -	or sendmail(from, to, prefix, name, subject, body)
    4.41 +	or sendmail(from, to, prefix, name, subject, phone, body)
    4.42  
    4.43  %>
    4.44  
    4.45  <%if ret == 1 then%>
    4.46 -	
    4.47 +
    4.48  	<%printsuccessmsg()%>
    4.49  
    4.50  <%elseif ret == -1 then%>
    4.51 -	
    4.52 +
    4.53  	<%printerrormsg()%>
    4.54  
    4.55  <%elseif ret == -2 then%>
    4.56 -	
    4.57 +
    4.58  	<%printfailmsg()%>
    4.59  
    4.60  <%else%>
    4.61 @@ -98,6 +103,10 @@
    4.62  				<br />
    4.63  				<input size="70" maxlength="50" name="mailsubject" />
    4.64  				<br />
    4.65 +				<label><%=loona.locale.CONTACTFORM_PHON%></label>
    4.66 +				<br />
    4.67 +				<input size="50" maxlength="50" name="mailphone" />
    4.68 +				<br />
    4.69  				<label><%=loona.locale.CONTACTFORM_BODY%></label>
    4.70  				<br />
    4.71  				<textarea cols="65" rows="10" name="mailbody"></textarea>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/extensions/table.lua	Sun Feb 21 01:14:21 2010 +0100
     5.3 @@ -0,0 +1,16 @@
     5.4 +<%
     5.5 +columns = arg[1]
     5.6 +rows = (#arg - 1) / columns
     5.7 +%>
     5.8 +
     5.9 +<table>
    5.10 +	<%for y = 0, rows - 1 do%>
    5.11 +		<tr>
    5.12 +			<%for x = 0, columns - 1 do%>
    5.13 +				<td class="col<%=x+1%>">
    5.14 +					<%arg[y * columns  + x + 2]()%>
    5.15 +				</td>
    5.16 +			<%end%>
    5.17 +		</tr>
    5.18 +	<%end%>
    5.19 +</table>
     6.1 --- a/locale/de	Tue Aug 11 15:24:02 2009 +0200
     6.2 +++ b/locale/de	Sun Feb 21 01:14:21 2010 +0100
     6.3 @@ -59,6 +59,7 @@
     6.4  CONTACTFORM_NAME = "Name",
     6.5  CONTACTFORM_ADDR = "Ihre e-Mail-Adresse",
     6.6  CONTACTFORM_SUBJ = "Betreff",
     6.7 +CONTACTFORM_PHON = "Telefon",
     6.8  CONTACTFORM_BODY = "Nachricht",
     6.9  CONTACTFORM_SEND = "Senden",
    6.10  CONTACTFORM_MAIL_SENT = "Ihre Mail an uns wurde verschickt.",
     7.1 --- a/locale/en	Tue Aug 11 15:24:02 2009 +0200
     7.2 +++ b/locale/en	Sun Feb 21 01:14:21 2010 +0100
     7.3 @@ -59,6 +59,7 @@
     7.4  CONTACTFORM_NAME = "Name",
     7.5  CONTACTFORM_ADDR = "Your e-Mail address",
     7.6  CONTACTFORM_SUBJ = "Subject",
     7.7 +CONTACTFORM_PHON = "Phone",
     7.8  CONTACTFORM_BODY = "Message",
     7.9  CONTACTFORM_SEND = "Send",
    7.10  CONTACTFORM_MAIL_SENT = "Your mail has been sent.",