chore(markdown): Linting of dev docs
This commit is contained in:
parent
1d8beedd44
commit
265ad404da
317 changed files with 1281 additions and 1503 deletions
|
@ -20,6 +20,7 @@ const condition = settings => {
|
|||
else return false // Do not load the plugin
|
||||
}
|
||||
```
|
||||
|
||||
You pass your plugin and condition method as a third parameter to the Design constructor
|
||||
with the `plugin` and `condition` keys respectively.
|
||||
|
||||
|
@ -50,16 +51,15 @@ const Pattern = new freesewing.Design(
|
|||
|
||||
Our condition method will return `true` only if the following conditions are met:
|
||||
|
||||
- A `settings` object is passed into the method
|
||||
- `settings.options` is _truthy_
|
||||
- `settings.options.draftForHighBust` is _truthy_
|
||||
- `settings.options.measurements.highBust` is _truthy_
|
||||
- A `settings` object is passed into the method
|
||||
- `settings.options` is *truthy*
|
||||
- `settings.options.draftForHighBust` is *truthy*
|
||||
- `settings.options.measurements.highBust` is *truthy*
|
||||
|
||||
This is a real-world example from our Teagan pattern. A t-shirt pattern that can be
|
||||
drafted to the high bust (rather than the full chest circumference) if the user
|
||||
drafted to the high bust (rather than the full chest circumference) if the user
|
||||
choses so.
|
||||
|
||||
But that feat is handled auto-magically by `plugin-bust` which is a build-time plugin.
|
||||
So whether to load this plugin or not hinges on the user settings, which is why we
|
||||
load this plugin conditionally.
|
||||
|
||||
|
|
|
@ -5,17 +5,16 @@ order: 60
|
|||
|
||||
A **hook** is a lifecycle event. The available hooks are:
|
||||
|
||||
- [preRender](/reference/hooks/prerender/): Called at the start of [`Pattern.render()`](/reference/api/pattern#render)
|
||||
- [postRender](/reference/hooks/postrender/): Called at the end of [`Pattern.render()`](/reference/api/pattern#render)
|
||||
- [insertText](/reference/hooks/inserttext/): Called when inserting text
|
||||
- [preDraft](/reference/hooks/predraft/): Called at the start of [`Pattern.draft()`](/reference/api/pattern#draft)
|
||||
- [postDraft](/reference/hooks/postdraft/): Called at the end of [`Pattern.draft()`](/reference/api/pattern#draft)
|
||||
- [preSample](/reference/hooks/presample/): Called at the start of [`Pattern.sample()`](/reference/api/pattern#sample)
|
||||
- [postSample](/reference/hooks/postsample/): Called at the end of [`Pattern.sample()`](/reference/api/pattern#sample)
|
||||
- [preRender](/reference/hooks/prerender/): Called at the start of [`Pattern.render()`](/reference/api/pattern#render)
|
||||
- [postRender](/reference/hooks/postrender/): Called at the end of [`Pattern.render()`](/reference/api/pattern#render)
|
||||
- [insertText](/reference/hooks/inserttext/): Called when inserting text
|
||||
- [preDraft](/reference/hooks/predraft/): Called at the start of [`Pattern.draft()`](/reference/api/pattern#draft)
|
||||
- [postDraft](/reference/hooks/postdraft/): Called at the end of [`Pattern.draft()`](/reference/api/pattern#draft)
|
||||
- [preSample](/reference/hooks/presample/): Called at the start of [`Pattern.sample()`](/reference/api/pattern#sample)
|
||||
- [postSample](/reference/hooks/postsample/): Called at the end of [`Pattern.sample()`](/reference/api/pattern#sample)
|
||||
|
||||
You can register a method for a hook. When the hook is triggered, your method will be
|
||||
called. It will receive two parameters:
|
||||
|
||||
- An object relevant to the hook. See the [hooks API reference](/reference/hooks/) for details.
|
||||
- Data passed when the hook was registered (optional)
|
||||
|
||||
- An object relevant to the hook. See the [hooks API reference](/reference/hooks/) for details.
|
||||
- Data passed when the hook was registered (optional)
|
||||
|
|
|
@ -3,7 +3,7 @@ title: Loading build-time plugins
|
|||
order: 20
|
||||
---
|
||||
|
||||
Build-time plugins are loaded at build time, by passing them to
|
||||
Build-time plugins are loaded at build time, by passing them to
|
||||
the [`freesewing.Design`](/reference/api/#design) constructor:
|
||||
|
||||
```js
|
||||
|
@ -24,4 +24,3 @@ import config from "../config"
|
|||
|
||||
const Pattern = new freesewing.Design(config, [plugins, gorePlugin] )
|
||||
```
|
||||
|
||||
|
|
|
@ -22,5 +22,3 @@ const myAaron = new Aaron()
|
|||
Plugins that use only hooks are typically run-time plugins
|
||||
|
||||
</Tip>
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ order: 90
|
|||
|
||||
Plugin structure for macros is similar, with a few changes:
|
||||
|
||||
- Rather than the hook name, you provide the macro name (that you choose yourself)
|
||||
- The context (`this`) of a macro method is **always** a [Part](/reference/api/part) object.
|
||||
- Rather than the hook name, you provide the macro name (that you choose yourself)
|
||||
- The context (`this`) of a macro method is **always** a [Part](/reference/api/part) object.
|
||||
|
||||
Apart from these, the structure is very similar:
|
||||
|
||||
|
@ -35,7 +35,7 @@ export default {
|
|||
}
|
||||
```
|
||||
|
||||
Did you figure out what this plugin does?
|
||||
Did you figure out what this plugin does?
|
||||
It provides a `box` macro that draws a box on our pattern in a given location with a give size.
|
||||
|
||||
We can use it like this:
|
||||
|
@ -48,7 +48,7 @@ macro('box', {
|
|||
});
|
||||
```
|
||||
|
||||
Obviously, you can expect to learn how to call a macro in its documentation,
|
||||
Obviously, you can expect to learn how to call a macro in its documentation,
|
||||
rather than have to comb through its code.
|
||||
|
||||
<Note>
|
||||
|
@ -61,4 +61,3 @@ to a macro needs to be contained in a single argument.
|
|||
Typically, you use a single plain object to configure the macro.
|
||||
|
||||
</Note>
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ title: Plugin structure
|
|||
order: 50
|
||||
---
|
||||
|
||||
Plugins can do two things:
|
||||
Plugins can do two things:
|
||||
|
||||
- They can use hooks
|
||||
- They can provide macros
|
||||
- They can use hooks
|
||||
- They can provide macros
|
||||
|
||||
Your plugin should export an object with the following structure:
|
||||
|
||||
|
@ -19,7 +19,6 @@ Your plugin should export an object with the following structure:
|
|||
};
|
||||
```
|
||||
|
||||
The `name` and `version` attributes are self-explanatory.
|
||||
The `name` and `version` attributes are self-explanatory.
|
||||
The [hooks](/guides/plugins/hooks/) and [macros](/guides/plugins/macros/) sections
|
||||
explain the `hooks` and `macros` properties.
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ order: 10
|
|||
|
||||
Plugins come in two flavours:
|
||||
|
||||
- [Build-time plugins](#build-time-plugins)
|
||||
- [Run-time plugins](#run-time-plugins)
|
||||
- [Build-time plugins](#build-time-plugins)
|
||||
- [Run-time plugins](#run-time-plugins)
|
||||
|
||||
When writing a plugin, ask yourself whether it's a run-time or a build-time plugin.
|
||||
And if the answer is both, please split them into two plugins.
|
||||
|
@ -25,14 +25,12 @@ Our [plugin bundle](/reference/plugins/bundle/) bundles build-time plugins that
|
|||
|
||||
<Note>Plugins that provide a macro are typically build-time plugins</Note>
|
||||
|
||||
|
||||
## Run-time plugins
|
||||
|
||||
A plugin is a run-time plugin if it can be added after instantiating your pattern.
|
||||
Think of it as a plugin to be used in the front-end.
|
||||
|
||||
Run-time plugins are not a dependecy of the pattern. They just _add something_ to it.
|
||||
Run-time plugins are not a dependecy of the pattern. They just *add something* to it.
|
||||
|
||||
Our [theme plugin](/reference/plugins/theme/) is a good example of a run-time plugin.
|
||||
If it's missing, your pattern will still work, it just won't look pretty.
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ title: Using hooks without a plugin
|
|||
order: 85
|
||||
---
|
||||
|
||||
You can attach a method to a hook at run-time without the need for a plugin
|
||||
You can attach a method to a hook at run-time without the need for a plugin
|
||||
using the [Pattern.on()](/reference/api/pattern/on) method.
|
||||
|
||||
The method takes the hook name as its first argument, and the hook method as its second.
|
||||
|
@ -17,4 +17,3 @@ pattern.on('preRender', function(svg) {
|
|||
```
|
||||
|
||||
Congratulations, you've just made your pattern yellow.
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ that as the second object.
|
|||
|
||||
Remember that:
|
||||
|
||||
- The `insertText` hook will receive a locale and string and you should return a string.
|
||||
- All other hooks receive an object. You don't need to return anything, but rather modify the object you receive.
|
||||
- The `insertText` hook will receive a locale and string and you should return a string.
|
||||
- All other hooks receive an object. You don't need to return anything, but rather modify the object you receive.
|
||||
|
||||
Let's look at an example:
|
||||
|
||||
|
@ -39,8 +39,8 @@ export default {
|
|||
|
||||
This is a complete plugin, ready to be published on NPM. It uses two hooks:
|
||||
|
||||
- `preRender` : We add some style and defs to our SVG
|
||||
- `insertText` : We transfer all text to UPPERCASE
|
||||
- `preRender` : We add some style and defs to our SVG
|
||||
- `insertText` : We transfer all text to UPPERCASE
|
||||
|
||||
<Note>
|
||||
|
||||
|
@ -52,8 +52,7 @@ the SVG tag with the name and version of our plugin.
|
|||
We check for this attribute when the `preRender` hook runs, thereby avoiding that
|
||||
our styles and defs will be added twice.
|
||||
|
||||
It is good practice to wrap you hook methods in a call like this, because you have
|
||||
It is good practice to wrap you hook methods in a call like this, because you have
|
||||
no guarantee the user won't render your pattern more than once.
|
||||
|
||||
</Note>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue