diff --git a/src/part.js b/src/part.js index 7fb8426c1a0..b4bd2cf4eee 100644 --- a/src/part.js +++ b/src/part.js @@ -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`); } }; diff --git a/src/pattern.js b/src/pattern.js index 4d77d2dd672..abb7a526772 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -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); + } +};