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
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);

View file

@ -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) {