Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Page.create

Page.create($fieldMap) -> Page

Description

Create a new Page object with the given map of fields.

When you call send on the object, it will return a well-formed HTML5 document to the client.

$page = Page.create({

    appName: 'My App',

    css: url'/assets/main.css',

    header: headerHtml(),
    footer: footerHtml(),
})

$page.setMain(html'This is the main page content.')

$page.send()

Field Map 

The create method accepts a Map with any of the following fields (all optional).

Title Parts

Key Description
appName Name of the app (without “.com”, etc.)
joiner Character between title parts (default: '-')
tagline Short description of site (max 50 characters)

See setTitle to see how these parts are used.

Meta Tags

Key Description See Method
description Page description (max 200 characters) setDescription
icon Path to favicon image (32x32 png) setIcon
image Thumbnail image for social sharing (1200x1200) setImage
head HTML string inserted into the <head> tag addToHead
bodyClass 'class' attribute of the <body> tag addBodyClass

Assets

Key Description See Method
css List of CSS URLs or TypeStrings addCss
js List of JavaScript URLs or TypeStrings addJs

HTML Content

Key Description See Method
header Content of <header> tag setHeader
footer Content of <footer> tag setFooter
main Content of <main> tag setMain
body Content of the entire <body> tag setBody

Full Example 

This examples shows how you can create the page in a module function, to define all of the parts that are shared across the app. (header, footer, etc.)

Then each individual page can set the fields that are specific to that page. (title, main content, etc.)

// modules/App.tht
//---------------------------------------

fn getPage {

    $page = Page.create({

        appName: 'SuperCalc',
        tagline: 'Add and Subtract Numbers',

        css: [
            url'/assets/main.css',
        ],
        js: [
            url'http://cdnjs.net/library.min.js',
            url'/assets/calc.js',
        ],

        header: headerHtml(),
        footer: footerHtml(),
    })

    return $page
}

// pages/about.tht
//---------------------------------------

$page = App.getPage()

$page.setTitle('About Me')
     .setMain(mainHtml())
     .send()

tm mainHtml {

    <h1> About Me
    <p> I have a passion for adding numbers.
}

See Also 

See Also