feat(markdown): Ported code howtos to v3
This commit is contained in:
parent
d1edf93750
commit
af99d3e8c0
25 changed files with 451 additions and 636 deletions
|
@ -1,42 +1,29 @@
|
|||
---
|
||||
title: Adding pattern parts
|
||||
for: developers
|
||||
about: Shows you how to add new parts to your pattern
|
||||
---
|
||||
|
||||
Since the patterns parts are listed
|
||||
in [the configuration file](/reference/api/config/), freesewing knows about
|
||||
all the parts that belong to your pattern.
|
||||
Parts can be added to the design add build time, by passing them to [the Design
|
||||
constructor](/reference/api/design), or at runtime by calling
|
||||
[Pattern.addPart()](/reference/api/pattern/addpart). The latter approach is
|
||||
rarely used, but it's there if you need it.
|
||||
|
||||
It expects that each pattern has its own draft method, that is called `draft`
|
||||
followed by the capitalized name of the pattern part.
|
||||
## At build time
|
||||
|
||||
For example, if our pattern `Sorcha` has a part called `back`, you should
|
||||
have a `draftBack` method. It's good practice to keep each part in its own
|
||||
file, so create a file called `back.js`. Inside, you export your method
|
||||
to draft this part:
|
||||
```mjs
|
||||
import { Design } from '@freesewing/core'
|
||||
import { myPart } from './mypart.mjs'
|
||||
|
||||
```js
|
||||
export default part => {
|
||||
// Your part code here
|
||||
|
||||
return part
|
||||
}
|
||||
const Sorcha = new Design({
|
||||
parts: [ myPart ]
|
||||
})
|
||||
```
|
||||
|
||||
Then, in your `index.js` file, you import this file, and attach the
|
||||
method to your pattern's prototype:
|
||||
## At run time
|
||||
|
||||
```js
|
||||
import freesewing from "freesewing"
|
||||
import plugins from "@freesewing/plugin-bundle"
|
||||
import config from "../config"
|
||||
// Parts
|
||||
import draftBack from "./back"
|
||||
```mjs
|
||||
import { Aaron } from '@freesewing/aaron'
|
||||
import { myRuntimePart } from './mypart.mjs'
|
||||
|
||||
// Create new design
|
||||
const Sorcha = new freesewing.Design(config, plugins)
|
||||
|
||||
// Attach to pattern prototype
|
||||
Sorcha.prototype.draftBack = part => draftBack(part)
|
||||
const pattern = new Aaron()
|
||||
pattern.addPart(myRuntimePart)
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue