├── .gitignore ├── .jshintrc ├── .travis.yml ├── LICENSE ├── README.md ├── docs └── jsnox-specstring.png ├── jsnox.js ├── package.json └── tests ├── test_autokey.js ├── test_parsing.js └── test_trees.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.DS_Store 3 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | // JSHint config 3 | // See http://www.jshint.com/options/ for full config documentation 4 | 5 | "browser" : true, // Standard browser globals e.g. `window`, `document`. 6 | "node" : true, // For testing if "module" exists 7 | "debug" : false, // Allow debugger statements 8 | "devel" : false, // Allow development statements (eg. console.log) 9 | 10 | // EcmaScript 5. 11 | "strict" : false, // Require `use strict` pragma in every file. 12 | "globalstrict" : false, // Allow global "use strict" (enables "strict"). 13 | 14 | // Enforcing Options 15 | // These options tell JSHint to be more strict towards your code. 16 | "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.). 17 | "curly" : false, // Requires {} for every new block or scope. 18 | "eqeqeq" : true, // Requires triple equals i.e. `===`. 19 | "forin" : false, // Requires `for in` loops to be filtered with 20 | // `hasOwnPrototype`. 21 | "immed" : true, // Requires IIFEs to be wrapped in parens 22 | // eg. `( function(){}() );` 23 | "latedef" : false, // Prohibits variable use before definition. 24 | "newcap" : false, // Requires capitalization of all constructors 25 | "noarg" : true, // Prohibits use of `arguments.caller` and `callee`. 26 | "noempty" : true, // Prohibits use of empty blocks. 27 | "nonew" : false, // Prohibits use of constructors for side-effects. 28 | "plusplus" : false, // Prohibits use of `++` & `--`. 29 | "regexp" : true, // Prohibits `.` and `[^...]` in regular expressions. 30 | "trailing" : true, // Prohibits trailing whitespaces. 31 | "undef" : true, // Requires all non-globals be declared before use. 32 | "unused" : "vars", // Warns when you define unused vars (but not fn args) 33 | 34 | // Relaxing Options 35 | // These options allow you to suppress certain types of warnings. 36 | "asi" : true, // Allows statements without semicolons 37 | "boss" : false, // Tolerates assignments inside if, for & while. 38 | "eqnull" : true, // Tolerates use of `== null`. 39 | "evil" : false, // Tolerates use of `eval`. 40 | "expr" : true, // Tolerates `ExpressionStatement` as Programs. 41 | "laxbreak" : false, // Tolerates unsafe line breaks 42 | // eg. `return [\n] x` without semicolons. 43 | "loopfunc" : false, // Allows functions to be defined within loops. 44 | "regexdash" : false, // Tolerates unescaped last dash i.e. `[-...]`. 45 | "scripturl" : true, // Tolerates script-targeted URLs. 46 | "shadow" : false, // Allows re-defined variables later in code 47 | // eg. `var x=1; x=2;`. 48 | "sub" : true, // Tolerates use of subscript notation 49 | // (eg. obj['key'] instead of obj.key). 50 | "supernew" : true, // Tolerate `new function()` and `new Object;`. 51 | "lastsemic" : true // Tolerate missing ; for final statements in blocks 52 | } 53 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.0" 4 | - "0.12" 5 | - "0.10" 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014 Aaron Franks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](http://travis-ci.org/af/JSnoX) 2 | 3 | # JSnoX 4 | 5 | Enjoy [React.js](http://facebook.github.io/react/), but not a fan of the JSX? 6 | JSnoX gives you a concise, expressive way to build ReactElement trees in pure JavaScript. 7 | 8 | 9 | ## Works with 10 | * React.js v0.12 and above 11 | * React Native 12 | 13 | 14 | ## Example 15 | 16 | ```js 17 | var React = require('react') 18 | var MyOtherComponent = require('./some/path.js') 19 | var d = require('jsnox')(React) 20 | 21 | var LoginForm = React.createClass({ 22 | submitLogin: function() { ... }, 23 | 24 | render: function() { 25 | return d('form[method=POST]', { onSubmit: this.submitLogin }, 26 | d('h1.form-header', 'Login'), 27 | d('input:email[name=email]'), 28 | d('input:password[name=pass]'), 29 | d(MyOtherComponent, { myProp: 'foo' }), 30 | d('button:submit', 'Login') 31 | ) 32 | } 33 | }) 34 | ``` 35 | 36 | 37 | ## API 38 | 39 | ```js 40 | // Create a function, d, that parses spec strings into React DOM: 41 | var React = require('react') 42 | var ReactDOM = require('react-dom') 43 | var d = require('jsnox')(React) 44 | 45 | // The function returned by JSnoX takes 3 arguments: 46 | // specString (required) - Specifies the tagName and (optionally) attributes 47 | // props (optional) - Additional props (can override output from specString) 48 | // children (optional) - String, or an array of ReactElements 49 | var myDom = d('div.foo', {}, 'hello') 50 | 51 | ReactDOM.render(myDom, myElement) // renders