HTML Tag functions?

Guiserver, GTK-server, OpenGL, PostScript,
HTML 5, MIDI, IDE

HTML Tag functions?

Postby jazper » Fri Dec 13, 2013 5:14 pm

Some time ago, one of the frequent contributors posted some code showing how to do HTML tags. I think it was in a context for each tag. Since bookmarking that, my hard disk died, and some bookmarks with it, though I had copies of all the main stuff.

Please can someone point me to this post, or the code in it? For example, a function called as (h1 string) would produce
Code: Select all
<h1>string</h1>
.

It was better than this, though, because it included args, allowing for classes etc.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: HTML Tag functions?

Postby xytroxon » Fri Dec 13, 2013 9:54 pm

I did, here is some experimental code.

Put into file named sxmlhtml.lsp

out put = test.htm

--xytoxon
sxmlhtml.tar
sxmlhtml.tar
(6 KiB) Downloaded 142 times
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976
xytroxon
 
Posts: 295
Joined: Tue Nov 06, 2007 3:59 pm

Re: HTML Tag functions?

Postby hilti » Sun Dec 15, 2013 11:17 am

I like this approach, available on Github

HTML Domain Specific Language (DSL) for newLISP
———————————————————————————————————————————————

The idea is to be able to write newlisp code as if you were writing HTML,
avoiding the use of template tags.

So instead of writing:

<html lang="en">
<head>
<title><% (print "This is my title") %></title>
</head>
</html>

Were you have to use an opening <% and a closing %> each time you need to
insert newlisp code, you write:

(html "lang=en"
(head ""
(title "" "This is my title")))

And everything is newlisp code.

To achieve this every HTML5 tag has it's counterpart function.

Every function needs at least one parameter for the inner code, hence the empty
strings in the example above. Also they can have any number of parameters
after, which are considered to be the code or text between opening and closing
tag.

Further parameters are concatenated to second one.

Every function returns a string with the computed html code.


https://github.com/conan-lugmen/newlisp-hin
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de
hilti
 
Posts: 139
Joined: Sun Apr 19, 2009 10:09 pm
Location: Hannover, Germany

Re: HTML Tag functions?

Postby conan » Sun Dec 15, 2013 3:36 pm

I haven't touched that code in some time now. Furthermore I have some un-pushed changes here in my disc, I changed several things to make it easier to use, for example, to avoid:

Every function needs at least one parameter for the inner code, hence the empty
strings in the example above.


There's no need for that in the new code.

However I stumped into some hard-to-debug (for me, cause I'm a moron) stuff which I cannot recall right now and then life got me away from this project.

What xytoxon posted works nice. My approach convoluted things just to have this one benefit: to validate HTML code at generation. However with all this TDD approach everybody has jumped in, which include tests for views, I'm not sure anymore if my approach adds any value.

So I'm kind of reluctant to review that code. But if someone here has interest. I can at least push the changes I got and a note with the failing bits, so someone can start from there.
conan
 
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: HTML Tag functions?

Postby xytroxon » Sun Dec 15, 2013 8:49 pm

Any improvements are welcome! I am unable to spend much time on it (or the internet) right now. I like how the recursiveness collapses into a single string, and being able to use newLISP comments too. Of course, the method of sticking the attributes into <tag></tag> isn't too elegant, but it works after a fashion ;o)

-- xytroxon

P.S. You can run the string through replace for <br></br> -> <br />
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976
xytroxon
 
Posts: 295
Joined: Tue Nov 06, 2007 3:59 pm

Re: HTML Tag functions?

Postby jazper » Tue Dec 17, 2013 8:34 pm

Much appreciated, thanks xytotron. I very much admire that code.

The .lsp file ran straight off in Win 7, but returned
Code: Select all
ERR: list or string expected : nil
called from user defined function page1:pre
called from user defined function page1:b
called from user defined function page1:p
called from user defined function page1:body
called from user defined function page1:html
called from user defined function page1:xml-document
on my 64 bit Crunchbang box. I guess that's line endings when unzipping or something. Will have a look tomorrow when I'm fresh.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: HTML Tag functions?

Postby jazper » Wed Dec 18, 2013 4:57 am

Interesting. Just gets curiouser and curiouser. On my Win 7 Dell at home, ran sxmlhtml.lsp in Scite: it ran perfectly, and produced test.html without a hitch. But newLISP GS editor produced exactly the error found on my Crunchbang 64 bit box.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: HTML Tag functions?

Postby jazper » Thu Dec 19, 2013 11:20 pm

After testing, the code works when called from newLISP, so I'm not bothered about IDE problems.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: HTML Tag functions?

Postby xytroxon » Thu Dec 19, 2013 11:35 pm

The only thing I can think of, is to try and change the two places \026 is used to a different number.

I remember that I had a strange problem on Windows when using \000 so I changed it tp \026

\026 is the ascii code for end of file

Try \001 or any number less than the value for space (Avoid the decimal values for "\t" "\r" "\n").

(string "\026" str ">") -> (string "\001" str ">")

(replace ">\026" xml-string "") -> (replace ">\001" xml-string "")

Or try increasing the stack size when running newlisp.

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976
xytroxon
 
Posts: 295
Joined: Tue Nov 06, 2007 3:59 pm

Re: HTML Tag functions?

Postby Astrobe » Fri Dec 20, 2013 3:30 pm

I started to do something along these lines. The technique is similar to the one used by xytroxon, except the tags generate a tree of strings. Then a "render" procedure walks the tree and spit it out. I don't have the code because it's on my PC atm.

For tag attributes, after various attempts, I came up with a macro named "with:", which sets a global variable to be inserted by the "tag" procedure that implements the tags. Most tags are basically like
Code: Select all
(define (html) (tag "html" (args))
.
Code: Select all
(set 'html (curry "html"))
would have been cool here, but it doesn't work there because the rest of the arguments are the body, and curry only works on 2-arguments procedures.

So the code for a page writes:
Code: Select all
(html (body
(with: "type=submit" (form "etc."))))

The drawback is that the order is reversed compared to regular html.The advantage is that one deosn't have 'noise' parameters. "with:" has to be a macro because newlisp evaluates the arguments first, and the global is not set a the right time.
Astrobe
 
Posts: 38
Joined: Mon Jan 11, 2010 9:41 pm

Re: HTML Tag functions?

Postby jazper » Mon Dec 23, 2013 9:17 pm

I tried the changes suggested by xytotron (replacing \026 with \001), without success.

It still runs fine directly from newLISP or in Scite, which calls newLISP switched as follows:
Code: Select all
newlisp -n -c -s 400000

Since it runs fine from newLISP without setting a stack size, I haven't tried to find or fiddle with defaults called from the IDE. For my next trick, a hex editor will be used to see if there are line end problems. I remember fixing something like this in the past.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa


Return to newLISP Graphics & Sound

Who is online

Users browsing this forum: No registered users and 2 guests

cron