Simplifying code related to passing rendering through to nested node

This commit is contained in:
Jeff Avallone 2014-12-10 19:01:57 -05:00
parent ff7525a6e4
commit f0c25dfc41
11 changed files with 115 additions and 113 deletions

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'any-character', type: 'any-character',
render() { _render() {
this.label = this.renderLabel(this.container, 'any character'); this.label = this.renderLabel(this.container, 'any character');
} }
}); });

View File

@ -39,6 +39,24 @@ export default {
}, },
render() { render() {
this._render();
},
position() {
if (this._proxy) {
this._proxy.position();
} else {
this._position();
}
},
proxy(node) {
this._proxy = node;
this._proxy.setContainer(this.container);
this._proxy.render();
},
_render() {
console.log(this); console.log(this);
this.container.addClass('placeholder'); this.container.addClass('placeholder');
@ -51,7 +69,7 @@ export default {
}); });
}, },
position() { _position() {
this.positionLabel(this.label); this.positionLabel(this.label);
}, },

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'charset', type: 'charset',
render() { _render() {
this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:'); this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:');
this.partContainer = this.container.group(); this.partContainer = this.container.group();
@ -15,7 +15,7 @@ export default _.extend({}, Base, {
}).bind(this)); }).bind(this));
}, },
position() { _position() {
_.invoke(this.parts.elements, 'position'); _.invoke(this.parts.elements, 'position');
this.spaceVertically(this.parts.elements, { this.spaceVertically(this.parts.elements, {

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'charset-range', type: 'charset-range',
render() { _render() {
this.first.setContainer(this.container.group()); this.first.setContainer(this.container.group());
this.first.render(); this.first.render();
@ -17,7 +17,7 @@ export default _.extend({}, Base, {
}); });
}, },
position() { _position() {
var box; var box;
this.first.position(); this.first.position();

View File

@ -12,7 +12,7 @@ export default _.extend({}, Base, {
return this.esc.arg.textValue; return this.esc.arg.textValue;
}, },
render() { _render() {
this.label = this.renderLabel(this.container, _.result(this, this.code())); this.label = this.renderLabel(this.container, _.result(this, this.code()));
this.label.select('rect').attr({ this.label.select('rect').attr({

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'literal', type: 'literal',
render() { _render() {
this.label = this.renderLabel(this.container, '"' + this.literal.textValue + '"'); this.label = this.renderLabel(this.container, '"' + this.literal.textValue + '"');
this.label.select('rect').attr({ this.label.select('rect').attr({

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'match', type: 'match',
render() { _render() {
var parts = this.parts(); var parts = this.parts();
if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) { if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) {
@ -26,16 +26,13 @@ export default _.extend({}, Base, {
.addClass('anchor'); .addClass('anchor');
} }
} else { } else {
this.content = parts[0]; this.proxy(parts[0]);
this.content.setContainer(this.container);
this.content.render();
} }
}, },
position() { _position() {
var items; var items;
if (this.contents) {
if (this.contents.anchor_start) { if (this.contents.anchor_start) {
this.positionLabel(this.contents.anchor_start); this.positionLabel(this.contents.anchor_start);
} }
@ -50,9 +47,6 @@ export default _.extend({}, Base, {
this.spaceHorizontally(items, { this.spaceHorizontally(items, {
padding: 10 padding: 10
}); });
} else {
this.content.position();
}
}, },
anchorStart() { anchorStart() {

View File

@ -4,21 +4,19 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'match-fragment', type: 'match-fragment',
render() { _render() {
if (this._repeat.textValue === '') { if (this._repeat.textValue === '') {
this._content.setContainer(this.container); this.proxy(this._content);
} else { } else {
this._content.setContainer(this.container.group()); this._content.setContainer(this.container.group());
}
this._content.render(); this._content.render();
}
}, },
position() { _position() {
var box, paths = []; var box, paths = [];
this._content.position(); this._content.position();
if (this._repeat.textValue !== '') {
this._content.container.transform(this._repeat.contentPosition()); this._content.container.transform(this._repeat.contentPosition());
box = this._content.getBBox(); box = this._content.getBBox();
@ -40,5 +38,4 @@ export default _.extend({}, Base, {
this.container.path(paths.join('')); this.container.path(paths.join(''));
} }
} }
}
}); });

View File

@ -4,12 +4,11 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'regexp', type: 'regexp',
render() { _render() {
var matches = this.matches(); var matches = this.matches();
if (matches.length === 1) { if (matches.length === 1) {
matches[0].setContainer(this.container); this.proxy(matches[0]);
matches[0].render();
} else { } else {
this.matchContainer = this.container.group() this.matchContainer = this.container.group()
.addClass('regexp-matches'); .addClass('regexp-matches');
@ -22,15 +21,13 @@ export default _.extend({}, Base, {
} }
}, },
position() { _position() {
var matches = this.matches(), var matches = this.matches(),
includeLines = (matches.length > 1),
containerBox, containerBox,
paths; paths;
_.invoke(matches, 'position'); _.invoke(matches, 'position');
if (includeLines) {
this.spaceVertically(matches, { this.spaceVertically(matches, {
padding: 5 padding: 5
}); });
@ -81,7 +78,6 @@ export default _.extend({}, Base, {
})); }));
this.container.prepend(this.container.path(paths.join(''))); this.container.prepend(this.container.path(paths.join('')));
}
}, },
matches() { matches() {

View File

@ -4,7 +4,7 @@ import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'root', type: 'root',
render() { _render() {
this.regexp.setContainer(this.container.group().transform(Snap.matrix() this.regexp.setContainer(this.container.group().transform(Snap.matrix()
.translate(10, 0))); .translate(10, 0)));
this.regexp.render(); this.regexp.render();
@ -17,7 +17,7 @@ export default _.extend({}, Base, {
.attr({ r: 5 }); .attr({ r: 5 });
}, },
position() { _position() {
var contentBox; var contentBox;
this.regexp.position(); this.regexp.position();

View File

@ -12,7 +12,7 @@ export default _.extend({}, Base, {
'?!': 'negative lookahead' '?!': 'negative lookahead'
}, },
render() { _render() {
var label = this.groupLabel(); var label = this.groupLabel();
if (label) { if (label) {
@ -21,19 +21,16 @@ export default _.extend({}, Base, {
this.regexp.setContainer(this.container.group()); this.regexp.setContainer(this.container.group());
this.regexp.render(); this.regexp.render();
} else { } else {
this.regexp.setContainer(this.container); this.proxy(this.regexp);
this.regexp.render();
} }
}, },
position() { _position() {
this.regexp.position(); this.regexp.position();
if (this.groupLabel()) {
this.positionLabeledBox(this.regexp.container, { this.positionLabeledBox(this.regexp.container, {
padding: 10 padding: 10
}); });
}
}, },
groupLabel() { groupLabel() {