UNPKG

@atomist/rug

Version:

TypeScript model for Atomist Rugs, see http://docs.atomist.com/

64 lines (63 loc) 2.86 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var DecoratingPathExpressionEngine_1 = require("../DecoratingPathExpressionEngine"); var helper = require("../../tree/TreeHelper"); var yaml = require("./Types"); /** * PathExpressionEngine decorator that returns Yaml type mixins for value nodes. */ var YamlPathExpressionEngine = (function (_super) { __extends(YamlPathExpressionEngine, _super); function YamlPathExpressionEngine() { return _super !== null && _super.apply(this, arguments) || this; } YamlPathExpressionEngine.prototype.decoratorFor = function (n) { if (n.value) { var ttn = n; // console.log(`Decorating [${n}] with tags [${n.nodeTags()}]`) if (helper.hasTag(n, "Scalar")) { switch (ttn.value().charAt(0)) { case '"': return new yaml.YamlQuotedValue(ttn); case ">": switch (ttn.value().charAt(1)) { case "-": return new yaml.YamlFoldedBlockWithStripChomping(ttn); case "+": return new yaml.YamlFoldedBlockWithKeepChomping(ttn); default: return new yaml.YamlFoldedBlockScalar(ttn); } case "|": switch (ttn.value().charAt(1)) { case "-": return new yaml.YamlLiteralBlockWithStripChomping(ttn); case "+": return new yaml.YamlLiteralBlockWithKeepChomping(ttn); default: return new yaml.YamlLiteralBlockScalar(ttn); } default: return new yaml.YamlRawValue(ttn); } } else if (helper.hasTag(n, "Sequence")) { return new yaml.YamlSequenceOps(ttn); } } // If we didn't match anything return null; }; return YamlPathExpressionEngine; }(DecoratingPathExpressionEngine_1.DecoratingPathExpressionEngine)); exports.YamlPathExpressionEngine = YamlPathExpressionEngine;