🚧 repo move to freesewing org
This commit is contained in:
parent
27500d52e1
commit
014eee3209
2 changed files with 23 additions and 11 deletions
|
@ -1,5 +1,7 @@
|
|||
import { macroName } from "./utils";
|
||||
import point from "./point";
|
||||
import path from "./path";
|
||||
import snippet from "./snippet";
|
||||
import attributes from "./attributes";
|
||||
import * as hooklib from "hooks";
|
||||
|
||||
|
@ -13,6 +15,11 @@ function part(id) {
|
|||
this.points.origin = new point(0, 0);
|
||||
for (let k in hooklib) this[k] = hooklib[k];
|
||||
|
||||
// Constructors so macros can create objects
|
||||
this.point = point;
|
||||
this.path = path;
|
||||
this.snippet = snippet;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -23,6 +30,8 @@ part.prototype.macroRunner = function(args) {
|
|||
let macro = macroName(key);
|
||||
if (typeof self[macro] === "function") {
|
||||
self[macro](data);
|
||||
} else {
|
||||
console.log(`Warning: ${macro} is not registered`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -83,17 +83,7 @@ pattern.prototype.on = function(hook, method) {
|
|||
this.hooks._hooks[hook].push(method);
|
||||
};
|
||||
|
||||
pattern.prototype.macro = function(key, method) {
|
||||
let name = macroName(key);
|
||||
this.on(name, method);
|
||||
for (let partId in this.parts) {
|
||||
let part = this.parts[partId];
|
||||
part[name] = () => null;
|
||||
this.hooks.attach(name, part);
|
||||
}
|
||||
};
|
||||
|
||||
pattern.prototype.withPlugin = function(plugin) {
|
||||
pattern.prototype.with = function(plugin) {
|
||||
if (plugin.hooks) this.loadPluginHooks(plugin);
|
||||
if (plugin.macros) this.loadPluginMacros(plugin);
|
||||
|
||||
|
@ -110,8 +100,21 @@ pattern.prototype.loadPluginHooks = function(plugin) {
|
|||
|
||||
pattern.prototype.loadPluginMacros = function(plugin) {
|
||||
for (let macro in plugin.macros) {
|
||||
console.log("loading ", macro);
|
||||
if (typeof plugin.macros[macro] === "function") {
|
||||
console.log(macro, "is a function");
|
||||
this.macro(macro, plugin.macros[macro]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pattern.prototype.macro = function(key, method) {
|
||||
let name = macroName(key);
|
||||
this.on(name, method);
|
||||
for (let partId in this.parts) {
|
||||
console.log(`Attaching macro ${name} to part ${partId}`);
|
||||
let part = this.parts[partId];
|
||||
part[name] = () => null;
|
||||
this.hooks.attach(name, part);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue