Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | 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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
--- | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
script: | ||
- npm install | ||
- npm test | ||
- '4.*' | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
var through = require('through'); | ||
var riot = require('riot'); | ||
var preamble = "var riot = require('riot');\n"; | ||
'use strict' | ||
|
||
const through = require('through') | ||
const compiler = require('riot-compiler') | ||
const preamble = "var riot = require('riot');\n" | ||
|
||
module.exports = function (file, o) { | ||
var opts = o || {}; | ||
var ext = opts.ext || 'tag'; | ||
var content = ''; | ||
const opts = o || {} | ||
const ext = opts.ext || 'tag' | ||
let content = '' | ||
|
||
return !file.match('\.' + ext + '$') ? through() : through( | ||
return !file.match(`\.${ ext }$`) ? through() : through( | ||
function (chunk) { // write | ||
content += chunk.toString(); | ||
content += chunk.toString() | ||
}, | ||
function () { // end | ||
try { | ||
this.queue(preamble + 'module.exports = ' + riot.compile(content, opts, file)); | ||
this.emit('end'); | ||
const compiled = compiler.compile(content, opts, file) | ||
this.queue(`${ preamble }module.exports = ${ compiled }`) | ||
this.emit('end') | ||
} catch (e) { | ||
this.emit('error', e); | ||
this.emit('error', e) | ||
} | ||
} | ||
); | ||
}; | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
var test = require('tape'); | ||
var concat = require('concat-stream'); | ||
var moduleDeps = require('module-deps'); | ||
var path = require('path'); | ||
var riotify = require('../'); | ||
const test = require('tape') | ||
const concat = require('concat-stream') | ||
const moduleDeps = require('module-deps') | ||
const path = require('path') | ||
const riotify = require('../') | ||
|
||
test('ignore', function (t) { | ||
var file = path.join(__dirname, 'ignore.ext'); | ||
var p = moduleDeps(); | ||
test('ignore', t => { | ||
const file = path.join(__dirname, 'ignore.ext') | ||
const p = moduleDeps() | ||
|
||
p.write({ transform: riotify, options: {} }); | ||
p.write({ file: file, id: file, entry: true }); | ||
p.end(); | ||
p.write({ transform: riotify, options: {} }) | ||
p.write({ file, id: file, entry: true }) | ||
p.end() | ||
|
||
t.plan(3); | ||
p.pipe(concat(function (out) { | ||
t.ok(out[0], 'got output element'); | ||
t.ok(out[0].source.length, 'got output element with source'); | ||
t.ok(out[0].source.match(/^<todo>/), 'skipped ignore.ext'); | ||
})); | ||
}); | ||
t.plan(3) | ||
p.pipe(concat(out => { | ||
t.ok(out[0], 'got output element') | ||
t.ok(out[0].source.length, 'got output element with source') | ||
t.ok(out[0].source.match(/^<todo>/), 'skipped ignore.ext') | ||
})) | ||
}) | ||
|
||
test('compile', function (t) { | ||
var file = path.join(__dirname, 'todo.tag'); | ||
var p = moduleDeps(); | ||
test('compile', t => { | ||
const file = path.join(__dirname, 'todo.tag') | ||
const p = moduleDeps() | ||
|
||
p.write({ transform: riotify, options: {} }); | ||
p.write({ file: file, id: file, entry: true }); | ||
p.end(); | ||
p.write({ transform: riotify, options: {} }) | ||
p.write({ file, id: file, entry: true }) | ||
p.end() | ||
|
||
t.plan(6); | ||
p.pipe(concat(function (out) { | ||
t.is(out.length, 2, 'got two files as output'); | ||
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js'); | ||
t.ok(out[0].source.match(/module.exports/), 'riot.js'); | ||
t.ok(out[1].id.match(/todo\.tag$/), 'out.1 is todo.tag'); | ||
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot'); | ||
t.ok(out[1].source.match(/riot.tag2\(.*todo/), 'compiled compile.tag'); | ||
})); | ||
}); | ||
t.plan(6) | ||
p.pipe(concat(out => { | ||
t.is(out.length, 2, 'got two files as output') | ||
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js') | ||
t.ok(out[0].source.match(/module.exports/), 'riot.js') | ||
t.ok(out[1].id.match(/todo\.tag$/), 'out.1 is todo.tag') | ||
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot') | ||
t.ok(out[1].source.match(/riot.tag2\(.*todo/), 'compiled compile.tag') | ||
})) | ||
}) | ||
|
||
test('compile-custom-ext', function (t) { | ||
var file = path.join(__dirname, 'customext.html'); | ||
var p = moduleDeps(); | ||
test('compile-custom-ext', t => { | ||
const file = path.join(__dirname, 'customext.html') | ||
const p = moduleDeps() | ||
|
||
p.write({ transform: riotify, options: {ext: "html"} }); | ||
p.write({ file: file, id: file, entry: true }); | ||
p.end(); | ||
p.write({ transform: riotify, options: {ext: 'html'} }) | ||
p.write({ file, id: file, entry: true }) | ||
p.end() | ||
|
||
t.plan(6); | ||
p.pipe(concat(function (out) { | ||
t.is(out.length, 2, 'got two files as output'); | ||
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js'); | ||
t.ok(out[0].source.match(/module.exports/), 'riot.js'); | ||
t.ok(out[1].id.match(/customext\.html$/), 'out.1 is customext.html'); | ||
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot'); | ||
t.ok(out[1].source.match(/riot.tag2\(.*customext/), 'compiled compile.tag'); | ||
})); | ||
}); | ||
t.plan(6) | ||
p.pipe(concat(out => { | ||
t.is(out.length, 2, 'got two files as output') | ||
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js') | ||
t.ok(out[0].source.match(/module.exports/), 'riot.js') | ||
t.ok(out[1].id.match(/customext\.html$/), 'out.1 is customext.html') | ||
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot') | ||
t.ok(out[1].source.match(/riot.tag2\(.*customext/), 'compiled compile.tag') | ||
})) | ||
}) | ||
|
||
test('compile-custom-ext-ignore', function (t) { | ||
var file = path.join(__dirname, 'todo.tag'); | ||
var p = moduleDeps(); | ||
test('compile-custom-ext-ignore', t => { | ||
const file = path.join(__dirname, 'todo.tag') | ||
const p = moduleDeps() | ||
|
||
p.write({ transform: riotify, options: {ext: "html"} }); | ||
p.write({ file: file, id: file, entry: true }); | ||
p.end(); | ||
p.write({ transform: riotify, options: {ext: 'html'} }) | ||
p.write({ file, id: file, entry: true }) | ||
p.end() | ||
|
||
t.plan(3); | ||
p.pipe(concat(function (out) { | ||
t.ok(out[0], 'got output element'); | ||
t.ok(out[0].source.length, 'got output element with source'); | ||
t.ok(out[0].source.match(/^<todo>/), 'skipped todo.tag'); | ||
})); | ||
}); | ||
t.plan(3) | ||
p.pipe(concat(out => { | ||
t.ok(out[0], 'got output element') | ||
t.ok(out[0].source.length, 'got output element with source') | ||
t.ok(out[0].source.match(/^<todo>/), 'skipped todo.tag') | ||
})) | ||
}) | ||
|
||
test('module exports riot tag', function (t) { | ||
var file = path.join(__dirname, 'todo.tag'); | ||
var p = moduleDeps(); | ||
test('module exports riot tag', t => { | ||
const file = path.join(__dirname, 'todo.tag') | ||
const p = moduleDeps() | ||
|
||
p.write({ transform: riotify }); | ||
p.write({ file: file, id: file, entry: true }); | ||
p.end(); | ||
p.write({ transform: riotify }) | ||
p.write({ file, id: file, entry: true }) | ||
p.end() | ||
|
||
t.plan(1); | ||
p.pipe(concat(function (out) { | ||
t.ok(out[1].source.match(/module.exports = riot.tag2/), 'riot tag'); | ||
})); | ||
}); | ||
t.plan(1) | ||
p.pipe(concat(out => { | ||
t.ok(out[1].source.match(/module.exports = riot.tag2/), 'riot tag') | ||
})) | ||
}) |