Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the caramel Reference Manual, version 0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Mon Apr 19 14:19:31 2021 GMT+0.
• Introduction | What caramel is all about | |
• Systems | The systems documentation | |
• Modules | The modules documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
Enlive like css selector-based template system in Common Lisp
(ql:quickload :caramel)
build dom from html file
(html-resource #p"/path/to/your/html/file")
search node by css selector
(select "#id" dom-node)
=> Matching node list
Every translator returns a function which takes a node and return translated node or nodes.
Set attributes to node
(set-attr :foo "baz" :bar "wow")
Remove attributes from node
(remove-attr :foo :bar)
Add css classes to node
(add-class "cls-foo" "cls-bar")
Remove css classes from node
(remove-class "cls-foo" "cls-bar")
Set content of node
(content "foo" a-node "foo")
Build html from specified string and set
(html-content "<p>Foo</p>")
Wrap node with specified tag
(wrap "p")
Get content of node
(unwrap)
Cascade transform to node
(do-> (content "foo") (set-attr :color "green") (add-class "cls-foo"))
Insert nodes before node
(before "foo" a-node "baz")
Insert nodes after node
(after "foo" a-node "baz")
Replace node with nodes
(substitute "foo" a-node "baz")
Move matched node
(move src-selector dst-selector)
Clone nodes
(clone-for x '(1 2 3) (content x))
(clone-for x '(1 2 3)
"p" (content x)
"h1" (content "foo"))
Define snippet from file.
(defsnippet bar #p"/path/to/your/file" "div#baz" ()
"p" (content "foo"))
(bar)
=> node-list
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")))
Get attribute value of node
(get-attr node name)
Get attribute alist of node
(get-attrs node)
Get content of node
(get-content text-node)
=> content string
(get-content document-or-element)
=> children-list
(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")
Copyright (c) 2013 Masato Sogame (poketo7878@gmail.com)
Licensed under the LLGPL License.
Next: Modules, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The caramel system |
Masato Sogame
LLGPL
CSS selector-based template engine for Common Lisp
# 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
caramel.asd (file)
src (module)
Modules are listed depth-first from the system components tree.
• The caramel/src module |
caramel (system)
src/
caramel.lisp (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The caramel.asd file | ||
• The caramel/src/caramel.lisp file |
Next: The caramel/src/caramel․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
caramel.asd
caramel (system)
Previous: The caramel․asd file, Up: Lisp files [Contents][Index]
src (module)
src/caramel.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The caramel-asd package | ||
• The caramel package |
Next: The caramel package, Previous: Packages, Up: Packages [Contents][Index]
caramel.asd
Previous: The caramel-asd package, Up: Packages [Contents][Index]
caramel.lisp (file)
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported macros | ||
• Exported functions |
Next: Exported functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
Previous: Exported macros, Up: Exported definitions [Contents][Index]
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal macros | ||
• Internal functions | ||
• Internal generic functions |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
caramel.lisp (file)
caramel.lisp (file)
Next: Internal generic functions, Previous: Internal macros, Up: Internal definitions [Contents][Index]
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
caramel.lisp (file)
Previous: Internal functions, Up: Internal definitions [Contents][Index]
caramel.lisp (file)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | C F L M |
---|
Jump to: | C F L M |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
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 |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C P S |
---|
Jump to: | C P S |
---|