Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: CGI scripting with Lua< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 16 2007,03:37 QUOTE

Yeah, I know...my CGI tests with Bash didn't go very far yet.  This isn't because Bash isn't worthy, of course....I use Bash more than anything else.

But at this time I'm trying to learn more about Lua scripting beyond just making GUI frontends to commandline tools, and since I've also been experimenting with dynamic web pages I thought Lua CGI would be a good place to get involved.  My main goal is to create a minimalist wiki, but that will be after I learn more about it.

First thing was a function to print the headers of an html document. My current function is static, with the exception of the page title:
Code Sample
function html_begin(title)
print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n'..
'"http://www.w3.org/TR/html4/strict.dtd">\n'..
'<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">\n'..
'<title>'..title..'</title>\n'..
'<link href="/style.css" rel="stylesheet" type="text/css"></head><body>')
end


I did this particularly because I can never remember what to use for the doctype.  But now I want to make it more dynamic, so you can pass a doctype and style sheet to the function.  The problem is that I'm not sure if generating the doctype is acceptable from a standards viewpoint.  Note this page:
http://www.w3.org/QA/2002/04/valid-dtd-list.html
At the bottom, where it says "Authoring tools MUST NOT use the following list". I wonder if CGI page generation is considered an authoring tool.

Any thoughts?

EDIT: Oh...I just noticed something. That list apparently pertains to specific dtd addresses.  I thought they meant that authoring tools should not set certain doc types (maybe because it couldn't guarantee the page conforms to the doctype or something).  Anyway, I was mistaken and apparently I can go ahead with my plan.

So I guess it's going to be something like this:
Code Sample
function html_begin(doctype,title,style)

I just need to contemplate the most efficient way to check for various doctypes, since there seems to be slight changes in syntax from version to version....


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 17 2007,03:07 QUOTE

Just getting some basic HTML generated is more complicated than I thought...particularly when trying to adhere to w3c standards.  Anyway, I got a few things done that will hopefully make it a little easier....
Code Sample

-- create the document type declaration (dtd)
function add_doctype(major,minor)
-- major: 2.0 3.2 4.0 4.01 x1.0 x1.1 minor: strict transitional frameset
local def_doctype = "HTML 4.01"
local def_dtd = "\"http://www.w3.org/TR/html4/strict.dtd\""
local doctype,dtd
if major == "4.01" then
 if minor == "transitional" then doctype,dtd = "HTML 4.01 Transitional","\"http://www.w3.org/TR/html4/loose.dtd\""
 elseif minor == "frameset" then doctype,dtd = "HTML 4.01 Frameset","\"http://www.w3.org/TR/html4/frameset.dtd\""
 else doctype,dtd = "HTML 4.01","\"http://www.w3.org/TR/html4/strict.dtd\""
 end
elseif major == "x1.0" then
 if minor == "transitional" then doctype,dtd = "XHTML 1.0 Transitional","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
 elseif minor == "frameset" then doctype,dtd = "XHTML 1.0 Frameset","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""
 else doctype,dtd = "XHTML 1.0 Strict","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""
 end
elseif major == "x1.1" then doctype,dtd = "XHTML 1.1",""
elseif major == "2.0" then doctype,dtd = "HTML 2.0",""
elseif major == "3.2" then doctype,dtd = "HTML 3.2 Final",""
else doctype,dtd = def_doctype,def_dtd
end
print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD '..doctype..'//EN"\n'..dtd)
end
-- EXAMPLES
-- add_doctype("4.01","transitional") -> HTML 4.01 Transitional
-- add_doctype() -> HTML 4.01 Strict (the default)
-- add_doctype("x1.0") -> XHTML 1.0 Strict
-- add doctype(nil,"transitional") -> if major is nil, it uses the default HTML 4.01 Strict
   
-- create the "head" part and open the body
function html_begin(title,style,charset)
if not title then title = "untitled" end
if not charset then charset = "ISO-8859-1" end
print('<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset='..charset..'" />\n<title>'..title..'</title>')
if style then print('<link href="'..style..'" rel="stylesheet" type="text/css" />') end
print('</head>\n\n<body>\n')
end
-- EXAMPLES
-- html_begin("my page","/css/mystyle.css") -> uses iso-8859-1 charset and custom stylesheet
-- html_begin("my page") -> uses iso-8859-1 charset and no stylesheet
-- html_begin("my page",nil,"utf-8") -> uses utf-8 charset and no stylesheet
-- html_begin() -> uses iso-8859-1 charset, no stylesheet, and page title "untitled"

-- a simplified version that combines both of the above functions,
-- with a static doctype declaration (XHTML 1.0 Strict)
function my_html_begin(title,style,charset)
if not title then title = "untitled" end
if not charset then charset = "ISO-8859-1" end
print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n'..
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'..
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'..
'<head>\n<meta http-equiv="Content-Type" content="text/html; charset='..charset..'" />')
if style then print('<link href="'..style..'" rel="stylesheet" type="text/css" />') end
print('<title>'..title..'</title>\n</head>\n\n<body>\n')
end


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Feb. 17 2007,07:33 QUOTE

Just a misc suggestion...

If you want to easily check your doc for w3c standards, it might be nice to have an (optional) link to the w3c html validator.
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 17 2007,15:55 QUOTE

That's a good idea...I think i'll do that. I was wondering about the issue of putting in a strict dtd but at the same time possibly having functions that create conflicting html.
I'm using the offline HTML Validator extension with Firefox, but this is not always going to be the case.

I'm also wondering if that first function is just too much code for too little result.  I'm thinking of just going with the third one, although I don't know how well strict XHTML works for old browsers.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
3 replies since Feb. 16 2007,03:37 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: CGI scripting with Lua

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code