Skip to content

Commit 6ba394c

Browse files
Merge pull request #77 from express-vue/feature/move_example
moves example folder into tests
2 parents 8b564dc + 02c3433 commit 6ba394c

File tree

11 files changed

+220
-10
lines changed

11 files changed

+220
-10
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
],
2222
"ava": {
2323
"files": [
24-
"tests/**/*.js"
24+
"tests/**/*.js",
25+
"!tests/example/**/*.js"
2526
],
2627
"source": [
2728
"src/**/*.js",
@@ -50,8 +51,8 @@
5051
"scripts": {
5152
"release": "generate-release",
5253
"flow": "flow",
53-
"debug": "npm run build && node --inspect example/app.js",
54-
"start": "npm run build && node example/app.js",
54+
"debug": "npm run build && node --inspect tests/example/app.js",
55+
"start": "npm run build && node tests/example/app.js",
5556
"prepublish": "npm run build && nsp check",
5657
"pretest": "eslint . --fix",
5758
"test": "eslint src && nyc ava",

tests/example/app.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// @flow
2+
const path = require('path');
3+
const express = require('express');
4+
const uuidv4 = require('uuid/v4');
5+
6+
const expressVueRenderer = require('../lib');
7+
const expressVue = require('./expressVue');
8+
9+
var exampleMixin = {
10+
methods: {
11+
hello: function () {
12+
console.log('Hello');
13+
}
14+
}
15+
};
16+
17+
const options = {
18+
rootPath: path.join(__dirname, 'vueFiles'),
19+
vue: {
20+
head: {
21+
meta: [{
22+
property: 'og:title',
23+
content: 'Page Title'
24+
},
25+
{
26+
name: 'twitter:title',
27+
content: 'Page Title'
28+
},
29+
{
30+
script: 'https://unpkg.com/vue@2.4.2/dist/vue.js'
31+
}, {
32+
name: 'viewport',
33+
content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
34+
}
35+
]
36+
}
37+
},
38+
data: {
39+
thing: true
40+
}
41+
};
42+
43+
44+
renderer = expressVue.init(options);
45+
46+
const app = express();
47+
app.use(express.static('./dist'));
48+
49+
app.use(renderer);
50+
51+
app.get('/', (req, res) => {
52+
const data = {
53+
title: 'Express Vue',
54+
message: 'Hello world',
55+
uuid: uuidv4(),
56+
uuid2: uuidv4()
57+
};
58+
const vueOptions = {
59+
head: {
60+
title: 'Page Title',
61+
meta: [
62+
{
63+
property: 'og:title2',
64+
content: 'Page Title2'
65+
}
66+
]
67+
}
68+
}
69+
res.renderVue('main.vue', data, vueOptions)
70+
});
71+
72+
app.listen(3000);
73+
74+
console.log('express example start in 127.0.0.1:3000');
75+
module.exports = app;

tests/example/components/inner.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div>
3+
<p>Inner Text</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data: function () {
10+
return {}
11+
}
12+
}
13+
</script>
14+
15+
<style lang="css">
16+
</style>

tests/example/components/uuid.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div>
3+
<inner></inner>
4+
<h2 class="test">Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
5+
</div>
6+
</template>
7+
8+
<script>
9+
import inner from '../components/inner.vue';
10+
export default {
11+
props: ['uuid'],
12+
data: function () {
13+
return {}
14+
},
15+
components: {
16+
inner: inner
17+
}
18+
}
19+
</script>
20+
21+
<style lang="css">
22+
.test {
23+
color: blue;
24+
}
25+
</style>

tests/example/components/uuid2.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<h3 class="red">Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
props: ['uuid2'],
10+
data: function () {
11+
return {}
12+
}
13+
}
14+
</script>
15+
16+
<style lang="css">
17+
.red {
18+
color: yellowgreen;
19+
}
20+
</style>

tests/example/expressVue.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const ExpressVueRenderer = require('../lib');
2+
3+
//This is the Middlewarein express-vue this wont be in the file
4+
function init(options) {
5+
//Make new object
6+
const Renderer = new ExpressVueRenderer(options);
7+
//Middleware init
8+
return (req, res, next) => {
9+
//Res RenderVUE function
10+
res.renderVue = (componentPath, data = {}, vueOptions = {}) => {
11+
res.set('Content-Type', 'text/html');
12+
Renderer.renderToStream(componentPath, data, vueOptions)
13+
.then(stream => {
14+
stream.on('data', chunk => res.write(chunk));
15+
stream.on('end', () => res.end());
16+
})
17+
.catch(error => {
18+
console.error(error);
19+
res.send(error);
20+
});
21+
};
22+
return next();
23+
};
24+
}
25+
26+
module.exports.init = init;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const exampleMixin = {
2+
methods: {
3+
hello: function () {
4+
console.log('Hello');
5+
}
6+
}
7+
};
8+
9+
module.exports = exampleMixin;
10+
exports.default = exampleMixin;

tests/example/vueFiles/main.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<template>
2+
<div>
3+
<h1>{{title}}</h1>
4+
<p>Welcome to the {{title}} demo. Click a link:</p>
5+
<input v-model="message" placeholder="edit me">
6+
<p>{{message}}</p>
7+
<uuid :uuid="uuid"></uuid>
8+
<uuid2 :uuid2="uuid2"></uuid2>
9+
<button type="button" name="button" v-on:click="this.hello">Test mixin</button>
10+
<button type="button" name="button" v-on:click="this.test">Test method</button>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import exampleMixin from '../mixins/exampleMixin';
16+
import uuid from '../components/uuid.vue';
17+
import uuid2 from '../components/uuid2.vue';
18+
export default {
19+
mixins: [exampleMixin],
20+
data: function () {
21+
return {}
22+
},
23+
methods: {
24+
test: function () {
25+
console.error('test');
26+
}
27+
},
28+
components: {
29+
uuid: uuid,
30+
uuid2: uuid2
31+
}
32+
}
33+
</script>
34+
35+
<style lang="css">
36+
37+
</style>

tests/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Models = require('../src/models');
55
const path = require('path');
66

77
const options = {
8-
rootPath: path.join(__dirname, '../example')
8+
rootPath: path.join(__dirname, 'example/vueFiles')
99
};
1010

1111
const data = {

tests/parser/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var cacheOptions = {
2020
var lruCache = LRU(cacheOptions);
2121

2222
let types = new Types();
23-
const component = __dirname + '/../../example/components/uuid.vue';
23+
const component = path.join(__dirname, '../example/components/uuid.vue');
2424
const options = {
25-
rootPath: path.join(__dirname, '../../example'),
25+
rootPath: path.join(__dirname, '../example/vueFiles'),
2626
component: 'uuid.vue'
2727
};
2828

0 commit comments

Comments
 (0)