Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to create a custom pattern #1748

Merged
merged 8 commits into from
Nov 5, 2024
Merged
76 changes: 75 additions & 1 deletion docs/classic-ui/mockup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pip install plonecli --user
Create an add-on package with `plonecli`.

```shell
plonecli add project.addon
plonecli create addon project.addon
```

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

## Create a custom pattern

To create a custom {term}`pattern` in your add-on, use the `mockup_pattern` {term}`bobtemplate`:
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved

```shell
cd project.addon
plonecli add mockup_pattern
```

Next, enter your pattern name without the `pat-` prefix.

```shell
--> Pattern name (without “pat-” prefix) [my-pattern]: testpattern
```

This creates the necessary JavaScript resources and webpack configuration for you, as shown in the following file system tree diagram.

```text
...
├── resources
| ├── pat-testpattern
| | ├── documentation.md
| | ├── testpattern.js
| | ├── testpattern.scss
| | ├── testpattern.test.js
│ ├── bundle.js
│ ├── index.html
│ ├── index.js
├── package.json
├── webpack.config.js
...
```

All your pattern JavaScript code goes into {file}`resources/pat-testpattern/testpattern.js`.
SCSS files can be imported, too, since webpack provides the `sass-loader` module.

Next, install the npm packages using {term}`yarn`.

```shell
yarn install
```

When you finish writing your JavaScript code, you have to build the bundle with the following command.

```shell
yarn build
```

This creates the webpack chunks and the JavaScript bundle files in your add-on package.

```text
...
├── src
| ├── project
| | ├── addon
| | | ├── browser
| | | | ├── static
| | | | | ├── bundles
| | | | | | ├── chunks
| | | | | | ├── addon-remote.min.js
| | | | | | ├── addon-remote.min.js.map
| | | | | | ├── addon.min.js
| | | | | | ├── addon.min.js.map
```

Note that `plonecli` also creates an XML file in {file}`src/project/addon/profiles/default/registry/bundles.xml`, which registers the {file}`addon-remote.min.js` file in the resource registry.

```{important}
You must re-import your profile with an upgrade step if you installed your add-on in Plone before adding the pattern.
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved
```

You can test your pattern now with the browser view `@@addon-pattern-demo` (see {file}`/src/project/addon/browser/pattern-demo.pt`)
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved
Alternatively you can implement it in your own templates by adding the CSS class `pat-testpattern` to a tag.
petschki marked this conversation as resolved.
Show resolved Hide resolved


## References

Expand Down
11 changes: 11 additions & 0 deletions docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@ Mockup
Mockup provides the JavaScript stack for Classic UI.
[View Mockup's patterns](https://plone.github.io/mockup/), based on Patternslib.

bobtemplate
bobtemplates
bobtemplates.plone
`bobtemplates.plone` provides {term}`mr.bob` templates to generate packages for Plone projects.
The {term}`plonecli` command line client provides a developer-friendly interface to `bobtemplates.plone`.

mr.bob
[`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.
Additionally, it can ask you questions needed to render the structure, or provide a configuration file to answer them.

Pattern
Patterns
Patternslib
[Patterns](https://patternslib.com/), or Patternslib, is a toolkit that enables designers to build rich interactive prototypes without the need for writing any JavaScript.
Expand Down