reubano / metalsmith-mithril

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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('mitrhil');

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('mitrhil');

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

About

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


Languages

Language:JavaScript 98.1%Language:HTML 1.9%