Giter VIP home page Giter VIP logo

cl-markup's People

Contributors

alexcharlton avatar fukamachi avatar guicho271828 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cl-markup's Issues

ESC macro

(defmacro esc (&rest forms)
  `(loop for form in forms
         collect (%escape-string-form form)))

Looks like there is a problem with this macro, a missing , or ,@.

`CL-markup` does not work for me. What is the correct way of installing it?

Hi,

I tried to use CL-MARKUP but it failed. I installed it with:

~ $ sbcl
This is SBCL 2.0.1.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload :cl-markup)
To load "cl-markup":
  Load 1 ASDF system:
    cl-markup
; Loading "cl-markup"

(:CL-MARKUP)

And then tried to test it with:

* (html
 (:body
  (:p :id "title" "aiueo")))

Which fails:

;   undefined function: :BODY
;   undefined function: COMMON-LISP-USER::HTML
;   undefined function: :P
;   Undefined functions:
;     :BODY HTML :P

Unfortunately, the installation section is empty.

Did I do something wrong during the installation?

Is there a way to fix it?

Thanks!

Markup in "if" statement output escaped html

It seems that using cl-markup inside a if statement the output is escaped. I made a little example where the 2 part fail to run on sbcl with this error :

The function :DIV is undefined.

(ql:quickload :cl-markup)

(print
 (cl-markup:markup
  (:div "Hello World")))

(print
 (cl-markup:markup
  (:div (if t
            (:div "Hello world")))))
```lisp

Performance

I've been testing the performance of different Common Lisp template libraries (And some of other languages) and have run into a pretty surprising result: cl-markup is significantly slower than Jinja2, and other templating engines.

The test is simple: A ten-thousand-element list is render in <li> tags and a similarly large hash table is rendered as a definition list.

The Jinja2 code is:

from datetime import datetime
from jinja2 import Template

TEMPLATE = '''
List:
<ol>
  {% for item in list %}
    <li>{{item}}</li>
  {% endfor %}
</ol>
Dictionary:
<dl>
  {% for key, value in dict.iteritems() %}
    <dt>{{key}}</dt>
    <dd>{{value}}</dd>
  {% endfor %}
</dl>
'''

LIST = [i for i in xrange(1,10000)]
DICT = {i:i*2 for i in LIST}

if __name__ == '__main__':
    template = Template(TEMPLATE)
    start = datetime.now()
    template.render(list=LIST, dict=DICT)
    end = datetime.now()
    print "Jinja2:", (end-start).microseconds/1e6

The cl-markup code is:

(ql:quickload :cl-markup)

(defparameter +list+ (loop for i from 0 to 10000 collecting i))
(defparameter +dict+ (let ((table (make-hash-table)))
                       (loop for item in +list+ do
                         (setf (gethash item table) item))
                       table))

(declaim (optimize (speed 3) (debug 0)))

(setf markup:*output-stream* nil)

(defun template ()
  (markup:markup
   (:ol
    (loop for item in +list+ do
      (markup:markup (:li item))))
   (:dl
    (loop for key being the hash-keys of +dict+
          for value being the hash-values of +dict+
          do
             (markup:markup (:dt key)
                            (:dd value))))))

(let ((start (get-internal-real-time)))
  (template)
  (format t "cl-markup: ~6$~&"
          (/ (- (get-internal-real-time) start)
             internal-time-units-per-second)))

I ran all the tests in a 64-bit Ubuntu Precise virtual machine with 2048 MB of RAM and two CPUs, on SBCL 1.0.55.0.debian. The results are pretty strange:

vagrant@precise64:~$ bash benchmark.sh 
Jinja2: 0.028667s
cl-markup: 0.247000s

Thoughts? Anything obvious I am doing wrong?

EDIT: Calling (compile 'template) brought it down to, 0.148000s, but it's still too high.

EDIT: After testing cl-who, it does the work in 0.027s, on par with Jinja but far slower than cl-markup.

Need of a "nil" body to close a tag

Hi,

edit: I was traped by something not identified in this message.

it wasn't obvious to me that tags are not closed if they have no body:

(markup (:br))
;=> "<br />"

whereas

(markup (:br nil))
;=> "<br></br>"

This can be an issue for html generation and is surely a trap easy to fall into.

It doesn't help to set the style:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *markup-language* :html))
(markup (:p))
;; => "<p>" (and nothing closing)

So am I doing sthg wrong and is it possible to have auto-closing tags with no body ?

code output not rendered. cannot embed lisp code.

i try to make use of cl-markup as follows. i have some functions that is created by markup to create parts of a single page.
and a big function that uses html and other little functions to create whole page.
but on browser this yields only created strings of html. only div in the code below is rendered.
(defun compose-home-page ()
(html
(:body
(morph-categories-axis)
(morph-time-axis)
(:div :style "height:45px; border:1px solid;"
(morph-name)
(morph-search)))))

and i cannot embed do lists inside the markup or html. this below code is rendered just like the above, all lines starting from dolist are ignored by the browser.
(defun compose-home-page ()
(html
(:body
(morph-categories-axis)
(morph-time-axis)
(:div :style "height:45px; border:1px solid;"
(morph-name)
(morph-search))
(dolist (itable (gather-all-artickles))
(dolist (iart itable)
(morph-artickle-section (getf iart :date)
(getf iart :author)
(getf iart :title)
(getf iart :body)
(getf iart :unique-id)
(getf iart :upvotes)
(getf iart :downvotes)))))))

the part of the first function above is similar to the followings. a part of it:
(setf time-axis-url
'(( "29s" . "1")("28s" . 2)("27f" . 3)("26t" . 4)("25w" . 5)("24t" . 6)("23m" . 7)("22m" . 8)))

(defun morph-time-axis ()
(markup
(:div :id "time-axis"
:style "height:100%; width:18px; position: fixed; border:1px solid; right: 0px;"
(loop for i in time-axis-url
collect (markup (:a :href (car i))
(:span " "))))))

Please Support HTML Comments

It would be nice if I could do something like this:

(:comment "For old IE compatibility")
(:comment "[if lt IE 9]>" (:script :src "foo.js") "<![endif]")`

And when using one of the HTML renderers have it rendered as:

<!-- For old IE compatibility -->
<!-- [if lt IE 9]> <script src="foo.js" /> <![endif]-->

You can probably come up with syntax that makes more sense within the context of cl-markup, but this is the general idea.

Thank you very much for creating and supporting this project.

Rendering to *output-stream* gives different result than rendering to string

Hi,

while playing around with rendering to *output-stream* versus rendering to a string, I got the following:

CL-USER> (use-package :cl-markup)
T
CL-USER> (markup (:ul (loop for item in '(1 2 3) collect (markup (:li item)))))
"<ul><li>1</li><li>2</li><li>3</li></ul>"
CL-USER> (let ((*output-stream* t))
           (markup (:ul (loop for item in '(1 2 3) collect (markup (:li item))))))
<ul><li>1</li><li>2</li><li>3</li></li></li></li></ul>
"</ul>"
CL-USER> 

Note the additional and unexpected closing tags </li> in the second output.

Is this invalid client code or a bug?

If it is a bug, perhaps the expansion under the (IF *OUTPUT-STREAM* regime should generate a PROGN that contains NIL as its last form.

In the above example, the last form of the PROGN is (WRITE-STRING "</li>" *OUTPUT-STREAM*).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.