-
Notifications
You must be signed in to change notification settings - Fork 5
Express Vue Renderer SPEC
The library will take 3 params, and return a promise.
There are 3 params, they are as follows:
- Full path to a .vue single file component (AKA VueFile from here on) - STRING
- Data object to be passed into the data function object in the VueFile - OBJECT
- Vue object to be passed into the VueFile and the renderer, this will be used primarily as the method for the head metadata functionality - OBJECT
The 3rd object may be optional, if no object is found it will create an empty object
The library will output a promise, with a nodeJS stream in the success block, and if an error was thrown anywhere in the library an error object will return in the catch block.
The library takes the location of the VueFile, and parses it into three objects using the official parser, this splits it up into three parts;
- Template object
- Script object
- Style object array
Parse the template from what its written in (HTML/PUG/whatever) into HTML, cache this and save it in memory.
Parse the script block from what it's written in (ES6/ES5/VanillaJS/CoffeeScript) into VanillaJS, cache this and save it into memory
Parse the style block from what it's written in (CSS/SCSS/LESS) into CSS, cache this and save it into memory.
Once we have parsed the VueFile, it's time to construct the new object, object will consist of the following;
- Template as string
- Style as string
- Script as string
- DataObject as object
- VueOptions as object
- GlobalOptions passed into library init method as object
- VueFile path as passed into library as string
Create an empty object that will be used as the render object.
The object will look something like this
rendererObject {
template: string;
data: function() {
return {}
}
}
this object will later be passed into the vueJS new Vue()
class instantiation, which will return a VUEJS class
Take the script block, and try and find any import/require statements first, if there are some found, try and require them, if this fails try to run them through the top level of this whole library, and see if it parses it as a VueFile. The logic behind this is this..
If its Javascript, it will require fine.. If its a VueFile, it will error..
If it errors, it might be a VueFile, so if we run a VueFile through the parser, it will return with an object, if it's not a VueFile it will throw an error..
if it errors two times, throw a new error and say that it couldn't render the Script Block, if it passes on either step add the rendered object to the renderer object..
look at the VueOptions object, and run it through the Head Renderer, it will return with a string, add this to the constructor object
take the template and add it to the template object as a string
start with the user's global template, which is in GlobalOptions, it consists of 3 parts, a head, middle, and end.
- create a new string
- add the head
- add the rendered head string
- add the rendered style block as string in a
<style>
block - add the middle
- add the rendered template string
- add the rendered VueJS Object string as a
<script>
block - add the end
Thats the whole functionality!
Now to do this as a stream.....
- create new string
- add head
- add rendered head string
- add rendered style block as string in a
<style>
block - add the middle
- create a new stream
- add this to the stream
- change variable to say it's now finished creating the stream.
- return the stream
every subsequent new piece of information will be added to the stream chunk... when the rendered template and rendered script finish.. these will be streamed back to the client as they are constructed.
when thats finished, add the end string, to close off the html.... and then tell the stream that its finished so the stream.on('end', callback)
api will trigger.