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
|
5 | out to [paper-handlebars](https://github.com/bigcommerce/paper-handlebars) to render pages.
|
6 |
|
7 | ## Usage
|
8 | Load Paper into your app:
|
9 | ```
|
10 | const Paper = require('@bigcommerce/stencil-paper');
|
11 | ```
|
12 |
|
13 | Instatiate paper passing `siteSettings`, `themeSettings`, `assembler`, and an optional `logger` (overriding the default logger):
|
14 | ```
|
15 | const paper = new Paper(siteSettings, themeSettings, assembler, logger);
|
16 | ```
|
17 |
|
18 | The `assembler` is the interface that Paper uses to load the templates and translations. This way we can use paper to load the templates
|
19 | from the file system or any other source. It's just an object that implements two methods: `getTemplates()` & `getTranslations()`:
|
20 | ```
|
21 | const 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 |
|
37 | Now we can load the theme for the page we want to render:
|
38 | ```
|
39 | paper.loadTheme(path, 'en').then(() => {
|
40 | paper.render(path, context).then(html => {
|
41 | reply(html);
|
42 | });
|
43 | });
|
44 | ```
|
45 |
|
46 | ## Helpers Reference
|
47 | See the [stencil API reference](https://developer.bigcommerce.com/stencil-docs/reference-docs/handlebars-helpers-reference) for documentation on the available helpers.
|
48 |
|
49 | #### License
|
50 | Copyright (c) 2015-2022, Bigcommerce Inc.
|
51 | All rights reserved.
|
52 |
|
53 | Redistribution and use in source and binary forms, with or without
|
54 | modification, are permitted provided that the following conditions are met:
|
55 | 1. Redistributions of source code must retain the above copyright
|
56 | notice, this list of conditions and the following disclaimer.
|
57 | 2. 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.
|
60 | 3. 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.
|
63 | 4. 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 |
|
67 | THIS SOFTWARE IS PROVIDED BY BIGCOMMERCE INC ''AS IS'' AND ANY
|
68 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
69 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
70 | DISCLAIMED. IN NO EVENT SHALL BIGCOMMERCE INC BE LIABLE FOR ANY
|
71 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
72 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
73 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
74 | ON 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
|
76 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|