Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

Add ejs support #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ These are the preprocessors supported by vueify out of the box:
- scss (via `node-sass`, use `sass` in [config section](#configuring-options))
- jade
- pug
- ejs
- coffee-script (use `coffee` in [config section](#configuring-options))

## PostCSS
Expand Down
12 changes: 12 additions & 0 deletions lib/compilers/ejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var ensureRequire = require('../ensure-require.js')

module.exports = function (raw, cb, compiler) {
ensureRequire('ejs', 'ejs')
var ejs = require('ejs')
try {
var html = ejs.render(raw, compiler.options.ejs || {})
} catch (err) {
return cb(err)
}
cb(null, html)
}
3 changes: 2 additions & 1 deletion lib/compilers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
scss: require('./sass'),
stylus: require('./stylus'),
jade: require('./jade'),
pug: require('./pug')
pug: require('./pug'),
ejs: require('./ejs')
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"chalk": "^1.1.1",
"convert-source-map": "^1.2.0",
"cssnano": "^3.3.2",
"ejs": "^2.5.2",
"hash-sum": "^1.0.2",
"lru-cache": "^4.0.0",
"object-assign": "^4.0.1",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/ejs-template-import.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<h1>hello</h1>
</div>
1 change: 1 addition & 0 deletions test/fixtures/ejs-template-import.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template lang="ejs" src="./ejs-template-import.ejs"></template>
5 changes: 5 additions & 0 deletions test/fixtures/ejs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template lang="ejs">
<div>
<h1>This is the app</h1><comp-a></comp-a><comp-b></comp-b>
</div>
</template>
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ describe('vueify', () => {
)
})

test('ejs', window => {
var module = window.vueModule
assertRenderFn(module,
'<div>' +
'<h1>This is the app</h1>' +
'<comp-a></comp-a>' +
'<comp-b></comp-b>' +
'</div>'
)
})

test('scoped-css', window => {
var module = window.vueModule
var id = 'data-v-' + genId(require.resolve('./fixtures/scoped-css.vue'))
Expand Down Expand Up @@ -123,6 +134,11 @@ describe('vueify', () => {
assertRenderFn(module, '<div><h1>hello</h1></div>')
})

test('ejs-template-import', window => {
var module = window.vueModule
assertRenderFn(module, '<div><h1>hello</h1></div>')
})

test('script-import', window => {
var module = window.vueModule
expect(module.data().msg).to.contain('Hello from Component A!')
Expand Down