diff --git a/src/pattern.js b/src/pattern.js index 0f3d20b2d64..77bb285b169 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -16,7 +16,7 @@ export default function Pattern(config = false) { // Hooks and Svg instance this.hooks = new Hooks(); - this.svg = new Svg(this); + Svg.prototype.hooks = this.hooks; // Data containers this.settings = {}; @@ -66,11 +66,11 @@ Pattern.prototype.draft = function() { ); }; -Pattern.prototype.render = function() { - //this.hooks.attach("preRenderSvg", this.svg); +/** Debug method, exposes debug hook */ +Part.prototype.debug = function(data) {}; - //this.hooks.attach("postRenderSvg", this.svg); - //this.hooks.attach('insertText', this.svg); +Pattern.prototype.render = function() { + this.svg = new Svg(this); return this.pack().svg.render(this); }; @@ -83,6 +83,7 @@ Pattern.prototype.on = function(hook, method) { }; Pattern.prototype.with = function(plugin) { + console.log(plugin); if (plugin.hooks) this.loadPluginHooks(plugin); if (plugin.macros) this.loadPluginMacros(plugin); diff --git a/src/svg.js b/src/svg.js index 4748f285648..61f72ca58ad 100644 --- a/src/svg.js +++ b/src/svg.js @@ -23,46 +23,27 @@ function Svg(pattern) { "http://freesewing.org/namespaces/freesewing" ); this.attributes.add("freesewing", version); - this.hooks = pattern.hooks; for (let k in hooklib) this[k] = hooklib[k]; - for (let k in pattern.hooks.all) this.hook(k, this[k]); - // Keep track of attached hooks - this.attached = { - preRenderSvg: false, - postRenderSvg: false, - insertText: false - }; + + //this.hooks was injected into the prototype by pattern + let self = this; + this.hooks.attach("preRenderSvg", self); + this.hooks.attach("postRenderSvg", self); + this.hooks.attach("insertText", self); + this.hooks.attach("debug", self); } /** Method to attach preRenderSvg hooks on */ -Svg.prototype.preRenderSvg = function() { - if (this.attached.preRenderSvg === false) { - let self = this; - this.hooks.attach("preRenderSvg", self); - this.attached.preRenderSvg = true; - this.preRenderSvg(); - } -}; +Svg.prototype.preRenderSvg = function() {}; /** Method to attach postRenderSvg hooks on */ -Svg.prototype.postRenderSvg = function() { - if (this.attached.postRenderSvg === false) { - let self = this; - this.hooks.attach("postRenderSvg", self); - this.attached.postRenderSvg = true; - this.postRenderSvg(); - } -}; +Svg.prototype.postRenderSvg = function() {}; /** Method to attach insertText hooks on */ -Svg.prototype.insertText = function(data) { - if (this.attached.inserText === false) { - let self = this; - this.hooks.attach("insertText", self); - this.attached.insertText = true; - this.insertText(data); - } -}; +Svg.prototype.insertText = function() {}; + +/** Debug method, exposes debug hook */ +Svg.prototype.debug = function() {}; /** Renders a draft object as SVG */ Svg.prototype.render = function(pattern) {