1
0
Fork 0

🚧 Working on debug

This commit is contained in:
Joost De Cock 2018-08-07 15:23:37 +02:00
parent 014450835a
commit ff9b561233
2 changed files with 19 additions and 37 deletions

View file

@ -16,7 +16,7 @@ export default function Pattern(config = false) {
// Hooks and Svg instance // Hooks and Svg instance
this.hooks = new Hooks(); this.hooks = new Hooks();
this.svg = new Svg(this); Svg.prototype.hooks = this.hooks;
// Data containers // Data containers
this.settings = {}; this.settings = {};
@ -66,11 +66,11 @@ Pattern.prototype.draft = function() {
); );
}; };
Pattern.prototype.render = function() { /** Debug method, exposes debug hook */
//this.hooks.attach("preRenderSvg", this.svg); Part.prototype.debug = function(data) {};
//this.hooks.attach("postRenderSvg", this.svg); Pattern.prototype.render = function() {
//this.hooks.attach('insertText', this.svg); this.svg = new Svg(this);
return this.pack().svg.render(this); return this.pack().svg.render(this);
}; };
@ -83,6 +83,7 @@ Pattern.prototype.on = function(hook, method) {
}; };
Pattern.prototype.with = function(plugin) { Pattern.prototype.with = function(plugin) {
console.log(plugin);
if (plugin.hooks) this.loadPluginHooks(plugin); if (plugin.hooks) this.loadPluginHooks(plugin);
if (plugin.macros) this.loadPluginMacros(plugin); if (plugin.macros) this.loadPluginMacros(plugin);

View file

@ -23,46 +23,27 @@ function Svg(pattern) {
"http://freesewing.org/namespaces/freesewing" "http://freesewing.org/namespaces/freesewing"
); );
this.attributes.add("freesewing", version); this.attributes.add("freesewing", version);
this.hooks = pattern.hooks;
for (let k in hooklib) this[k] = hooklib[k]; 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.hooks was injected into the prototype by pattern
this.attached = { let self = this;
preRenderSvg: false, this.hooks.attach("preRenderSvg", self);
postRenderSvg: false, this.hooks.attach("postRenderSvg", self);
insertText: false this.hooks.attach("insertText", self);
}; this.hooks.attach("debug", self);
} }
/** Method to attach preRenderSvg hooks on */ /** Method to attach preRenderSvg hooks on */
Svg.prototype.preRenderSvg = function() { Svg.prototype.preRenderSvg = function() {};
if (this.attached.preRenderSvg === false) {
let self = this;
this.hooks.attach("preRenderSvg", self);
this.attached.preRenderSvg = true;
this.preRenderSvg();
}
};
/** Method to attach postRenderSvg hooks on */ /** Method to attach postRenderSvg hooks on */
Svg.prototype.postRenderSvg = function() { Svg.prototype.postRenderSvg = function() {};
if (this.attached.postRenderSvg === false) {
let self = this;
this.hooks.attach("postRenderSvg", self);
this.attached.postRenderSvg = true;
this.postRenderSvg();
}
};
/** Method to attach insertText hooks on */ /** Method to attach insertText hooks on */
Svg.prototype.insertText = function(data) { Svg.prototype.insertText = function() {};
if (this.attached.inserText === false) {
let self = this; /** Debug method, exposes debug hook */
this.hooks.attach("insertText", self); Svg.prototype.debug = function() {};
this.attached.insertText = true;
this.insertText(data);
}
};
/** Renders a draft object as SVG */ /** Renders a draft object as SVG */
Svg.prototype.render = function(pattern) { Svg.prototype.render = function(pattern) {