How to use the yaml.eval function in yaml

To help you get started, we’ve selected a few yaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhiokim / haroopress / bin / convert / octopress.js View on Github external
function parseHead(str) {
    var header;

    header = str.split('\n');
    header.shift();
    header.pop();
    header = header.map(function(line) {
        if(line.indexOf('date:') > -1) {
            return '  date: "'+ line.replace('date: ','') +'"';
        }
        return '  '+ line;
    });
    header = header.join('\n');
    header = [''].concat('\n'+header).join('---') +'\n';

    header = yaml.eval(header);
    header = mergeHead(header);
    header = JSON.stringify(header, null, 4);

    return header;
}
github logicalparadox / codex / lib / codex.back.js View on Github external
, shortName = res.replace(self.inDir, '');

        fileNames.push(shortName);

        var template = outPath.replace(self.outDir, '').split('/')[1].split('.')[0]
          , group = (shortName.split('/').length == 3) ? 'root' : template
          , markdown = fs.readFileSync(res, 'utf8')
          , yml = markdown.match(/^-{3}((.|\n)*)-{3}/g)
          , defaults = {
              title: '',
              template: template,
              'render-file': true
            }

        if (yml) {
          var props = yaml.eval(yml[0]);
          markdown = markdown.replace(/^-{3}((.|\n)*)-{3}/g, '');
          defaults = _.defaults(props, defaults);
        }

        var result = {
          inPath: res,
          inFile: shortName,
          outPath: outPath,
          href: href,
          prepared: Codex.parseMarkdown(markdown)
        };

        result = _.merge(defaults, result);

        if (result['render-file']) {
          self.files.push(result);
github jxson / haiku / lib / haiku / utilities.js View on Github external
exports.extractFrontMatter = function(data) {
  var regex = /^(\s*---([\s\S]+)---\s*)/gi
      , match = regex.exec(data)
  ;
  if (match && match.length > 0) {
    var yamlString = match[2].replace(/^\s+|\s+$/g,'')
      , template = data.replace(match[0],'')
      , yamlAttributes
    ;

    return {
      content: template,
      attributes: yaml.eval(yamlString)
    };
  } else {
    return {
      content: data,
      attributes: {}
    }
  }
};
github heroku / vulcan / server / node_modules / restler / lib / restler.js View on Github external
parsers.yaml = function(data, callback) {
    if (data) {
      try {
        callback(null, yaml.eval(data));
      } catch (err) {
        err.message = 'Failed to parse YAML body: ' + err.message;
        callback(err, null);
      }
    } else {
      callback(null, null);
    }
  };
github robhawkes / rawkets / server / main.js View on Github external
fs.readFile("config.yml", "binary", function(err, file) {
	if (err) {
		util.puts(err);
	};
	
	//util.puts(file.toString());
	var output = yaml.eval(file.toString());
	TWITTER_CONSUMER_KEY = output["TWITTER_CONSUMER_KEY"];
	TWITTER_CONSUMER_SECRET = output["TWITTER_CONSUMER_SECRET"];	
});
github prey / prey-node-client / node_modules / restler / lib / restler.js View on Github external
parsers.yaml = function(data, callback) {
    return callback(data && yaml.eval(data));
  };
github RelaxedJS / ReLaXed / src / plugin.js View on Github external
function _handleConfig(file) {
  var config
  switch(path.extname(file)) {
  case 'yml':
    config = yaml.eval(fs.readFileSync(file))
    break
  case 'yaml':
    config = yaml.eval(fs.readFileSync(file))
    break
  case 'json':
    config = require(file)
    break
  }

  if (!config.plugins) {
    return false
  }

  var list = []

  for (var plugin in config.plugins) {
    list.push(plugin)
  }
  return _requirePlugins(list)
github RelaxedJS / ReLaXed / src / plugin.js View on Github external
function _handleConfig(file) {
  var config
  switch(path.extname(file)) {
  case 'yml':
    config = yaml.eval(fs.readFileSync(file))
    break
  case 'yaml':
    config = yaml.eval(fs.readFileSync(file))
    break
  case 'json':
    config = require(file)
    break
  }

  if (!config.plugins) {
    return false
  }

  var list = []

  for (var plugin in config.plugins) {
github preactjs / preact-www / preact.config.js View on Github external
transform(content, path) {
				if (typeof content !== 'string') {
					content = content.toString('utf8');
				}

				const matches = content.match(FRONT_MATTER_REG);
				if (!matches) return content;

				const meta = yaml.eval('---\n'+matches[1].replace(/^/gm,'  ')+'\n') || {};
				content = content.replace(FRONT_MATTER_REG, '');
				if (!meta.title) {
					let [,title] = content.match(TITLE_REG) || [];
					if (title) {
						content = content.replace(TITLE_REG, '');
						meta.title = title;
					}
				}

				content = '---\n' + JSON.stringify(meta) + '\n---\n' + content;
				return content;
			}
		}, {
github danwrong / restler / lib / restler.js View on Github external
parsers.yaml = function(data, callback) {
    return callback(data && yaml.eval(data));
  };