This is the caramel Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 08 16:33:42 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
caramel
CSS selector-based template engine for Common Lisp
Masato Sogame
LLGPL
# Caramel
Enlive like css selector-based template system in Common Lisp
## Installation
(ql:quickload :caramel)
## Usage
### html-resource
build dom from html file
(html-resource #p"/path/to/your/html/file")
### select
search node by css selector
(select "#id" dom-node)
=> Matching node list
### Translator
Every translator returns a function
which takes a node and return translated node or nodes.
#### set-attr
Set attributes to node
(set-attr :foo "baz" :bar "wow")
#### remove-attr
Remove attributes from node
(remove-attr :foo :bar)
#### add-class
Add css classes to node
(add-class "cls-foo" "cls-bar")
#### remove-class
Remove css classes from node
(remove-class "cls-foo" "cls-bar")
#### content
Set content of node
(content "foo" a-node "foo")
#### html-content
Build html from specified string and set
(html-content "<p>Foo</p>")
#### wrap
Wrap node with specified tag
(wrap "p")
#### unwrap
Get content of node
(unwrap)
#### do->
Cascade transform to node
(do-> (content "foo") (set-attr :color "green") (add-class "cls-foo"))
#### before
Insert nodes before node
(before "foo" a-node "baz")
#### after
Insert nodes after node
(after "foo" a-node "baz")
#### substitute
Replace node with nodes
(substitute "foo" a-node "baz")
#### move
Move matched node
(move src-selector dst-selector)
#### clone-for
Clone nodes
(clone-for x ’(1 2 3) (content x))
(clone-for x ’(1 2 3)
"p" (content x)
"h1" (content "foo"))
## Snippet & Template
### defsnippet
Define snippet from file.
(defsnippet bar #p"/path/to/your/file" "div#baz" ()
"p" (content "foo"))
(bar)
=> node-list
### deftemplate
Define template from file.
(deftemplate foo #p"/path/to/your/base/file" (&optional foo)
"#bar" (do->
(content "fuge")
(set-attr :color "green")
(add-class "cls-foo"))
"p#para" (if foo
(content foo)
(content "defaul")))
## Scraping
### get-attr
Get attribute value of node
(get-attr node name)
### get-attrs
Get attribute alist of node
(get-attrs node)
### get-content
Get content of node
(get-content text-node)
=> content string
(get-content document-or-element)
=> children-list
#### example
(defun -> (&rest fns)
(lambda (init)
(loop with citem = init
for fn in fns
do
(setf citem (funcall fn citem))
finally (return citem))))
(defun google-search (word)
(let* ((query (list (cons "q" word)))
(str (drakma:http-request "http://www.google.com/search"
:parameters query))
(dom (html-resource str)))
(loop
for node in (select "h3.r" dom)
collect (get-attr (funcall (-> (unwrap) #’first) node) "href"))))
(google-search "foo")
=>
("/url?q=http://en.wikipedia.org/wiki/Foobar&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CBgQFjAA&usg=AFQjCNENNqcYY0yw8Y9RKmzildDpcRlcSg"
"/url?q=http://www.foo.com/&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CCEQFjAB&usg=AFQjCNEi6s8gBpsT6sK5Em5Rq-zpL6v01w"
"/url?q=http://www.urbandictionary.com/define.php%3Fterm%3Dfoo&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CCUQFjAC&usg=AFQjCNFC3xe17h6LLn86ZXUtY4CXfCcOwQ"
"/url?q=http://catb.org/jargon/html/F/foo.html&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CCkQFjAD&usg=AFQjCNFmr2ssHlV9Sjrrq833Rz8TjsDSFQ"
"/url?q=http://foofood.ca/&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CCwQFjAE&usg=AFQjCNFVHsem3EcurfHqsByEIR70wJ0vNA"
"/url?q=http://www.foofighters.com/&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CC8QFjAF&usg=AFQjCNFgY5a73m8zvOltlo1SeHm3h0asUw"
"/url?q=http://www.forgetfoo.com/&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CDMQFjAG&usg=AFQjCNFHZEG0pjLC-fwDNKPOv6MZu4Y4qQ"
"/url?q=http://www.foo-apartment.com/&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CDgQFjAH&usg=AFQjCNHkIFr_2j-KtvcHPxWd-XMhLudjcQ"
"/url?q=http://www.facebook.com/foofighters&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CDwQFjAI&usg=AFQjCNE-mJsSRMzQUdMOXjPToJljjmVeFg"
"/url?q=http://www.ietf.org/rfc/rfc3092.txt&sa=U&ei=Oas2UZrOFoyIkwXot4C4Cw&ved=0CEAQFjAJ&usg=AFQjCNFYfQd6aQqdZy9M5W4lzgTkosaniA")
## Author
* Masato Sogame (poketo7878@gmail.com)
## Copyright
Copyright (c) 2013 Masato Sogame (poketo7878@gmail.com)
# License
Licensed under the LLGPL License.
0.1
cxml
(system).
alexandria
(system).
iterate
(system).
cxml-dom
(system).
closure-html
(system).
css-selectors
(system).
buildnode
(system).
src
(module).
Modules are listed depth-first from the system components tree.
Files are sorted by type and then listed depth-first from the systems components trees.
caramel/src/caramel.lisp
src
(module).
add-class
(function).
after
(function).
append
(function).
before
(function).
clone-for
(macro).
content
(function).
defsnippet
(macro).
deftemplate
(macro).
do->
(function).
get-attr
(function).
get-attrs
(function).
get-content
(function).
html-content
(function).
html-resource
(function).
move
(function).
prepend
(function).
remove-attr
(function).
remove-class
(function).
select
(function).
set-attr
(function).
substitute
(function).
apply-select-trans
(macro).
dom-to-html-string
(function).
flatmap
(function).
group
(function).
replace-node-with
(method).
treat-node-list
(function).
unwrap
(function).
with-clone-node
(macro).
wrap
(function).
Packages are listed by definition order.
caramel
alexandria
.
common-lisp
.
css-selectors
.
iterate
.
net.acceleration.buildnode
.
add-class
(function).
after
(function).
append
(function).
before
(function).
clone-for
(macro).
content
(function).
defsnippet
(macro).
deftemplate
(macro).
do->
(function).
get-attr
(function).
get-attrs
(function).
get-content
(function).
html-content
(function).
html-resource
(function).
move
(function).
prepend
(function).
remove-attr
(function).
remove-class
(function).
select
(function).
set-attr
(function).
substitute
(function).
apply-select-trans
(macro).
dom-to-html-string
(function).
flatmap
(function).
group
(function).
replace-node-with
(generic function).
treat-node-list
(function).
unwrap
(function).
with-clone-node
(macro).
wrap
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Jump to: | A B C D F G H M P R S T U W |
---|
Jump to: | A B C D F G H M P R S T U W |
---|
Jump to: | C F M P S |
---|
Jump to: | C F M P S |
---|