Skip to content

Commit d66f010

Browse files
Merge branch 'release/0.6.10'
2 parents 81222ab + d6fb973 commit d66f010

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-vue-renderer",
3-
"version": "0.6.9",
3+
"version": "0.6.10",
44
"description": "Rendering Engine for turning Vue files into Javascript Objects",
55
"homepage": "https://github.com/express-vue/express-vue-renderer",
66
"author": {

src/models/defaults.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ class Defaults {
1717
options: Object;
1818
vue: Object;
1919
data: Object;
20+
style: string;
2021
constructor(options: Object = {}) {
2122
this.options = options;
2223
this.layout = new Layout.Layout(options.layout);
2324

25+
if (options.style) {
26+
this.style = options.style;
27+
}
28+
2429
if (options.rootPath) {
2530
this.rootPath = path.resolve(options.rootPath);
2631
}

src/parser/component.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const fs = require('fs');
44
const camelCase = require('camel-case');
55
const compiler = require('vue-template-compiler');
6-
const CleanCSS = require('clean-css');
76
const styleParser = require('./style');
87
const htmlParser = require('./html');
98
const scriptParser = require('./script');
@@ -28,13 +27,14 @@ function componentParser(templatePath: string, defaults: Object, type: string, C
2827
let error = `Could Not Find Component, I was expecting it to live here \n${templatePath} \nBut I couldn't find it there, ¯\\_(ツ)_/¯\n\n`;
2928
reject(error);
3029
} else {
31-
parseContent(content, templatePath, defaults, type, Cache).then(contentObject => {
30+
parseContent(content, templatePath, defaults, type, Cache)
31+
.then(contentObject => {
3232
// set the cache for the component
33-
Cache.set(templatePath, contentObject);
34-
resolve(contentObject);
35-
}).catch(error => {
36-
reject(error);
37-
});
33+
Cache.set(templatePath, contentObject);
34+
resolve(contentObject);
35+
}).catch(error => {
36+
reject(error);
37+
});
3838
}
3939
});
4040
}
@@ -66,11 +66,10 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
6666
Promise.all(promiseArray).then(resultsArray => {
6767
const template = resultsArray[0];
6868
const script = resultsArray[1];
69-
let style = '';
70-
if (resultsArray[2]) {
71-
style = resultsArray[2];
69+
if (defaults.style === undefined) {
70+
defaults.style = resultsArray[2];
7271
} else {
73-
style = new CleanCSS({}).minify(resultsArray[1].styles ? resultsArray[1].styles : '').styles;
72+
defaults.style += resultsArray[2];
7473
}
7574

7675
script.template = template;
@@ -79,7 +78,7 @@ function parseContent(content: string, templatePath: string, defaults: Object, t
7978
template: template,
8079
parsedContent: parsedContent,
8180
type: type,
82-
style: style,
81+
style: defaults.style,
8382
name: camelCase(templateName),
8483
script: script
8584
};

src/utils/require.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class Options {
2222
}
2323
}
2424

25-
function getVueObject(componentPath: string, rootPath: string, vueComponentFileMatch: string, Cache: Object): Promise < {rendered:Object, match: string} > {
25+
function getVueObject(componentPath: string, rootPath: string, vueComponentFileMatch: string, Cache: Object, Options: Options): Promise < {rendered:Object, match: string} > {
2626
const GlobalOptions = new Models.Defaults({
2727
rootPath: rootPath,
28-
component: componentPath
28+
component: componentPath,
29+
style: Options.defaults.style || ''
2930
});
3031
return new Promise((resolve, reject) => {
3132
Utils.setupComponent(componentPath, GlobalOptions, Cache)
@@ -34,6 +35,12 @@ function getVueObject(componentPath: string, rootPath: string, vueComponentFileM
3435
if (!rendered) {
3536
reject(new Error('Renderer Error'));
3637
} else {
38+
if (Options.defaults.style) {
39+
Options.defaults.style += rendered.layout.style;
40+
} else {
41+
Options.defaults.style = rendered.layout.style;
42+
}
43+
3744
resolve({
3845
rendered: rendered,
3946
match: vueComponentFileMatch
@@ -99,7 +106,7 @@ function requireFromString(code: string, filename: string = '', optsObj: Object
99106
//this is because its easier to do string replace later
100107
const vueComponentFile = vueComponentFileMatch.match(options.vueFileRegex);
101108
if (vueComponentFile && vueComponentFile.length > 0) {
102-
promiseArray.push(getVueObject(vueComponentFile[0], options.rootPath, vueComponentFileMatch, Cache));
109+
promiseArray.push(getVueObject(vueComponentFile[0], options.rootPath, vueComponentFileMatch, Cache, options));
103110
}
104111
}
105112
Promise.all(promiseArray)

tests/example/components/inner.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<p>Inner Text</p>
3+
<p class="pink">Inner Text</p>
44
</div>
55
</template>
66

@@ -13,4 +13,8 @@ export default {
1313
</script>
1414

1515
<style lang="css">
16+
.pink {
17+
color: pink;
18+
text-decoration: underline;
19+
}
1620
</style>

tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const vueOptions = {
2020
}
2121
}
2222

23-
const exampleHead = `<head>\n<title>Page Title</title>\n<style>.test{color:#00f}.red{color:#9acd32}</style></head>`;
24-
const exampleScript = `<script>(function(){"use strict";var u=function(){return new Vue({mixins:[{methods:{hello:function(){console.log(\'Hello\')}}}],data:function(){return{"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods:{test:function(){console.error(\'test\')}},components:{uuid:{props:["uuid"],data:function(){return{}},components:{inner:{data:function(){return{}},template:"<div><p>Inner Text</p></div>"}},styles:"",template:"<div><inner></inner><h2 class=\\"test\\">Uuid: {{uuid ? uuid : \'no uuid\'}}</h2></div>"},uuid2:{props:["uuid2"],data:function(){return{}},template:"<div><h3 class=\\"red\\">Uuid2: {{uuid2 ? uuid2 : \'no uuid\'}}</h3></div>"}},styles:".test{color:#00f}.red{color:#9acd32}",template:"<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>"})};typeof module!==\'undefined\'&&module.exports?(module.exports=u):(this.app=u())}).call(this),app.$mount(\'#app\')</script>`;
23+
const exampleHead = `<head>\n<title>Page Title</title>\n<style>.red{color:#9acd32}.pink{color:pink;text-decoration:underline}.test{color:#00f}</style></head>`;
24+
const exampleScript = `<script>(function(){"use strict";var t=function(){return new Vue({mixins:[{methods:{hello:function(){console.log('Hello')}}}],data:function(){return{"title":"Express Vue","message":"Hello world","uuid":"farts"}},methods:{test:function(){console.error('test')}},components:{uuid:{props:["uuid"],data:function(){return{}},components:{inner:{data:function(){return{}},template:"<div><p class=\\"pink\\">Inner Text</p></div>"}},styles:".pink{color:pink;text-decoration:underline}",template:"<div><inner></inner><h2 class=\\"test\\">Uuid: {{uuid ? uuid : 'no uuid'}}</h2></div>"},uuid2:{props:["uuid2"],data:function(){return{}},template:"<div><h3 class=\\"red\\">Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3></div>"}},styles:".pink{color:pink;text-decoration:underline}.test{color:#00f}.red{color:#9acd32}",template:"<div><h1>{{title}}</h1><p>Welcome to the {{title}} demo. Click a link:</p><input v-model=\\"message\\" placeholder=\\"edit me\\"><p>{{message}}</p><uuid :uuid=\\"uuid\\"></uuid><uuid2 :uuid2=\\"uuid2\\"></uuid2><button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.hello\\">Test mixin</button> <button type=\\"button\\" name=\\"button\\" v-on:click=\\"this.test\\">Test method</button></div>"})};typeof module!=='undefined'&&module.exports?(module.exports=t):(this.app=t())}).call(this),app.$mount('#app')</script>`;
2525

2626
test('renders App object', t => {
2727
const renderer = new ExpressVueRenderer(options);

tests/models/models.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const options = {
3535
{foo: true}
3636
]
3737
}
38-
39-
}
38+
},
39+
style: '.fart{color:brown}'
4040
};
4141

4242
const layout = new Layout.Layout(customLayout);
@@ -55,7 +55,8 @@ const exampleObject = {
5555
cache: {
5656
max: 500,
5757
maxAge: 3600000
58-
}
58+
},
59+
style: '.fart{color:brown}'
5960
};
6061

6162
test('Root Path', t => {

tests/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('it should parse components', t => {
6565
.then(function (layout) {
6666
const exampleLayout = {
6767
type: 'COMPONENT',
68-
style: '.test{color:#00f}',
68+
style: '.pink{color:pink;text-decoration:underline}.test{color:#00f}',
6969
name: 'component',
7070
script: {
7171
data() {

0 commit comments

Comments
 (0)