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
<h1>string</h1>
.
It was better than this, though, because it included args, allowing for classes etc.
I did, here is some experimental code.
Put into file named sxmlhtml.lsp
out put = test.htm
--xytoxon[attachment=0]sxmlhtml.tar[/attachment]
I like this approach, available on Github
Quote
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
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:
Quote
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.
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> ->
Much appreciated, thanks xytotron. I very much admire that code.
The .lsp file ran straight off in Win 7, but returned
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.
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.
After testing, the code works when called from newLISP, so I'm not bothered about IDE problems.
The only thing I can think of, is to try and change the two places