The caramel Reference Manual

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.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 caramel

CSS selector-based template engine for Common Lisp

Author

Masato Sogame

License

LLGPL

Long Description

# 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.

Version

0.1

Dependencies
  • cxml (system).
  • alexandria (system).
  • iterate (system).
  • cxml-dom (system).
  • closure-html (system).
  • css-selectors (system).
  • buildnode (system).
Source

caramel.asd.

Child Component

src (module).


3 Modules

Modules are listed depth-first from the system components tree.


3.1 caramel/src

Source

caramel.asd.

Parent Component

caramel (system).

Child Component

caramel.lisp (file).


4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


4.1 Lisp


4.1.1 caramel/caramel.asd

Source

caramel.asd.

Parent Component

caramel (system).

ASDF Systems

caramel.

Packages

caramel-asd.


4.1.2 caramel/src/caramel.lisp

Source

caramel.asd.

Parent Component

src (module).

Packages

caramel.

Public Interface
Internals

5 Packages

Packages are listed by definition order.


5.1 caramel-asd

Source

caramel.asd.

Use List
  • asdf/interface.
  • common-lisp.

5.2 caramel

Source

caramel.lisp.

Use List
  • alexandria.
  • common-lisp.
  • css-selectors.
  • iterate.
  • net.acceleration.buildnode.
Public Interface
Internals

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


6.1 Public Interface


6.1.1 Macros

Macro: clone-for (var lst &rest trans)
Package

caramel.

Source

caramel.lisp.

Macro: defsnippet (name file-path selector args &rest select-trans-pair)
Package

caramel.

Source

caramel.lisp.

Macro: deftemplate (name file-path args &rest select-body-pair)
Package

caramel.

Source

caramel.lisp.


6.1.2 Ordinary functions

Function: add-class (&rest class)
Package

caramel.

Source

caramel.lisp.

Function: after (&rest nodes)
Package

caramel.

Source

caramel.lisp.

Function: append (&rest nodes)
Package

caramel.

Source

caramel.lisp.

Function: before (&rest nodes)
Package

caramel.

Source

caramel.lisp.

Function: content (&rest value)
Package

caramel.

Source

caramel.lisp.

Function: do-> (&rest fns)
Package

caramel.

Source

caramel.lisp.

Function: get-attr (node name)
Package

caramel.

Source

caramel.lisp.

Function: get-attrs (node)
Package

caramel.

Source

caramel.lisp.

Function: get-content (node)
Package

caramel.

Source

caramel.lisp.

Function: html-content (html-str)
Package

caramel.

Source

caramel.lisp.

Function: html-resource (input)
Package

caramel.

Source

caramel.lisp.

Function: move (src-selector dst-selector)
Package

caramel.

Source

caramel.lisp.

Function: prepend (&rest nodes)
Package

caramel.

Source

caramel.lisp.

Function: remove-attr (&rest atters)
Package

caramel.

Source

caramel.lisp.

Function: remove-class (&rest class)
Package

caramel.

Source

caramel.lisp.

Function: select (selector node)
Package

caramel.

Source

caramel.lisp.

Function: set-attr (&rest atters)
Package

caramel.

Source

caramel.lisp.

Function: substitute (&rest nodes)
Package

caramel.

Source

caramel.lisp.


6.2 Internals


6.2.1 Macros

Macro: apply-select-trans (node select trans)
Package

caramel.

Source

caramel.lisp.

Macro: with-clone-node (var node &body body)
Package

caramel.

Source

caramel.lisp.


6.2.2 Ordinary functions

Function: dom-to-html-string (dom)
Package

caramel.

Source

caramel.lisp.

Function: flatmap (fn node-or-nodes)
Package

caramel.

Source

caramel.lisp.

Function: group (list)
Package

caramel.

Source

caramel.lisp.

Function: treat-node-list (doc node-list)
Package

caramel.

Source

caramel.lisp.

Function: unwrap ()
Package

caramel.

Source

caramel.lisp.

Function: wrap (tag)
Package

caramel.

Source

caramel.lisp.


6.2.3 Generic functions

Generic Function: replace-node-with (old-node node-or-nodes)
Package

caramel.

Methods
Method: replace-node-with ((old-node node) node-or-nodes)
Source

caramel.lisp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   A   B   C   D   F   G   H   M   P   R   S   T   U   W  
Index Entry  Section

A
add-class: Public ordinary functions
after: Public ordinary functions
append: Public ordinary functions
apply-select-trans: Private macros

B
before: Public ordinary functions

C
clone-for: Public macros
content: Public ordinary functions

D
defsnippet: Public macros
deftemplate: Public macros
do->: Public ordinary functions
dom-to-html-string: Private ordinary functions

F
flatmap: Private ordinary functions
Function, add-class: Public ordinary functions
Function, after: Public ordinary functions
Function, append: Public ordinary functions
Function, before: Public ordinary functions
Function, content: Public ordinary functions
Function, do->: Public ordinary functions
Function, dom-to-html-string: Private ordinary functions
Function, flatmap: Private ordinary functions
Function, get-attr: Public ordinary functions
Function, get-attrs: Public ordinary functions
Function, get-content: Public ordinary functions
Function, group: Private ordinary functions
Function, html-content: Public ordinary functions
Function, html-resource: Public ordinary functions
Function, move: Public ordinary functions
Function, prepend: Public ordinary functions
Function, remove-attr: Public ordinary functions
Function, remove-class: Public ordinary functions
Function, select: Public ordinary functions
Function, set-attr: Public ordinary functions
Function, substitute: Public ordinary functions
Function, treat-node-list: Private ordinary functions
Function, unwrap: Private ordinary functions
Function, wrap: Private ordinary functions

G
Generic Function, replace-node-with: Private generic functions
get-attr: Public ordinary functions
get-attrs: Public ordinary functions
get-content: Public ordinary functions
group: Private ordinary functions

H
html-content: Public ordinary functions
html-resource: Public ordinary functions

M
Macro, apply-select-trans: Private macros
Macro, clone-for: Public macros
Macro, defsnippet: Public macros
Macro, deftemplate: Public macros
Macro, with-clone-node: Private macros
Method, replace-node-with: Private generic functions
move: Public ordinary functions

P
prepend: Public ordinary functions

R
remove-attr: Public ordinary functions
remove-class: Public ordinary functions
replace-node-with: Private generic functions
replace-node-with: Private generic functions

S
select: Public ordinary functions
set-attr: Public ordinary functions
substitute: Public ordinary functions

T
treat-node-list: Private ordinary functions

U
unwrap: Private ordinary functions

W
with-clone-node: Private macros
wrap: Private ordinary functions


A.3 Variables