How to use the stylus/lib/nodes.Block function in stylus

To help you get started, we’ve selected a few stylus 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 shama / stylus-loader / lib / evaluator.js View on Github external
// Parse the file
  importStack.push(file);
  nodes.filename = file;

  var str;
  if (this.cache.sources && this.cache.sources[file]) {
    str = this.cache.sources[file];
  } else {
    str = fs.readFileSync(file, 'utf8');
  }

  if (literal && !this.resolveURL) return new nodes.Literal(str.replace(/\r\n?/g, '\n'));

  // parse
  var block = new nodes.Block
    , parser = new Parser(str, utils.merge({ root: block }, this.options));

  try {
    block = parser.parse();
  } catch (err) {
    err.filename = file;
    err.lineno = parser.lexer.lineno;
    err.input = str;
    throw err;
  }

  // Evaluate imported "root"
  block.parent = this.root;
  block.scope = false;
  var ret = this.visit(block);
  importStack.pop();
github mockingbot / ibot / scripts / stylus-enhanced-evaluator.js View on Github external
// Avoid overflows from importing the same file over again
  if (file === importStack[importStack.length - 1]) return nodes.null

  if (this.options._imports) this.options._imports.push(node.clone())

  // Parse the file
  importStack.push(file)
  nodes.filename = file

  var str = fs.readFileSync(file, "utf8")

  if (literal && !this.resolveURL)
    return new nodes.Literal(str.replace(/\r\n?/g, "\n"))

  // parse
  var block = new nodes.Block(),
    parser = new Parser(str, utils.merge({ root: block }, this.options))

  try {
    block = parser.parse()
  } catch (err) {
    err.filename = file
    err.lineno = parser.lexer.lineno
    err.input = str
    throw err
  }

  // Evaluate imported "root"
  block.parent = this.root
  block.scope = false
  var ret = this.visit(block)
  importStack.pop()
github mockingbot / ibot / scripts / stylus-enhanced-evaluator.js View on Github external
*****************************************************************************/
  // if still not found, so maybe it ref to a module file in node_modules
  if (!found) {
    path = urlToRequest(path)
    let pathComponents = this.filename.split(sep)
    if (pathComponents.indexOf("components") > -1) {
      const pkgDir = pathComponents
        .slice(0, pathComponents.indexOf("components") + 2)
        .join(sep)
      found = [resolve.sync(path, { extensions: [".styl"], basedir: pkgDir })]
    }
  }
  // Throw if import failed
  if (!found) throw new Error("failed to locate @" + nodeName + " file " + path)

  var block = new nodes.Block()

  for (var i = 0, len = found.length; i < len; ++i) {
    block.push(importFile.call(this, imported, found[i], literal, index))
  }

  return block
}
github shama / stylus-loader / lib / evaluator.js View on Github external
// Lookup
  var dirname = this.paths[this.paths.length - 1];
  found = this.cache.find(path, dirname);
  index = this.cache.isIndex(path, dirname);
  if (!found) {
    found = utils.find(path, this.paths, this.filename);
    if (!found) {
      found = utils.lookupIndex(name, this.paths, this.filename);
      index = true;
    }
  }

  // Throw if import failed
  if (!found) throw new Error('failed to locate @' + nodeName + ' file ' + path);

  var block = new nodes.Block;

  for (var i = 0, len = found.length; i < len; ++i) {
    block.push(importFile.call(this, imported, found[i], literal, index));
  }

  return block;
}