https://github.com/tonyaldon/jack
jack is a HTML generator library for Emacs Lisp.
https://github.com/tonyaldon/jack
emacs-lisp html html-generation html-generator
Last synced: 8 days ago
JSON representation
jack is a HTML generator library for Emacs Lisp.
- Host: GitHub
- URL: https://github.com/tonyaldon/jack
- Owner: tonyaldon
- License: gpl-3.0
- Created: 2022-11-05T15:06:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T06:12:51.000Z (over 2 years ago)
- Last Synced: 2024-04-17T09:12:44.432Z (over 2 years ago)
- Topics: emacs-lisp, html, html-generation, html-generator
- Language: Emacs Lisp
- Homepage: https://jack.tonyaldon.com
- Size: 206 KB
- Stars: 28
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
~jack~ is a HTML generator library for Emacs Lisp.
To install it put ~jack.el~ file in your load path and require ~jack~
like this:
#+BEGIN_SRC emacs-lisp
(require 'jack)
#+END_SRC
~jack~ provides the function ~jack-html~ that takes a data structure
as input representing the HTML tree you want to generate and generates it
as a string.
For instance:
#+BEGIN_SRC emacs-lisp
(jack-html '(:section (:div (:p "foo"))))
;; "
foo
"
#+END_SRC
HTML attributes are specified in a list starting by the ~@~ sign
#+BEGIN_SRC emacs-lisp
(jack-html '(:div (@ :id "id" :class "class" :style "color:red;") "foo"))
;; "
foo"
#+END_SRC
In the keyword defining the HTML tag you can use ~/~ to declare its
~id~ and ~.~ to declare its classes like this:
#+BEGIN_SRC emacs-lisp
(jack-html '(:div/id.class-1.class-2
(@ :class "class-3" :style "color:red;")
"foo"))
;; "
foo"
#+END_SRC
Note that I would have prefered to use ~#~ for declaring the ~id~ but it
has to be escaped in keywords which is ugly.
Tag content can be lists of components:
#+BEGIN_SRC emacs-lisp
(jack-html '(:ul ((:li "1") (:li "2"))))
;; "
- 1
- 2
(jack-html '(:ul (@ :id "id") ((:li "1") (:li "2"))))
;; "
- 1
- 2
#+END_SRC
Components can be generated by a forms:
#+BEGIN_SRC emacs-lisp
(jack-html `(:p ,(concat "foo-" "bar")))
;; "
foo-bar
"(jack-html (mapcar (lambda (n) `(:p ,n)) '(1 2 3)))
;; "
1
2
3
"#+END_SRC
Tag content can be forms:
#+BEGIN_SRC emacs-lisp
(jack-html `(:ul ,(mapcar (lambda (n) `(:li ,n)) '(1 2))))
;; "
- 1
- 2
(jack-html `(:ul (@ :id "id")
,(mapcar (lambda (n) `(:li ,n)) '(1 2))))
;; "
- 1
- 2
#+END_SRC
Tag content and attributes can be variables:
#+BEGIN_SRC emacs-lisp
(let ((x "foo") (y "bar"))
(jack-html `(:p (@ :id ,x) ,y)))
;; "
bar
"(jack-html
(let ((x "foo") (y "bar"))
`(:p (@ :id ,x) ,y)))
;; "
bar
"#+END_SRC
If the variable ~jack-html-raise-error-p~ is set to ~nil~, which is the
default value, ~jack-html~ processes non component object as the empty
string.
Let's consider the case of the vector like ~[a b c]~ that is not a
component for ~jack-html~.
We have
#+BEGIN_SRC emacs-lisp
(let ((jack-html-raise-error-p nil))
(jack-html "foo" [a b c] "bar"))
;; "foobar"
#+END_SRC
and,
#+BEGIN_SRC emacs-lisp
(let ((jack-html-raise-error-p t))
(jack-html "foo" [a b c] "bar"))
#+END_SRC
which raises the error:
#+BEGIN_SRC text
Object '[a b c]' of type 'vector' can't be a component in 'jack-html'
#+END_SRC