Refactoring code for escape display

This commit is contained in:
Jeff Avallone 2014-12-09 17:43:05 -05:00
parent cd279d3a80
commit 3bbd55c36a
2 changed files with 50 additions and 49 deletions

View File

@ -4,7 +4,5 @@ import Escape from './escape.js';
export default _.extend({}, Escape, {
type: 'charset_escape',
codeMap: _.extend({}, Escape.codeMap, {
b: 'backspace'
})
});

View File

@ -4,7 +4,26 @@ import Base from './base.js';
export default _.extend({}, Base, {
type: 'escape',
codeMap: {
code() {
return this.esc.code.textValue;
},
arg() {
return this.esc.arg.textValue;
},
render() {
this.container.addClass('escape');
this.label = this.render_label(this.container, _.result(this, this.code()));
this.label.select('rect').attr({
rx: 3,
ry: 3
});
},
// Escape code mappings
b: 'word boundary',
B: 'non-word boundary',
d: 'digit',
@ -27,38 +46,22 @@ export default _.extend({}, Base, {
7: 'Back reference (group = 7)',
8: 'Back reference (group = 8)',
9: 'Back reference (group = 9)',
0: (arg) => {
0() {
var arg = this.arg();
if (arg) {
return 'octal: ' + arg;
} else {
return 'null';
}
},
c: (arg) => {
return 'ctrl-' + arg;
c() {
return 'ctrl-' + this.arg();
},
x: (arg) => {
return '0x' + arg.toUpperCase();
x() {
return '0x' + this.arg().toUpperCase();
},
u: (arg) => {
return 'U+' + arg.toUpperCase();
}
},
render() {
var code = this.codeMap[this.esc.code.textValue];
if (_.isFunction(code)) {
code = code(this.esc.arg.textValue);
}
this.container.addClass('escape');
this.label = this.render_label(this.container, code);
this.label.select('rect').attr({
rx: 3,
ry: 3
});
u() {
return 'U+' + this.arg().toUpperCase();
}
});