Page - Create Documents

This module contains functions for rendering HTML documents.

Basic Example

(import [hyccup.page [html5 include-css include-js]])

(html5 ['p "hello world"])
;; "<!DOCTYPE html>\n<html><p>hello world</p></html>"

(html5
  ['head
    #* (include-css "/my.css")
    #* (include-js "/my.js")]
  ['body "hello world"])
;; "<!DOCTYPE html>
;; <html>
;; <head>
;;   <link href=\"/my.css\" rel=\"stylesheet\" type=\"text/css\">
;;   <script src=\"/my.js\" type=\"text/javascript\"></script>
;; </head>
;; <body>hello world</body>
;; </html>"
from hyccup.page import html5, include_js, include_css

html5(['p', 'hello world'])
# '<!DOCTYPE html>\n<html><p>hello world</p></html>'

html5(['head',
       *include-css('/my.css'),
       *include-js('/my.js')],
      ['body', 'hello world'])
# '<!DOCTYPE html>
# <html>
# <head>
#   <link href="/my.css" rel="stylesheet" type="text/css">
#   <script src="/my.js" type="text/javascript"></script>
# </head>
# <body>hello world</body>
# </html>'

API

Source code: hyccup/page.hy

(hyccup.page.xhtml #* contents * lang  [encoding UTF-8])

Create a XHTML 1.0 strict document with the supplied contents.

Parameters
  • lang – The language of the document

  • encoding – The character encoding of the document (defaults to UTF-8).

(hyccup.page.html4 #* contents)

Create a HTML 4 document with the supplied contents.

The first argument may be an optional attribute map.

(hyccup.page.html5 #* contents * lang  [xml False]  [encoding UTF-8])

Create a HTML5 document with the supplied contents.

Parameters
  • xml – If True, use html with xml mode.

  • encoding – The character encoding of the document (defaults to UTF-8).

  • lang – The language of the document.

(hyccup.page.include-css #* styles)

Include a list of external stylesheet files.

(hyccup.page.include-js #* scripts)

Include a list of external javascript files.