Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including metalsmith-mithril with all npm packages installed. Try it out:

var metalsmithMithril = require("metalsmith-mithril")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-mithril v0.4.0

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

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
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free