1
0
Fork 0

feat: Flat import of markdown repo

This is a flat (without history) import of (some of) the content
from our markdown module.

We've imported this without history because the repo contains our
blog posts and showcases posts content prior to porting them to strapi.

Since this contains many images, it would balloon the size of this repo
to import the full history.

Instead, please refer to the history of the (archived) markdown repo
at: https://github.com/freesewing/markdown
This commit is contained in:
Joost De Cock 2021-08-25 16:09:31 +02:00
parent 1671a896b5
commit b34a2ee2ed
6132 changed files with 244167 additions and 0 deletions

View file

@ -0,0 +1,65 @@
---
title: Conditionally loading build-time plugins
order: 30
---
You can choose to load your build-time plugin conditionally based on run-time data.
To do so, you need to create a `condition` method that will determine whether the
plugin will be loaded. This method receives the complete settings object and should
return `true` if the plugin is to be loaded, and `false` if it should not be loaded.
```js
const condition = settings => {
if (settings) {
// Remember, settings contains:
// settings.options => The user's options
// settings.measurements => The measurements
return true // Load the plugin
}
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.
Let's look at a complete example to illustrate this:
```js
import freesewing from '@freesewing/core'
import plugins from '@freesewing/plugin-bundle'
import myConditionalPlugin from '@freesewing/plugin-bust'
const myConditionalPluginCheck = (settings = false) =>
settings &&
settings.options &&
settings.options.draftForHighBust &&
settings.measurements.highBust
? true
: false
const Pattern = new freesewing.Design(
config,
plugins,
{
plugin: myConditionalPlugin,
condition: myConditionalPluginCheck
}
)
```
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_
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
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.