1 | # ergo-core
|
2 |
|
3 | The API comprises of all the files in the api folder, and are exported according to their .js name. These api functions are also mimic-ed in ergo-cli which expose information in a human readable format.
|
4 |
|
5 | For example,
|
6 |
|
7 | * In ergo-core/api there is an init.js and looks like this:
|
8 |
|
9 | ```
|
10 | module.exports = function(folder, ...) { }
|
11 | ```
|
12 |
|
13 | * In ergo-cli/api there is another init.js. This latter calls `require('ergo-core').init` as such:
|
14 |
|
15 | ```
|
16 | module.exports.init = function(folder, ...) {
|
17 | ...
|
18 | return require('ergo-core').init(folder, ...)
|
19 | }
|
20 | ```
|
21 |
|
22 |
|
23 | ### Note:
|
24 |
|
25 | ALL complex functions exported to the CLI api are expected to return Promises, unless intrinsically syncronous (such as config.getConfigSync).
|
26 |
|
27 | NOT all functions are exported through the CLI api (such as 'config', which is a regular helper api).
|
28 |
|
29 |
|
30 | ## Rendering Pipelines
|
31 |
|
32 | The basic flow of rendering is like this:
|
33 |
|
34 | ```
|
35 | start o------> plugin 1 --------------------------> plugin 2 ----... ...---> :end
|
36 | (tex/md) (html)
|
37 | / \ / \
|
38 | / \ / \
|
39 | / \ / \
|
40 | pre-render 1 post-render 1 pre-render 3 post-render 2
|
41 | | / \
|
42 | pre-render 2 pre-post-render post-pre-render
|
43 | | |
|
44 | ... ...
|
45 | ```
|
46 | Note that each pre-render and post-render stage can have it's own pre and post rendering stages. Shown above are:
|
47 | * 2 pre-renderers for plugin 1 (pre-render 1 and pre-render 2).
|
48 | * 1 post-renderer for plugin 1, which has it's own pre-renderer (pre-post-render)
|
49 | * 1 pre-renderer for plugin 2 (pre-render 3), which has it's own post-renderer (post-pre-render)
|
50 | * 1 post-renderer for plugin 2 (post-render 2)
|
51 |
|
52 | The order of execution of the above is:
|
53 |
|
54 | 1. pre-render 1
|
55 | 1. pre-render 2
|
56 | 1. plugin 1
|
57 | 1. for each file ... ?
|
58 | 1. post-render 1
|
59 | 1. pre-post-render
|
60 | 1. pre-render 3
|
61 | 1. post-pre-render
|
62 | 1. plugin 2
|
63 | 1. post-render 2
|
64 |
|
65 | Each stage is executed on ALL files, before proceding to the next.
|
66 |
|
67 |
|
68 | A simple less -> css with a separate css-minifier would look like this:
|
69 | ```
|
70 | start o---> less ---> css-minifier ---> :end
|
71 |
|
72 | ```
|
73 |
|
74 |
|
75 | The default plugin/rendering pipleline for a textile/markdown file is more involved. An optional html minifier is also indicated where it woulc be located in the pipeline:
|
76 | ```
|
77 | start o------> plugin 1 ------------> [html-minifier] ----... ...---> :end
|
78 | (tex/md) (html)
|
79 | / \
|
80 | / \
|
81 | / \
|
82 | header_read template_man
|
83 | \ \
|
84 | header_add simpletag
|
85 | ```
|
86 |
|
87 | Note:
|
88 |
|
89 | * 'header_read' is a pre-render task of textile/marked plugins
|
90 | * 'header_add' is a post-render task of 'header_read'
|
91 | * 'template_man' is a post-render task of textile/marked plugins
|
92 | * 'simpletag' (or mustache) is a post-render task of 'template_man'
|
93 |
|
94 | So, in a linear manner, the order of execution is, where each task is done on all files before proceeding to the next:
|
95 |
|
96 | ```
|
97 | start o---> header_read
|
98 | ---> header_add ...
|
99 | ---> textile/markdown ...
|
100 | ---> template_man
|
101 | ---> simpletag ...
|
102 | (optional) ---> html-minifier
|
103 | ---> :end
|
104 | ```
|
105 |
|
106 | Notes:
|
107 |
|
108 | * The 'header_read' & subsequent 'header_add' plugins gather various bits of data and fill out the `fields` property for each file. The main content is in fields.content.
|
109 | * The 'header_read' is designed to be replaceable by a yaml reader, if that's your thing.
|
110 | * Extra fields are added in 'header_add' plugin, such as date, seo names, etc.
|
111 | * The 'header_add' also gathers lists of info, notably post_types, categories and tags and places them in context.fields
|
112 | * The textile/markdown converts just the 'content' field
|
113 | * The 'template_man':
|
114 | * Looks up and applies any 'layouts', eg blog posts, vs articles, vs other to the data, modifying the 'content' field.
|
115 | * The tag renderer simpletag:
|
116 | * Renders the 'content' field according to the 'fields' property AND context.fields, modifying the 'content' field
|
117 | * Is designed to be replaceable, for example by mustache.
|
118 | * If there is an HTML renderer (in order to minify), it is last to be invoked, but can have it's own pre & post-rendering cycles too.
|
119 |
|
120 | So, when 'preparing' any partials (/snippets) for rendering, they also go through the above pipleline.
|
121 |
|
122 |
|
123 |
|
124 | ### Race Conditions
|
125 |
|
126 | There are possible race conditions. eg:
|
127 |
|
128 | * blog.tem.html
|
129 | * blog/blog post.md
|
130 |
|
131 | The render chain for both is:
|
132 |
|
133 | * template_man, simpletag
|
134 | * header_read, header_add, marked, template_man, simpletag
|
135 |
|
136 | However, if we render each in order, then `blog.tem.html` will try to render before `header_add` has been reached in the other. There are 2 solutions to this:
|
137 |
|
138 | 1. 'right align' all rendering, padding with a 'dummy_render', such that the render chains are:
|
139 | * dummy_render, dummy_render, dummy_render, template_man, simpletag
|
140 | * header_read , header_add , marked , template_man, simpletag
|
141 | (Which just happens to work, in this case)
|
142 | 1. A more tricky 'alignment' such that all eg 'template_man', will be rendered at the same time
|
143 |
|
144 | Option 1. has been chosen, for now...
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|