Skip to content

Commit

Permalink
Merge pull request #37 from riot/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
cognitom committed Nov 25, 2016
2 parents 33ec6df + c96a53e commit 0738fd3
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 129 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"mocha": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"eqeqeq": ["error", "smart"],
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"no-cond-assign": "off",
"no-console": "off",
"no-unexpected-multiline": "error",
"quotes": ["error", "single", "avoid-escape"],
"semi": ["error", "never"]
}
}
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,5 @@
---
language: node_js language: node_js
node_js: node_js:
- '0.10' - '4.*'
script:
- npm install
- npm test
notifications: notifications:
email: false email: false
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG # CHANGELOG


## 2.0.0

* Compatible with Riot 3.0.0
* Moved to Riot organization
* Make riot-compiler a peerDependency
* Add eslint

## 1.0.1 ## 1.0.1


* Passing the file name to the riot compiler #30 * Passing the file name to the riot compiler #30
Expand Down
68 changes: 40 additions & 28 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,15 @@
[![Build [![Build
Status](https://travis-ci.org/jhthorsen/riotify.svg)](https://travis-ci.org/jhthorsen/riotify) Status](https://travis-ci.org/riot/riotify.svg)](https://travis-ci.org/riot/riotify)


# riotify # riotify


"riotify" is a browserify transformer for [riot](https://muut.com/riotjs) ".tag" files. "riotify" is a browserify transformer for [riot](https://muut.com/riotjs) ".tag" files.


## Installation ## Installation


npm install riotify ```bash
$ npm install riotify
```


## Usage ## Usage


Expand All @@ -17,34 +19,42 @@ This module is meant to be used together with


Either of the two commands below result creates the same result: Either of the two commands below result creates the same result:


browserify -t riotify app.js ```bash
module-deps -t riotify app.js | browser-pack $ browserify -t riotify app.js
$ module-deps -t riotify app.js | browser-pack
```


Example `app.js`: Example `app.js`:


var riot = require('riot') ```javascript
var todo = require('./todo.tag') var riot = require('riot')
riot.mount(todo) var todo = require('./todo.tag')
riot.mount(todo)
```


Example `todo.tag`: Example `todo.tag`:


<todo> ```html
<div each={ items }> <todo>
<h3>{ title }</h3> <div each={ items }>
</div> <h3>{ title }</h3>
</div>
// a tag file can contain any JavaScript, even require()
var resources = require('../resources.json') // a tag file can contain any JavaScript, even require()
this.items = [ { title: resources.en.first }, { title: resources.en.second } ] var resources = require('../resources.json')
</todo> this.items = [ { title: resources.en.first }, { title: resources.en.second } ]
</todo>
```


Note that your tag files actually need to have the extension ".tag". Note that your tag files actually need to have the extension ".tag".


### Compile Options ### Compile Options


This plugin can give riot's compile options. This plugin can give riot's compile options.


% browserify -t [ riotify --type coffeescript --template jade ] app.js ```bash
$ browserify -t [ riotify --type coffeescript --template jade ] app.js
```


You can also configure it in package.json You can also configure it in package.json


Expand All @@ -61,16 +71,16 @@ You can also configure it in package.json


#### Available option #### Available option


* compact: `Boolean` - compact: `Boolean`
* Minify `</p> <p>` to `</p><p>` - Minify `</p> <p>` to `</p><p>`
* expr: `Boolean` - expr: `Boolean`
* Run expressions trough parser defined with `--type` - Run expressions trough parser defined with `--type`
* type: `String, coffeescript | cs | es6 | none` - type: `String, coffeescript | cs | es6 | none`
* JavaScript pre-processor - JavaScript pre-processor
* template: `String, jade` - template: `String, jade`
* HTML pre-processor - HTML pre-processor
* ext: `String` - ext: `String`
* custom extension, you’re free to use any file extension for your tags (instead of default .tag): - custom extension, you’re free to use any file extension for your tags (instead of default .tag):


See more: https://muut.com/riotjs/compiler.html See more: https://muut.com/riotjs/compiler.html


Expand All @@ -95,7 +105,9 @@ These are the simplest cases. `uglify` and `sourcemaps` would be needed.


## Tests ## Tests


npm test ```bash
$ npm test
```


## Author ## Author


Expand Down
29 changes: 16 additions & 13 deletions index.js
Original file line number Original file line Diff line number Diff line change
@@ -1,23 +1,26 @@
var through = require('through'); 'use strict'
var riot = require('riot');
var preamble = "var riot = require('riot');\n"; const through = require('through')
const compiler = require('riot-compiler')
const preamble = "var riot = require('riot');\n"


module.exports = function (file, o) { module.exports = function (file, o) {
var opts = o || {}; const opts = o || {}
var ext = opts.ext || 'tag'; const ext = opts.ext || 'tag'
var content = ''; let content = ''


return !file.match('\.' + ext + '$') ? through() : through( return !file.match(`\.${ ext }$`) ? through() : through(
function (chunk) { // write function (chunk) { // write
content += chunk.toString(); content += chunk.toString()
}, },
function () { // end function () { // end
try { try {
this.queue(preamble + 'module.exports = ' + riot.compile(content, opts, file)); const compiled = compiler.compile(content, opts, file)
this.emit('end'); this.queue(`${ preamble }module.exports = ${ compiled }`)
this.emit('end')
} catch (e) { } catch (e) {
this.emit('error', e); this.emit('error', e)
} }
} }
); )
}; }
28 changes: 19 additions & 9 deletions package.json
Original file line number Original file line Diff line number Diff line change
@@ -1,23 +1,33 @@
{ {
"name": "riotify", "name": "riotify",
"version": "1.0.1", "version": "2.0.0",
"description": "browserify plugin for riot tag files", "description": "browserify plugin for riot tag files",
"main": "index.js", "main": "index.js",
"files": [
"index.js"
],
"dependencies": { "dependencies": {
"riot": "^2.3.0", "through": "^2.3.8"
"through": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"concat-stream": "^1.4.0", "concat-stream": "^1.5.2",
"module-deps": "^3.6.0", "eslint": "^3.10.2",
"tape": "^2.12.1" "module-deps": "^4.0.8",
"tape": "^4.6.3",
"riot": "^3.0.0",
"riot-compiler": "^3.0.0"
},
"peerDependencies": {
"riot-compiler": "^3.0.0"
}, },
"scripts": { "scripts": {
"test": "tape test/*.js" "test": "npm run eslint && npm run tape",
"tape": "tape test/*.js",
"eslint": "eslint index.js test/*.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/jhthorsen/riotify.git" "url": "https://github.com/riot/riotify.git"
}, },
"keywords": [ "keywords": [
"browserify", "browserify",
Expand All @@ -27,6 +37,6 @@
"author": "Jan Henning Thorsen", "author": "Jan Henning Thorsen",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/jhthorsen/riotify/issues" "url": "https://github.com/riot/riotify/issues"
} }
} }
Loading

0 comments on commit 0738fd3

Please sign in to comment.