metalsmith-mithril

0.4.0 • Public • Published

Build Status

Metalsmith - mithril

Metalsmith plugin that creates html out of mithril.js code.

Installation

npm install metalsmith-mithril --save

Usage

With source files

var Metalsmith = require('metalsmith');
var mithril = require('metalsmith-mithril');
 
Metalsmith(__dirname)
  .use(mithril({
    ext: '.m.js', // default
    concurrent: 2 // how many files will be processed in parallel, default is none
  }))

example.m.js

var m = require('mithril');
 
module.exports = {
  metadata: {
    title: 'Page title'
  },
  controller: function (file, metalsmith, callback) {
    // call callback when controller is done
    // if callback is ommitted in arguments, controller is supposed to be sync
    callback();
  },
  view: function (controller, file, metalsmith) {
    return m('h1', file.title);
  }
};

With layouts

var Metalsmith = require('metalsmith');
var mithril = require('metalsmith-mithril');
 
Metalsmith(__dirname)
  .use(mithril.layouts({
    pattern: '**/*.html', // default
    ext: '.m.js', // default
    directory: 'layouts', // default
    default: 'example.m.js', // default layout to use if none is provided
    concurrent: 2 // how many files will be processed in parallel, default is none
  }))

layouts/example.m.js

var m = require('mithril');
 
module.exports = {
  controller: function (file, metalsmith, callback) {
    // call callback when controller is done
    // if callback is ommitted in arguments, controller is supposed to be sync
    callback();
  },
  view: function (controller, file, metalsmith) {
    return [
      m('h1', file.title),
      m('main', file.contents.toString())
    ];
  }
};

example.html

---
title: Example
---
This is the content.

Results in:

<h1>Example</h1>
<main>This is the content.</main>

Development

To run the tests do:

npm test

Dependents (0)

Package Sidebar

Install

npm i metalsmith-mithril

Weekly Downloads

2

Version

0.4.0

License

MIT

Unpacked Size

11.1 kB

Total Files

13

Last publish

Collaborators

  • ondrej