-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
5dfb040
commit f1fbcb2
Showing
6 changed files
with
95 additions
and
63 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,50 @@ | ||
var map = require('./map') | ||
|
||
, fs = require('fs') | ||
, path = require('path') | ||
|
||
, read = fs.readFileSync | ||
This comment has been minimized.
Sorry, something went wrong. |
||
, extname = path.extname; | ||
|
||
var Adapter = function (source, options) { | ||
this.source = source; | ||
this.options = (options || {}); | ||
this.compiler = Adapter.compiler(options); | ||
this.kind = Adapter.kind(options); | ||
} | ||
|
||
Adapter.prototype = { | ||
render: function () { | ||
if (this.compiler) { | ||
if (!this.source && this.options.path) | ||
this.source = read(this.options.path, 'utf8'); | ||
return this.compiler.render(this.source, this.options); | ||
} | ||
} | ||
} | ||
|
||
Adapter.compiler = function (options) { | ||
if (options.path && !options.with) | ||
options.with = map.extensions[extname(options.path)]; | ||
return map.compilers[options.with]; | ||
} | ||
|
||
Adapter.kind = function (options) { | ||
var compiler | ||
, kind; | ||
|
||
options = (options || {}); | ||
compiler = Adapter.compiler(options); | ||
|
||
if (compiler) { | ||
kind = map.kinds[compiler.kind]; | ||
kind.name = compiler.kind; | ||
return kind; | ||
} | ||
} | ||
|
||
Adapter.supports = function (options) { | ||
return !!Adapter.compiler(options); | ||
} | ||
|
||
module.exports = Adapter; |
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
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 |
---|---|---|
|
@@ -47,5 +47,4 @@ Peak.prototype = { | |
|
||
} | ||
|
||
Peak.Compiler = Compiler; | ||
module.exports = Peak; |
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 |
---|---|---|
|
@@ -2,8 +2,8 @@ var Peak = require('../') | |
, Commands = require('../lib/commands') | ||
, Lexer = require('../lib/compiler/lexer') | ||
, Parser = require('../lib/compiler/parser') | ||
, Adapter = require('../lib/compiler/adapter') | ||
, Compiler = require('../lib/compiler') | ||
, Adapter = require('../lib/adapter') | ||
|
||
, chai = require('chai') | ||
, fs = require('fs') | ||
|
@@ -314,32 +314,32 @@ describe('parser', function () { | |
describe('adapter', function () { | ||
|
||
it('should return js kind if ext is .coffee', function () { | ||
var adapter = Adapter('$ ->\nconsole.log \'test\'', { path: 'test.coffee' }); | ||
var adapter = new Adapter('$ ->\nconsole.log \'test\'', { path: 'test.coffee' }); | ||
adapter.kind.name.should.eq('javascript'); | ||
}) | ||
|
||
it('should return html kind if ext is .jade', function () { | ||
var adapter = Adapter('html\n head', { path: 'test.jade' }); | ||
var adapter = new Adapter('html\n head', { path: 'test.jade' }); | ||
adapter.kind.name.should.eq('html'); | ||
}) | ||
|
||
it('should return html kind if ext is .sneak', function () { | ||
var adapter = Adapter('html\n head', { path: 'test.sneak' }); | ||
var adapter = new Adapter('html\n head', { path: 'test.sneak' }); | ||
adapter.kind.name.should.eq('html'); | ||
}) | ||
|
||
it('should return html kind if ext is .haml', function () { | ||
var adapter = Adapter('%html', { path: 'test.haml' }); | ||
var adapter = new Adapter('%html', { path: 'test.haml' }); | ||
adapter.kind.name.should.eq('html'); | ||
}) | ||
|
||
it('should return css kind if ext is .styl', function () { | ||
var adapter = Adapter('body\n background: black', { path: 'test.styl' }); | ||
var adapter = new Adapter('body\n background: black', { path: 'test.styl' }); | ||
adapter.kind.name.should.eq('css'); | ||
}) | ||
|
||
it('should return css kind if ext is .less', function () { | ||
var adapter = Adapter('body { &.index { background: blue; } }', { path: 'test.less' }); | ||
var adapter = new Adapter('body { &.index { background: blue; } }', { path: 'test.less' }); | ||
adapter.kind.name.should.eq('css'); | ||
}) | ||
|
||
|
@@ -528,7 +528,7 @@ describe('watcher', function (){ | |
|
||
describe('deployer', function () { | ||
|
||
this.timeout(10000); | ||
this.timeout(20000); | ||
|
||
it('should throw exception if credentials are invalid', function (done) { | ||
var peak = new Peak(join(fixtures, 'deployer', 'invalid'), {email: "[email protected]", password: "!@#$%^&"}); | ||
|
Still sync here...