-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from danmademe/feature/better_tests
Feature/better tests
- Loading branch information
Showing
18 changed files
with
352 additions
and
168 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[ignore] | ||
.*/node_modules/vue/src/*. | ||
.*/dist/*. | ||
.*/node_modules/vue/src/*. |
This file was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
declare function expressVue(componentPath: string, options: Object, callback: Function): void; | ||
|
||
export = expressVue; | ||
export = expressVue; |
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,46 +1,67 @@ | ||
// @flow | ||
'use strict'; | ||
|
||
import { | ||
Defaults, | ||
Types | ||
} from './defaults'; | ||
} from './models'; | ||
import { | ||
layoutParser, | ||
componentParser | ||
} from './parser'; | ||
import {renderHtmlUtil} from './utils'; | ||
|
||
function expressVue(componentPath, options, callback) { | ||
let types = new Types(); | ||
let promiseArray = []; | ||
|
||
let defaults = new Defaults(options.settings.vue, options.settings.views); | ||
let types = new Types(); | ||
defaults.layoutPath = defaults.layoutsDir + defaults.defaultLayout + '.vue'; | ||
defaults.options = options; | ||
|
||
let componentArray = [ | ||
layoutParser(defaults.layoutPath, defaults, types.LAYOUT), | ||
componentParser(componentPath, defaults, types.COMPONENT) | ||
]; | ||
function setupComponentArray(componentPath: string, defaults: Defaults) { | ||
let array = []; | ||
array.push(layoutParser(defaults.layoutPath, defaults, types.LAYOUT)); | ||
array.push(componentParser(componentPath, defaults, types.COMPONENT)); | ||
|
||
if (defaults.options.vue && defaults.options.vue.components) { | ||
for (var component in defaults.options.vue.components) { | ||
if (defaults.options.vue.components.hasOwnProperty(component)) { | ||
const componentFile = defaults.componentsDir + defaults.options.vue.components[component] + '.vue'; | ||
componentArray.push(componentParser(componentFile, defaults, types.SUBCOMPONENT)); | ||
array.push(componentParser(componentFile, defaults, types.SUBCOMPONENT)); | ||
} | ||
} | ||
} | ||
Promise.all(componentArray).then(function(components) { | ||
renderHtmlUtil(components, defaults).then(function(html) { | ||
callback(null, html); | ||
}).catch(function(error) { | ||
console.error(error); | ||
callback(new Error(error)); | ||
}); | ||
}, function(error) { | ||
console.error(error); | ||
callback(new Error(error)); | ||
return array; | ||
} | ||
|
||
function renderError(error: string, callback: Function) { | ||
console.error(error); | ||
callback(new Error(error)); | ||
} | ||
|
||
function renderComponents(components: Array<Object>, defaults: Defaults, callback: Function) { | ||
renderHtmlUtil(components, defaults).then(function(html) { | ||
callback(null, html); | ||
}) | ||
.catch(function(error) { | ||
renderError(error, callback); | ||
}); | ||
} | ||
|
||
function expressVue(componentPath: string, options: Object, callback: Function) { | ||
|
||
let defaults = new Defaults(options); | ||
promiseArray = setupComponentArray(componentPath, defaults); | ||
|
||
Promise.all(promiseArray) | ||
.then(function(components) { | ||
renderComponents(components, defaults, callback); | ||
}) | ||
.catch(function(error) { | ||
renderError(error, callback); | ||
}); | ||
} | ||
|
||
export default expressVue; | ||
export { | ||
expressVue, | ||
expressVue as default, | ||
renderError, | ||
setupComponentArray, | ||
renderComponents | ||
}; |
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 @@ | ||
// @flow | ||
import Types from './types'; | ||
|
||
const types = new Types(); | ||
|
||
class DataObject { | ||
data: Object; | ||
constructor(componentData: Object, defaultData: Object, type: Types) { | ||
switch (type) { | ||
case types.COMPONENT: | ||
this.data = Object.assign({}, componentData, defaultData); | ||
break; | ||
case types.SUBCOMPONENT: | ||
this.data = componentData; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
export default DataObject; |
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,23 @@ | ||
// @flow | ||
class Defaults { | ||
rootPath: string; | ||
layoutsDir: string; | ||
componentsDir: string; | ||
defaultLayout: string; | ||
options: Object; | ||
backupLayout: string; | ||
layoutPath: string; | ||
options: Object; | ||
constructor(options: Object) { | ||
this.rootPath = options.settings.vue.rootPath === undefined ? options.settings.views + '/' : options.settings.vue.rootPath + '/'; | ||
this.layoutsDir = options.settings.vue.layoutsDir === undefined ? '' : this.rootPath + options.settings.vue.layoutsDir + '/'; | ||
this.componentsDir = options.settings.vue.componentsDir === undefined ? '' : options.settings.vue.componentsDir + '/'; | ||
this.defaultLayout = options.settings.vue.defaultLayout === undefined ? '' : options.settings.vue.layoutsDir === undefined ? this.rootPath + options.settings.vue.defaultLayout : options.settings.vue.defaultLayout; | ||
this.options = options.settings.vue.options === undefined ? {} : options.settings.vue.options; | ||
this.backupLayout = '<template><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><script src="https://unpkg.com/vue/dist/vue.js"></script></head><body>{{{app}}}{{{script}}}</body></html></template><script></script><style></style>'; | ||
this.layoutPath = this.layoutsDir + this.defaultLayout + '.vue'; | ||
this.options = options; | ||
} | ||
} | ||
|
||
export default Defaults; |
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,9 @@ | ||
import Types from './types'; | ||
import Defaults from './defaults'; | ||
import DataObject from './dataObject'; | ||
|
||
export { | ||
Types, | ||
Defaults, | ||
DataObject | ||
}; |
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,14 @@ | ||
// @flow | ||
|
||
class Types { | ||
COMPONENT: string; | ||
SUBCOMPONENT: string; | ||
LAYOUT: string; | ||
constructor() { | ||
this.COMPONENT = 'COMPONENT'; | ||
this.SUBCOMPONENT = 'SUBCOMPONENT'; | ||
this.LAYOUT = 'LAYOUT'; | ||
} | ||
} | ||
|
||
export default Types; |
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
Oops, something went wrong.