Skip to content

Commit 3eaae7b

Browse files
committed
Explain how to create a custom pattern
1 parent 04a02f1 commit 3eaae7b

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

docs/classic-ui/mockup.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pip install plonecli --user
3030
Create an add-on package with `plonecli`.
3131

3232
```shell
33-
plonecli add project.addon
33+
plonecli create addon project.addon
3434
```
3535

3636
This will create a package `project.addon`, which you can install in your Plone site.
@@ -52,6 +52,82 @@ You can check the full list of available features using the `-l` parameter:
5252
plonecli -l
5353
```
5454

55+
## Create a custom pattern
56+
57+
To create a custom pattern in your addon use the `mockup_pattern` bobtemplate:
58+
59+
```shell
60+
cd project.addon
61+
plonecli add mockup_pattern
62+
```
63+
64+
Now enter your pattern name without *pat-* prefix:
65+
66+
```shell
67+
--> Pattern name (without “pat-” prefix) [my-pattern]: testpattern
68+
```
69+
70+
This creates the necessary JS resources and webpack configuration for you:
71+
72+
```text
73+
...
74+
├── resources
75+
| ├── pat-testpattern
76+
| | ├── documentation.md
77+
| | ├── testpattern.js
78+
| | ├── testpattern.scss
79+
| | ├── testpattern.test.js
80+
│ ├── bundle.js
81+
│ ├── index.html
82+
│ ├── index.js
83+
├── package.json
84+
├── webpack.config.js
85+
...
86+
```
87+
88+
All your pattern JS code goes into `resources/pat-testpattern/testpattern.js`.
89+
SCSS files can be imported too since webpack provides the `sass-loader` module.
90+
91+
Next step is to install the npm packages (yarn recommended):
92+
93+
```shell
94+
yarn install
95+
```
96+
97+
When you have finished your JS code you have to build the bundle with:
98+
99+
```shell
100+
yarn build
101+
```
102+
103+
This creates the webpack chunks and the JS bundle files in your addon package:
104+
105+
```text
106+
...
107+
├── src
108+
| ├── project
109+
| | ├── addon
110+
| | | ├── browser
111+
| | | | ├── static
112+
| | | | | ├── bundles
113+
| | | | | | ├── chunks
114+
| | | | | | ├── addon-remote.min.js
115+
| | | | | | ├── addon-remote.min.js.map
116+
| | | | | | ├── addon.min.js
117+
| | | | | | ├── addon.min.js.map
118+
```
119+
120+
Note that `plonecli` also creates a XML file in `src/project/addon/profiles/default/registry/bundles.xml`
121+
which registers the `addon-remote.min.js` in the resources registry.
122+
123+
```{important}
124+
You have to re-import your profile with an upgrade step if you have installed
125+
your addon in Plone before adding the pattern.
126+
```
127+
128+
You can test your pattern now with the browser view `@@addon-pattern-demo` (see /src/project/addon/browser/pattern-demo.pt)
129+
or implement it in your own templates by adding the CSS class `pat-testpattern` to a tag.
130+
55131

56132
## References
57133

0 commit comments

Comments
 (0)