@dosgato/templating 0.0.95 → 0.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.d.ts +32 -2
- package/dist/component.js +28 -3
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
32
32
|
* The editBar and newBar methods will automatically use it to blank out the editing UI.
|
|
33
33
|
*/
|
|
34
34
|
editMode: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The extension of the variation currently being rendered.
|
|
37
|
+
*
|
|
38
|
+
* See 'renderVariation' and 'variationsToFetch' for more discussion of variations.
|
|
39
|
+
*/
|
|
40
|
+
extension: string;
|
|
35
41
|
/**
|
|
36
42
|
* When hydrating an inherited component, the renderer will set this to the id of the page it
|
|
37
43
|
* came from. You may use this information in any of the phases to alter your behavior if needed.
|
|
@@ -61,8 +67,29 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
61
67
|
* Try to minimize the number of round trips you make here, make use of Promise.all and such;
|
|
62
68
|
* remember that the api functions are mostly dataloaded so calling them simultaneously is
|
|
63
69
|
* advantageous where possible.
|
|
70
|
+
*
|
|
71
|
+
* fetch() may be run while rendering a non-HTML variation of a page. If you need to do different
|
|
72
|
+
* work in those cases, remember this.extension is available.
|
|
64
73
|
*/
|
|
65
74
|
fetch(): Promise<FetchedType>;
|
|
75
|
+
/**
|
|
76
|
+
* Only run fetch for specific variations.
|
|
77
|
+
*
|
|
78
|
+
* Sometimes pages are requested with an alternate extension like .rss or .ics. See 'renderVariation'
|
|
79
|
+
* method for more discussion on this.
|
|
80
|
+
*
|
|
81
|
+
* When rendering variations, many components will not need to fetch anything, because they are not
|
|
82
|
+
* going to render anything. For instance, if we are rendering an '.ics' variation and this component
|
|
83
|
+
* is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
|
|
84
|
+
*
|
|
85
|
+
* This method returns an array of extensions where we SHOULD run fetch(). The default is only run fetch
|
|
86
|
+
* on 'html'. Components that support other variations should override this method and opt in to more
|
|
87
|
+
* extensions.
|
|
88
|
+
*
|
|
89
|
+
* The extensions listed should NOT include the preceding dot. In the case of an extended extension like
|
|
90
|
+
* '.js.map', you should provide 'js.map'.
|
|
91
|
+
*/
|
|
92
|
+
variationsToFetch(): string[];
|
|
66
93
|
/**
|
|
67
94
|
* Some components may be inheritable to subpages within the same site. For instance, a site's
|
|
68
95
|
* social media links may appear on every page's footer. To accomplish this in your template,
|
|
@@ -186,6 +213,9 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
186
213
|
* respond, or return empty string if you want your child components to be silent in all
|
|
187
214
|
* cases.
|
|
188
215
|
*
|
|
216
|
+
* The extension will NOT include the preceding dot. In the case of an extended extension like
|
|
217
|
+
* '.js.map', you will receive 'js.map'.
|
|
218
|
+
*
|
|
189
219
|
* This function will be run after the fetch phase. The context and html rendering phases
|
|
190
220
|
* will be skipped.
|
|
191
221
|
*/
|
|
@@ -272,7 +302,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
272
302
|
*/
|
|
273
303
|
static editBar: (path: string, opts: EditBarOpts) => string;
|
|
274
304
|
static newBar: (path: string, opts: NewBarOpts) => string;
|
|
275
|
-
constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean);
|
|
305
|
+
constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean, extension: string);
|
|
276
306
|
areas: Map<string, Component<any, any, ContextBase>[]>;
|
|
277
307
|
data: Omit<DataType, 'areas'>;
|
|
278
308
|
fetched: FetchedType;
|
|
@@ -544,6 +574,6 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
|
|
|
544
574
|
*/
|
|
545
575
|
addHeader: (key: string, value: string | undefined) => void;
|
|
546
576
|
protected passError(e: Error, path: string): void;
|
|
547
|
-
constructor(page: PageRecord<DataType>, editMode: boolean);
|
|
577
|
+
constructor(page: PageRecord<DataType>, editMode: boolean, extension: string);
|
|
548
578
|
}
|
|
549
579
|
export {};
|
package/dist/component.js
CHANGED
|
@@ -11,7 +11,7 @@ function defaultWrap(info) { return info.output; }
|
|
|
11
11
|
export class Component extends ResourceProvider {
|
|
12
12
|
// the constructor is part of the recursive hydration mechanism: constructing
|
|
13
13
|
// a Component will also construct/hydrate all its child components
|
|
14
|
-
constructor(data, path, parent, editMode) {
|
|
14
|
+
constructor(data, path, parent, editMode, extension) {
|
|
15
15
|
super();
|
|
16
16
|
/**
|
|
17
17
|
* Override with `true` to indicate that this template never accepts data from editors
|
|
@@ -23,6 +23,7 @@ export class Component extends ResourceProvider {
|
|
|
23
23
|
// building a template, but you can use them in the functions you do provide
|
|
24
24
|
this.areas = new Map(); // a Map of area names and the array of hydrated components in each
|
|
25
25
|
this.editMode = editMode;
|
|
26
|
+
this.extension = extension;
|
|
26
27
|
this.parent = parent;
|
|
27
28
|
const { areas, ...ownData } = data;
|
|
28
29
|
this.data = ownData;
|
|
@@ -52,10 +53,31 @@ export class Component extends ResourceProvider {
|
|
|
52
53
|
* Try to minimize the number of round trips you make here, make use of Promise.all and such;
|
|
53
54
|
* remember that the api functions are mostly dataloaded so calling them simultaneously is
|
|
54
55
|
* advantageous where possible.
|
|
56
|
+
*
|
|
57
|
+
* fetch() may be run while rendering a non-HTML variation of a page. If you need to do different
|
|
58
|
+
* work in those cases, remember this.extension is available.
|
|
55
59
|
*/
|
|
56
60
|
async fetch() {
|
|
57
61
|
return undefined;
|
|
58
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Only run fetch for specific variations.
|
|
65
|
+
*
|
|
66
|
+
* Sometimes pages are requested with an alternate extension like .rss or .ics. See 'renderVariation'
|
|
67
|
+
* method for more discussion on this.
|
|
68
|
+
*
|
|
69
|
+
* When rendering variations, many components will not need to fetch anything, because they are not
|
|
70
|
+
* going to render anything. For instance, if we are rendering an '.ics' variation and this component
|
|
71
|
+
* is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
|
|
72
|
+
*
|
|
73
|
+
* This method returns an array of extensions where we SHOULD run fetch(). The default is only run fetch
|
|
74
|
+
* on 'html'. Components that support other variations should override this method and opt in to more
|
|
75
|
+
* extensions.
|
|
76
|
+
*
|
|
77
|
+
* The extensions listed should NOT include the preceding dot. In the case of an extended extension like
|
|
78
|
+
* '.js.map', you should provide 'js.map'.
|
|
79
|
+
*/
|
|
80
|
+
variationsToFetch() { return ['html']; }
|
|
59
81
|
/**
|
|
60
82
|
* Inherit components from another page with matching area
|
|
61
83
|
*
|
|
@@ -99,6 +121,9 @@ export class Component extends ResourceProvider {
|
|
|
99
121
|
* respond, or return empty string if you want your child components to be silent in all
|
|
100
122
|
* cases.
|
|
101
123
|
*
|
|
124
|
+
* The extension will NOT include the preceding dot. In the case of an extended extension like
|
|
125
|
+
* '.js.map', you will receive 'js.map'.
|
|
126
|
+
*
|
|
102
127
|
* This function will be run after the fetch phase. The context and html rendering phases
|
|
103
128
|
* will be skipped.
|
|
104
129
|
*/
|
|
@@ -249,8 +274,8 @@ export class Component extends ResourceProvider {
|
|
|
249
274
|
}
|
|
250
275
|
}
|
|
251
276
|
export class Page extends Component {
|
|
252
|
-
constructor(page, editMode) {
|
|
253
|
-
super(page.data, '', undefined, editMode);
|
|
277
|
+
constructor(page, editMode, extension) {
|
|
278
|
+
super(page.data, '', undefined, editMode, extension);
|
|
254
279
|
this.id = page.id;
|
|
255
280
|
this.pageInfo = page;
|
|
256
281
|
}
|