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
82 changes: 81 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,86 @@ 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
In the following example, its name is `testpattern`.

```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, the JS bundle files, a demo browser view in your addon package:
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved

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

There is also a XML file in `src/project/addon/profiles/default/registry/bundles.xml` which registers the `addon-remote.min.js` in the resources registry.
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved

```{important}
You must re-import your profile with an upgrade step if you installed your add-on in Plone before adding the pattern by uninstall/install the addon in the controlpanel or writing a genericsetup upgrade step.
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved
```

You can access the demo browser view in your browser with `http://localhost:8080/Plone/@@addon-pattern-demo`
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 an HTML tag, such as an `img` tag.

```html
<img class="pat-testpattern">
```


## References

Expand Down
11 changes: 11 additions & 0 deletions docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,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