1
0
Fork 0

Revert "chore: Linting for markdown and js"

This reverts commit 1c92e0f655.
This commit is contained in:
joostdecock 2021-10-17 18:26:00 +02:00
parent 994874fa72
commit cba1ab19c8
6627 changed files with 25791 additions and 24211 deletions

View file

@ -1,8 +1,7 @@
***
---
title: Conditionally loading build-time plugins
order: 30
---------
---
You can choose to load your build-time plugin conditionally based on run-time data.
@ -21,7 +20,6 @@ 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.
@ -52,15 +50,16 @@ 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.

View file

@ -1,22 +1,19 @@
***
---
title: Plugin guide
order: 400
icons:
* logo
* plugin
for: developers
about: |
This guide shows you everything you need to know to understand plugins in FreeSewing, and create your own.
goals:
* Know about build-time plugins vs run-time plugins
* Understanding plugin structure
* Hooks and how to use them
* Using hooks without a plugin
* Using macros
***
icons:
- logo
- plugin
for: developers
about: |
This guide shows you everything you need to know to understand plugins in FreeSewing, and create your own.
goals:
- Know about build-time plugins vs run-time plugins
- Understanding plugin structure
- Hooks and how to use them
- Using hooks without a plugin
- Using macros
---
Plugins allow you to extend FreeSewing.

View file

@ -1,21 +1,21 @@
***
---
title: Hooks
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)

View file

@ -1,10 +1,9 @@
***
---
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
@ -25,3 +24,4 @@ import config from "../config"
const Pattern = new freesewing.Design(config, [plugins, gorePlugin] )
```

View file

@ -1,8 +1,7 @@
***
---
title: Loading run-time plugins
order: 40
---------
---
Run-time plugin are loaded at run time, by passing them to the `use` method of
an instatiated pattern. That method is chainable, so if you have multiple plugins
@ -23,3 +22,5 @@ const myAaron = new Aaron()
Plugins that use only hooks are typically run-time plugins
</Tip>

View file

@ -1,13 +1,12 @@
***
---
title: Macros
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:
@ -36,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:
@ -49,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>
@ -62,3 +61,4 @@ to a macro needs to be contained in a single argument.
Typically, you use a single plain object to configure the macro.
</Note>

View file

@ -1,13 +1,12 @@
***
---
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:
@ -20,6 +19,7 @@ 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.

View file

@ -1,13 +1,12 @@
***
---
title: Types of plugins
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.
@ -26,12 +25,14 @@ 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.

View file

@ -1,8 +1,7 @@
***
---
title: Using hooks more than once
order: 80
---------
---
What if you want to attach more than one method to a hook?
You could spread them over seperate plugins, but there's a better way.

View file

@ -1,10 +1,9 @@
***
---
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.
@ -18,3 +17,4 @@ pattern.on('preRender', function(svg) {
```
Congratulations, you've just made your pattern yellow.

View file

@ -1,8 +1,7 @@
***
---
title: Using hooks
order: 70
---------
---
For each hook, your plugin should provide a method that takes the relevant data
as its first argument. If data was passed when the hook was loaded, you will receive
@ -10,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:
@ -40,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>
@ -53,7 +52,8 @@ 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>