From 661e7fa6fbba0c8f6a230cd98efe812affb14816 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Thu, 23 Apr 2015 19:37:24 -0400 Subject: [PATCH] Adding documentation to root.js --- src/js/parser/javascript/root.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/js/parser/javascript/root.js b/src/js/parser/javascript/root.js index 2d57416..b7588d8 100644 --- a/src/js/parser/javascript/root.js +++ b/src/js/parser/javascript/root.js @@ -1,3 +1,6 @@ +// Root nodes contain the top-level [Regexp](./regexp.html) node. Any flags +// and a few decorative elements are rendered by the root node. + import _ from 'lodash'; export default { @@ -9,17 +12,22 @@ export default { m: 'Multiline' }, + // Renders the root into the currently set container. _render() { var flagText; + // Render a label for any flags that have been set of the expression. if (this.flags.length > 0) { flagText = this.container.text(0, 0, `Flags: ${this.flags.join(', ')}`); } + // Render the content of the regular expression. return this.regexp.render(this.container.group()) .then(() => { var box; + // Move rendered regexp to account for flag label and to allow for + // decorative elements. if (flagText) { this.regexp.transform(Snap.matrix() .translate(10, flagText.getBBox().height)); @@ -30,6 +38,7 @@ export default { box = this.regexp.getBBox(); + // Render decorative elements. this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`); this.container.circle(0, box.ay, 5); this.container.circle(box.x2 + 10, box.ay, 5); @@ -37,6 +46,7 @@ export default { }, setup() { + // Convert list of flags into text describing each flag. this.flags = _(this.properties.flags.textValue).unique().sort().map(flag => { return this.flagLabels[flag]; }).value();