1 | # react-jade
|
2 |
|
3 | Compile Jade to React JavaScript
|
4 |
|
5 | [![Build Status](https://travis-ci.org/ForbesLindesay/react-jade.png?branch=master)](https://travis-ci.org/ForbesLindesay/react-jade)
|
6 | [![Dependency Status](https://gemnasium.com/ForbesLindesay/react-jade.png)](https://gemnasium.com/ForbesLindesay/react-jade)
|
7 | [![NPM version](https://badge.fury.io/js/react-jade.png)](http://badge.fury.io/js/react-jade)
|
8 |
|
9 | ## Installation
|
10 |
|
11 | npm install react-jade
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ### With Browserify
|
16 |
|
17 | If you are using browserify, just write a file that looks like the following, then use `react-jade` as a transform. It will then inline the result of calling `jade.compileFile` automatically.
|
18 |
|
19 | ```js
|
20 | var React = require('react');
|
21 | var jade = require('jade-react');
|
22 |
|
23 | var template = jade.compileFile(__dirname + '/template.jade');
|
24 |
|
25 | React.renderComponent(template({local: 'values'}), document.getElementById('container'));
|
26 | ```
|
27 |
|
28 | ```
|
29 | browserify index.js --transform react-jade > bundle.js
|
30 | ```
|
31 |
|
32 | ### Without Browserify
|
33 |
|
34 | If you are not using browserify, you could manually compile the jade to some client file. e.g.
|
35 |
|
36 | ```js
|
37 | var fs = require('fs');
|
38 | var jade = require('react-jade');
|
39 |
|
40 | fs.writeFileSync(__dirname + '/template.js', 'var template = ' + jade.compileFileClient(__dirname + '/template.jade'));
|
41 | ```
|
42 |
|
43 | Then on your html page:
|
44 |
|
45 | ```html
|
46 | <div id="container"></div>
|
47 | <script src="http://fb.me/react-0.10.0.js"></script>
|
48 | <script src="template.js"></script>
|
49 | <script>
|
50 | React.renderComponent(template({local: 'values'}), document.getElementById('container'));
|
51 | </script>
|
52 | ```
|
53 |
|
54 | ## API
|
55 |
|
56 | ```js
|
57 | var jade = require('react-jade');
|
58 | ```
|
59 |
|
60 | ### jade(options) / jade(file)
|
61 |
|
62 | Acts as a browseify transform to inline calls to `jade.compileFile`. The source code looks something like:
|
63 |
|
64 | ```js
|
65 | function browserify(options) {
|
66 | function transform(file) {
|
67 | return new TransformStream(); //stream to do the transform implemented here
|
68 | }
|
69 | if (typeof options === 'string') {
|
70 | var file = options;
|
71 | options = arguments[2] || {};
|
72 | return transform(file);
|
73 | } else {
|
74 | return transform;
|
75 | }
|
76 | }
|
77 | ```
|
78 |
|
79 | ### jade.compileFile(filename, options) => fn
|
80 |
|
81 | Compile a jade file into a function that takes locals and returns a React DOM node.
|
82 |
|
83 | ### jade.compileFileClient(filename, options)
|
84 |
|
85 | Compile a jade file into the source code for a function that takes locals and returns a React DOM node. The result requires either a global 'React' variable, or the ability to require 'React' as a CommonJS module.
|
86 |
|
87 | ## Unsupported Features
|
88 |
|
89 | Although a lot of jade just works, there are still some features that have yet to be implemented. Here is a list of known missing features, in order of priority for adding them. Pull requests welcome:
|
90 |
|
91 | - mixins
|
92 | - attribute extension/merging (via `&attributes`)
|
93 | - case/when
|
94 | - using each to iterate over keys of an object (rather than over items in an array)
|
95 | - interpolation
|
96 | - attribute interpollation
|
97 | - special handling of data-attributes
|
98 | - outputting unescaped html results in an extra wrapper div and doesn't work for attributes
|
99 |
|
100 | ## License
|
101 |
|
102 | MIT |
\ | No newline at end of file |