The caramel Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The caramel Reference Manual

This is the caramel Reference Manual, version 0.1, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:00:57 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

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

Copyright

Copyright (c) 2013 Masato Sogame (poketo7878@gmail.com)

License

    Licensed under the LLGPL License.

Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

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


Previous: , Up: Systems   [Contents][Index]

2.1 caramel

Author

Masato Sogame

License

LLGPL

Description

CSS selector-based template engine for Common Lisp

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
Source

caramel.asd (file)

Component

src (module)


Next: , Previous: , Up: Top   [Contents][Index]

3 Modules

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


Previous: , Up: Modules   [Contents][Index]

3.1 caramel/src

Parent

caramel (system)

Location

src/

Component

caramel.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

4 Files

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


Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.1 caramel.asd

Location

caramel.asd

Systems

caramel (system)

Packages

caramel-asd


Previous: , Up: Lisp files   [Contents][Index]

4.1.2 caramel/src/caramel.lisp

Parent

src (module)

Location

src/caramel.lisp

Packages

caramel

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

5.1 caramel-asd

Source

caramel.asd

Use List

Previous: , Up: Packages   [Contents][Index]

5.2 caramel

Source

caramel.lisp (file)

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

6 Definitions

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


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.1 Macros

Macro: clone-for VAR LST &rest TRANS
Package

caramel

Source

caramel.lisp (file)

Macro: defsnippet NAME FILE-PATH SELECTOR ARGS &rest SELECT-TRANS-PAIR
Package

caramel

Source

caramel.lisp (file)

Macro: deftemplate NAME FILE-PATH ARGS &rest SELECT-BODY-PAIR
Package

caramel

Source

caramel.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

6.1.2 Functions

Function: add-class &rest CLASS
Package

caramel

Source

caramel.lisp (file)

Function: after &rest NODES
Package

caramel

Source

caramel.lisp (file)

Function: append &rest NODES
Package

caramel

Source

caramel.lisp (file)

Function: before &rest NODES
Package

caramel

Source

caramel.lisp (file)

Function: content &rest VALUE
Package

caramel

Source

caramel.lisp (file)

Function: do-> &rest FNS
Package

caramel

Source

caramel.lisp (file)

Function: get-attr NODE NAME
Package

caramel

Source

caramel.lisp (file)

Function: get-attrs NODE
Package

caramel

Source

caramel.lisp (file)

Function: get-content NODE
Package

caramel

Source

caramel.lisp (file)

Function: html-content HTML-STR
Package

caramel

Source

caramel.lisp (file)

Function: html-resource INPUT
Package

caramel

Source

caramel.lisp (file)

Function: move SRC-SELECTOR DST-SELECTOR
Package

caramel

Source

caramel.lisp (file)

Function: prepend &rest NODES
Package

caramel

Source

caramel.lisp (file)

Function: remove-attr &rest ATTERS
Package

caramel

Source

caramel.lisp (file)

Function: remove-class &rest CLASS
Package

caramel

Source

caramel.lisp (file)

Function: select SELECTOR NODE
Package

caramel

Source

caramel.lisp (file)

Function: set-attr &rest ATTERS
Package

caramel

Source

caramel.lisp (file)

Function: substitute &rest NODES
Package

caramel

Source

caramel.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

6.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.1 Macros

Macro: apply-select-trans NODE SELECT TRANS
Package

caramel

Source

caramel.lisp (file)

Macro: with-clone-node VAR NODE &body BODY
Package

caramel

Source

caramel.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.2 Functions

Function: dom-to-html-string DOM
Package

caramel

Source

caramel.lisp (file)

Function: flatmap FN NODE-OR-NODES
Package

caramel

Source

caramel.lisp (file)

Function: group LIST
Package

caramel

Source

caramel.lisp (file)

Function: treat-node-list DOC NODE-LIST
Package

caramel

Source

caramel.lisp (file)

Function: unwrap ()
Package

caramel

Source

caramel.lisp (file)

Function: wrap TAG
Package

caramel

Source

caramel.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

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 (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L   M  
Index Entry  Section

C
caramel.asd: The caramel<dot>asd file
caramel/src: The caramel/src module
caramel/src/caramel.lisp: The caramel/src/caramel<dot>lisp file

F
File, Lisp, caramel.asd: The caramel<dot>asd file
File, Lisp, caramel/src/caramel.lisp: The caramel/src/caramel<dot>lisp file

L
Lisp File, caramel.asd: The caramel<dot>asd file
Lisp File, caramel/src/caramel.lisp: The caramel/src/caramel<dot>lisp file

M
Module, caramel/src: The caramel/src module

Jump to:   C   F   L   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

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: Exported functions
after: Exported functions
append: Exported functions
apply-select-trans: Internal macros

B
before: Exported functions

C
clone-for: Exported macros
content: Exported functions

D
defsnippet: Exported macros
deftemplate: Exported macros
do->: Exported functions
dom-to-html-string: Internal functions

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

G
Generic Function, replace-node-with: Internal generic functions
get-attr: Exported functions
get-attrs: Exported functions
get-content: Exported functions
group: Internal functions

H
html-content: Exported functions
html-resource: Exported functions

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

P
prepend: Exported functions

R
remove-attr: Exported functions
remove-class: Exported functions
replace-node-with: Internal generic functions
replace-node-with: Internal generic functions

S
select: Exported functions
set-attr: Exported functions
substitute: Exported functions

T
treat-node-list: Internal functions

U
unwrap: Internal functions

W
with-clone-node: Internal macros
wrap: Internal functions

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

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   P   S  
Index Entry  Section

C
caramel: The caramel system
caramel: The caramel package
caramel-asd: The caramel-asd package

P
Package, caramel: The caramel package
Package, caramel-asd: The caramel-asd package

S
System, caramel: The caramel system

Jump to:   C   P   S