2014-11-30 22:54:12 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
|
|
|
export default _.extend({}, Base, {
|
2014-12-03 01:10:56 +00:00
|
|
|
type: 'match',
|
2014-12-03 02:02:48 +00:00
|
|
|
|
2014-12-03 23:59:59 +00:00
|
|
|
render() {
|
2014-12-03 02:02:48 +00:00
|
|
|
this.contents = {};
|
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
if (this.anchorStart()) {
|
|
|
|
this.contents.anchor_start = this.renderLabel(this.container, 'Start of line')
|
2014-12-04 01:20:08 +00:00
|
|
|
.addClass('anchor');
|
2014-12-03 02:02:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 22:01:21 +00:00
|
|
|
this.contents.parts = _.map(this.parts(), (function(part) {
|
|
|
|
part.setContainer(this.container.group());
|
2014-12-03 23:59:59 +00:00
|
|
|
part.render();
|
|
|
|
return part;
|
2014-12-10 22:01:21 +00:00
|
|
|
}).bind(this));
|
2014-12-03 02:02:48 +00:00
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
if (this.anchorEnd()) {
|
|
|
|
this.contents.anchor_end = this.renderLabel(this.container, 'End of line')
|
2014-12-04 01:20:08 +00:00
|
|
|
.addClass('anchor');
|
2014-12-03 02:02:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
position() {
|
2014-12-10 22:09:18 +00:00
|
|
|
var items;
|
2014-12-03 02:02:48 +00:00
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
if (this.anchorStart()) {
|
|
|
|
this.positionLabel(this.contents.anchor_start);
|
2014-12-03 02:02:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
if (this.anchorEnd()) {
|
|
|
|
this.positionLabel(this.contents.anchor_end);
|
2014-12-03 02:02:48 +00:00
|
|
|
}
|
2014-12-04 01:26:09 +00:00
|
|
|
|
2014-12-10 00:02:31 +00:00
|
|
|
_.invoke(this.contents.parts, 'position');
|
|
|
|
|
|
|
|
items = _(this.contents).values().flatten().value();
|
|
|
|
this.spaceHorizontally(items, {
|
|
|
|
padding: 10
|
|
|
|
});
|
2014-12-03 02:02:48 +00:00
|
|
|
},
|
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
anchorStart() {
|
2014-12-03 02:02:48 +00:00
|
|
|
return this._anchor_start.textValue !== '';
|
|
|
|
},
|
|
|
|
|
2014-12-09 23:08:40 +00:00
|
|
|
anchorEnd() {
|
2014-12-03 02:02:48 +00:00
|
|
|
return this._anchor_end.textValue !== '';
|
|
|
|
},
|
|
|
|
|
|
|
|
parts() {
|
|
|
|
return _.reduce(this._parts.elements, function(result, node) {
|
|
|
|
var last = result.pop();
|
|
|
|
|
|
|
|
if (last) {
|
2014-12-06 21:03:58 +00:00
|
|
|
if (node.elements[0].type === 'literal' && node.elements[1].textValue === '' && last.elements[0].type === 'literal' && last.elements[1].textValue === '') {
|
2014-12-03 02:09:20 +00:00
|
|
|
last = _.clone(last, true);
|
2014-12-03 02:02:48 +00:00
|
|
|
last.textValue += node.textValue;
|
|
|
|
last.elements[0].textValue += node.elements[0].textValue;
|
2014-12-06 21:03:58 +00:00
|
|
|
last.elements[0].literal.textValue += node.elements[0].literal.textValue;
|
2014-12-03 02:02:48 +00:00
|
|
|
last.elements[1] = node.elements[1];
|
|
|
|
node = last;
|
|
|
|
} else {
|
|
|
|
result.push(last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 02:09:20 +00:00
|
|
|
result.push(node);
|
2014-12-03 02:02:48 +00:00
|
|
|
return result;
|
|
|
|
}, []);
|
|
|
|
}
|
2014-11-30 22:54:12 +00:00
|
|
|
});
|