UNPKG

3.45 kBMarkdownView Raw
1# stencil-paper
2[![Build Status](https://travis-ci.org/bigcommerce/paper.svg?branch=master)](https://travis-ci.org/bigcommerce/paper) [![npm (scoped)](https://img.shields.io/npm/v/@bigcommerce/stencil-paper.svg)](https://www.npmjs.com/package/@bigcommerce/stencil-paper)
3
4*stencil-paper* is a plugin for `stencil-cli`. Its duty is to load templates and translations, and call
5out to [paper-handlebars](https://github.com/bigcommerce/paper-handlebars) to render pages.
6
7## Usage
8Load Paper into your app:
9```
10const Paper = require('@bigcommerce/stencil-paper');
11```
12
13Instatiate paper passing `siteSettings`, `themeSettings`, `assembler`, and an optional `logger` (overriding the default logger):
14```
15const paper = new Paper(siteSettings, themeSettings, assembler, logger);
16```
17
18The `assembler` is the interface that Paper uses to load the templates and translations. This way we can use paper to load the templates
19from the file system or any other source. It's just an object that implements two methods: `getTemplates()` & `getTranslations()`:
20```
21const assembler = {
22 getTemplates: (path, processor) => {
23 return new Promise((resolve, reject) => {
24 // implement me
25 resolve(processor(templates));
26 });
27 },
28 getTranslations: () => {
29 return new Promise((resolve, reject) => {
30 // implement me
31 resolve(translations);
32 });
33 }
34};
35```
36
37Now we can load the theme for the page we want to render:
38```
39paper.loadTheme(path, 'en').then(() => {
40 paper.render(path, context).then(html => {
41 reply(html);
42 });
43});
44```
45
46## Helpers Reference
47See the [stencil API reference](https://developer.bigcommerce.com/stencil-docs/reference-docs/handlebars-helpers-reference) for documentation on the available helpers.
48
49#### License
50Copyright (c) 2015-2022, Bigcommerce Inc.
51All rights reserved.
52
53Redistribution and use in source and binary forms, with or without
54modification, are permitted provided that the following conditions are met:
551. Redistributions of source code must retain the above copyright
56 notice, this list of conditions and the following disclaimer.
572. Redistributions in binary form must reproduce the above copyright
58 notice, this list of conditions and the following disclaimer in the
59 documentation and/or other materials provided with the distribution.
603. All advertising materials mentioning features or use of this software
61 must display the following acknowledgement:
62 This product includes software developed by Bigcommerce Inc.
634. Neither the name of Bigcommerce Inc. nor the
64 names of its contributors may be used to endorse or promote products
65 derived from this software without specific prior written permission.
66
67THIS SOFTWARE IS PROVIDED BY BIGCOMMERCE INC ''AS IS'' AND ANY
68EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
69WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
70DISCLAIMED. IN NO EVENT SHALL BIGCOMMERCE INC BE LIABLE FOR ANY
71DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
72(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
73LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
75(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
76SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.