@dosgato/templating 1.1.10 → 1.1.11

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.
@@ -211,20 +211,27 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
211
211
  * render of the parent component.
212
212
  */
213
213
  abstract render(): string;
214
+ /**
215
+ * If you are rendering a variation for a component that has areas and children,
216
+ * you can call Component.renderVariation(extension, this.renderedAreas) to help you easily
217
+ * render the areas and children inside whatever wrapper content you need.
218
+ */
219
+ static renderVariation(extension: string, renderedAreas: Map<string, RenderedComponent[]>): string;
214
220
  /**
215
221
  * Sometimes pages are requested with an alternate extension like .rss or .ics. In these
216
222
  * situations, each component should consider whether it should output anything. For
217
223
  * instance, if the extension is .rss and a component represents an article, it should
218
224
  * probably output an RSS item. If you don't recognize the extension, just return
219
- * super.renderVariation(extension, renderedAreas) to give your child components a chance to
225
+ * Component.renderVariation(extension, this.renderedAreas) to give your child components a chance to
220
226
  * respond, or return empty string if you want your child components to be silent in all
221
227
  * cases.
222
228
  *
229
+ * If you implement this function to add content for a specific extension, you should also
230
+ * probably override `shouldFetchVariation` to return true for that extension. Also remember
231
+ * to use Component.renderVariation(extension, this.renderedAreas) to render your child components.
232
+ *
223
233
  * The extension will NOT include the preceding dot. In the case of an extended extension like
224
234
  * '.js.map', you will receive 'js.map'.
225
- *
226
- * This function will be run after the fetch phase. The context and html rendering phases
227
- * will be skipped.
228
235
  */
229
236
  renderVariation(extension: string): string;
230
237
  /**
package/dist/component.js CHANGED
@@ -85,23 +85,32 @@ export class Component extends ResourceProvider {
85
85
  setContext(renderCtxFromParent, areaName) {
86
86
  return renderCtxFromParent;
87
87
  }
88
+ /**
89
+ * If you are rendering a variation for a component that has areas and children,
90
+ * you can call Component.renderVariation(extension, this.renderedAreas) to help you easily
91
+ * render the areas and children inside whatever wrapper content you need.
92
+ */
93
+ static renderVariation(extension, renderedAreas) {
94
+ return Array.from(renderedAreas.values()).flatMap(ras => ras.map(ra => ra.output)).join('');
95
+ }
88
96
  /**
89
97
  * Sometimes pages are requested with an alternate extension like .rss or .ics. In these
90
98
  * situations, each component should consider whether it should output anything. For
91
99
  * instance, if the extension is .rss and a component represents an article, it should
92
100
  * probably output an RSS item. If you don't recognize the extension, just return
93
- * super.renderVariation(extension, renderedAreas) to give your child components a chance to
101
+ * Component.renderVariation(extension, this.renderedAreas) to give your child components a chance to
94
102
  * respond, or return empty string if you want your child components to be silent in all
95
103
  * cases.
96
104
  *
105
+ * If you implement this function to add content for a specific extension, you should also
106
+ * probably override `shouldFetchVariation` to return true for that extension. Also remember
107
+ * to use Component.renderVariation(extension, this.renderedAreas) to render your child components.
108
+ *
97
109
  * The extension will NOT include the preceding dot. In the case of an extended extension like
98
110
  * '.js.map', you will receive 'js.map'.
99
- *
100
- * This function will be run after the fetch phase. The context and html rendering phases
101
- * will be skipped.
102
111
  */
103
112
  renderVariation(extension) {
104
- return Array.from(this.renderedAreas.values()).flatMap(ras => ras.map(ra => ra.output)).join('');
113
+ return Component.renderVariation(extension, this.renderedAreas);
105
114
  }
106
115
  /**
107
116
  * helper function to print an area's component list, but you can also override this if you
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {