Skip to content

Commit 472d9bd

Browse files
Explain how to create a custom pattern (#1748)
* Explain how to create a custom pattern * Tidy up mockup.md. - Add more glossary terms and references. * Provide clarification of HTML tag * update info for pattern demo browser view * Apply suggestions from code review --------- Co-authored-by: Steve Piercy <web@stevepiercy.com>
1 parent a0b6e18 commit 472d9bd

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

docs/classic-ui/mockup.md

Lines changed: 83 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,88 @@ 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 {term}`pattern` in your add-on, use the `mockup_pattern` {term}`bobtemplate`.
58+
59+
```shell
60+
cd project.addon
61+
plonecli add mockup_pattern
62+
```
63+
64+
Next, enter your pattern name without the `pat-` prefix
65+
In the following example, its name is `testpattern`.
66+
67+
```shell
68+
--> Pattern name (without “pat-” prefix) [my-pattern]: testpattern
69+
```
70+
71+
This creates the necessary JavaScript resources and webpack configuration for you, as shown in the following file system tree diagram.
72+
73+
```text
74+
...
75+
├── resources
76+
| ├── pat-testpattern
77+
| | ├── documentation.md
78+
| | ├── testpattern.js
79+
| | ├── testpattern.scss
80+
| | ├── testpattern.test.js
81+
│ ├── bundle.js
82+
│ ├── index.html
83+
│ ├── index.js
84+
├── package.json
85+
├── webpack.config.js
86+
...
87+
```
88+
89+
All your pattern JavaScript code goes into {file}`resources/pat-testpattern/testpattern.js`.
90+
SCSS files can be imported, too, since webpack provides the `sass-loader` module.
91+
92+
Next, install the npm packages using {term}`yarn`.
93+
94+
```shell
95+
yarn install
96+
```
97+
98+
When you finish writing your JavaScript code, you have to build the bundle with the following command.
99+
100+
```shell
101+
yarn build
102+
```
103+
104+
This creates the webpack chunks, the JavaScript bundle files, and a demo browser view in your add-on package.
105+
106+
```text
107+
...
108+
├── src
109+
| ├── project
110+
| | ├── addon
111+
| | | ├── browser
112+
| | | | ├── static
113+
| | | | | ├── bundles
114+
| | | | | | ├── chunks
115+
| | | | | | ├── addon-remote.min.js
116+
| | | | | | ├── addon-remote.min.js.map
117+
| | | | | | ├── addon.min.js
118+
| | | | | | ├── addon.min.js.map
119+
| | | | ├── pattern-demo.pt
120+
```
121+
122+
There is also an XML file in {file}`src/project/addon/profiles/default/registry/bundles.xml` which registers the {file}`addon-remote.min.js` in the resources registry.
123+
124+
```{important}
125+
You must re-import your profile with an upgrade step if you installed your add-on in Plone before adding the pattern.
126+
Uninstall, then re-install, the add-on in the control panel.
127+
Alternatively you can write a GenericSetup upgrade step.
128+
```
129+
130+
You can access the demo browser view in your browser with `http://localhost:8080/Plone/@@addon-pattern-demo`.
131+
Alternatively you can implement it in your own templates by adding the CSS class `pat-testpattern` to an HTML tag, such as an `img` tag.
132+
133+
```html
134+
<img class="pat-testpattern">
135+
```
136+
55137

56138
## References
57139

docs/glossary.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,17 @@ Mockup
441441
Mockup provides the JavaScript stack for Classic UI.
442442
[View Mockup's patterns](https://plone.github.io/mockup/), based on Patternslib.
443443
444+
bobtemplate
445+
bobtemplates
446+
bobtemplates.plone
447+
`bobtemplates.plone` provides {term}`mr.bob` templates to generate packages for Plone projects.
448+
The {term}`plonecli` command line client provides a developer-friendly interface to `bobtemplates.plone`.
449+
450+
mr.bob
451+
[`mr.bob`](https://mrbob.readthedocs.io/en/latest/) is a tool that takes a directory skeleton, copies over its directory structure to a target folder, and can use the Jinja2 (or some other) templating engine to dynamically generate the files.
452+
Additionally, it can ask you questions needed to render the structure, or provide a configuration file to answer them.
453+
454+
Pattern
444455
Patterns
445456
Patternslib
446457
[Patterns](https://patternslib.com/), or Patternslib, is a toolkit that enables designers to build rich interactive prototypes without the need for writing any JavaScript.

0 commit comments

Comments
 (0)