0.4.0 • Published 4 years ago

metalsmith-mithril v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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
0.4.0

4 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.0

7 years ago

0.1.0

8 years ago

0.0.1

8 years ago