Skip to content

hung-phan/grunt-msx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-msx Build Status

Precompile Mithril views which use JSX into JavaScript by insin

NPM

Getting Started

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-msx --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-msx');

The "msx" task

Overview

In your project's Gruntfile, add a section named msx to the data object passed into grunt.initConfig().

grunt.initConfig({
  msx: {
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

Working on

Usage Examples

Default Options

In this example, the app option are used to convert all files matched test/fixtures/*.jsx to Mithril views.

grunt.initConfig({
  msx: {
    app: {
      files: [{
        expand: true,
        cwd: 'test/fixtures',
        src  : '**/*.jsx',
        dest : 'test/expected',
      }]
    }
  },
})

With Browserify

browserify: {
  app: {
    files: { '<%= yeoman.app %>/scripts/main.js': ['<%= yeoman.app %>/jsx/main.jsx'] },
    options: {
      transform: [require('grunt-msx').browserify]
    }
  }
},

Example

todo.view = function(ctrl) {
  return <html>
    <body>
      <input onchange={m.withAttr("value", ctrl.description)} value={ctrl.description()}/>
      <button onclick={ctrl.add.bind(ctrl, ctrl.description)}>Add</button>
      <table>
        {ctrl.list.map(function(task, index) {
          return <tr>
            <td>
              <input
                type="checkbox"
                onclick={m.withAttr("checked", task.done)}
                checked={task.done()}
               />
            </td>
            <td style={{textDecoration: task.done() ? "line-through" : "none"}}>
              {task.description()}
            </td>
          </tr>
        })}
      </table>
    </body>
  </html>
};

To

todo.view = function(ctrl) {
  return m("html", [
    m("body", [
      m("input", {onchange:m.withAttr("value", ctrl.description), value:ctrl.description()}),
      m("button", {onclick:ctrl.add.bind(ctrl, ctrl.description)}, ["Add"]),
      m("table", [
        ctrl.list.map(function(task, index) {
          return m("tr", [
            m("td", [
              m("input",
                {type:"checkbox",
                onclick:m.withAttr("checked", task.done),
                checked:task.done()}
               )
            ]),
            m("td", {style:{textDecoration: task.done() ? "line-through" : "none"}}, [
              task.description()
            ])
          ])
        })
      ])
    ])
  ])
};

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014 Hung Quang Phan. Licensed under the MIT license.

About

Precompile Mithril views which use JSX into JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published