dbashford / mimosa-server-template-compile

A mimosa module for compiling server templates as part of a build
3 stars 1 forks source link

mimosa-server-template-compile

Overview

This Mimosa module will find and compile server templates as part of a Mimosa build.

For more information regarding Mimosa, see http://mimosa.io

Usage

Add 'server-template-compile' to your list of modules. That's all! Mimosa will install the module for you when you start up.

Functionality

This module will, as part of a mimosa build, compile your dynamic templates into .html files. Use this module if you want to take advantage of Mimosa's serving of dynamic templates, but do not intend to deploy node to your target environment and therefore cannot dynamically compile templates at runtime. This also enables building of static websites using dynamic assets.

The server template languages supported by Mimosa are supported by this module. Those include:

This module replaces the old --jade flag that was a part of mimosa build pre version 0.7.0.

This module will also clean up after itself, removing any templates it has compiled when you run a clean command.

Default Config

The default config for this module is almost entirely derived from other settings and properties in a project. Some are from other Mimosa module settings, some from flags used during mimosa build, others from the project's package.json. Those settings are indicated below after an arrow =>.

The full default config:

serverTemplate:
  compileWith: => server.views.compileWith or 'jade'
  extension: => server.views.extension or 'jade'
  inPath: => server.views.path or 'views'
  outPath: => server.watch.compiledDir
  exclude: ["layout.jade"]
  locals:
    title:     "Mimosa"
    reload:    false
    optimize:  => whether or not the --optimize flag is used
    cachebust: => project's package.json.version or ""

The derived settings above are assumed, making the actual mimosa-config defaults the following:

serverTemplate:
  exclude: ["layout.jade"]
  locals:
    title: "Mimosa"
    reload: false

If you are using jade, and using mimosa-server, and have templates that do not vary far from those delivered by mimosa new, then all you may need to do is change the locals.title property. For example:

serverTemplate:
  locals:
    title: "MyAppName"

Alternate Config

Your templates may not all take the same parameters. The config is flexible enough to allow you to pass in different parameters per template.

serverTemplate:
  compileWith: => server.views.compileWith or 'jade'
  extension: => server.views.extension or 'jade'
  inPath: => server.views.path or 'views'
  outPath: => server.watch.compiledDir
  exclude: ["layout.jade"]
  locals:
    title:     "Mimosa"
    reload:    false
    optimize:  => whether or not the --optimize flag is used
    cachebust: => project's package.json.version
  views: [{
    path: "foo.jade" <= no default
    locals:
      title:     "Mimosa"
      reload:    false
      optimize:  => whether or not the --optimize flag is used
      cachebust: => project's package.json.version or ""
  }]

Additional fields in this config: