How to use the stylus.render 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 nitin42 / stylus-in-react / utils / testParser.js View on Github external
function parseStylus(stylusCode) {
	let AST, rules, stylesheet, hash, selectors, element;

	stylus.render(stylusCode, { filename: 'source.css' }, (err, css) => {
		// throws parse errors
		if (err) {
			throw new Error('Indentation error');
		}

		// Generate css AST
		AST = parser.parse(css, { source: 'css' });

		// Get the root selector
		selectors = AST.stylesheet.rules[0] !== undefined ? AST.stylesheet.rules[0].selectors : null;

		// Set the root element
		element = getParentNode(selectors);

		// Style rules
		rules = AST.stylesheet.rules;
github artsy / positron / lib / assets.js View on Github external
// Browserify + Transforms
  if (path.extname(file) == '.js' || path.extname(file) == '.coffee') {
    var b = browserify().add(assetsDir + file);
    try { b.transform(require('caching-coffeeify')) } catch (e) {};
    try { b.transform(require('jadeify')) } catch (e) {};
    try { b.transform(require('uglifyify')) } catch (e) {};
    b.bundle(function(err, buf) {
      if (err) return errExit(err);
      fs.writeFileSync(publicDir + file.split('.')[0] + '.js', buf);
    });
  }

  // Stylus + Sqwish
  try { var stylus = require('stylus'); } catch (e) {};
  if (stylus && path.extname(file) == '.styl') {
    stylus.render(fs.readFileSync(assetsDir + file).toString(), {
      filename: assetsDir + file
    }, function(err, css) {
      if (err) return errExit(err);
      try { var css = require('sqwish').minify(css) } catch (e) {};
      fs.writeFileSync(publicDir + file.split('.')[0] + '.css', css);
    });
  }
});
github jsbin / pennyworth / targets / stylus / index.js View on Github external
var convertToStylus = function (resolve, reject, data) {
  stylus.render(data.source, function (error, css) {
    if (error) {
      // index starts at 1
      var lineMatch = error.message.match(/stylus:(\d+)/);
      var line = parseInt(lineMatch[1], 10) || 0;
      var msg = error.message.match(/\n\n(.+)\n$/);
      if (line > 0) {
        line = line - 1;
      }
      var errors = {
        line: line,
        ch: null,
        msg: msg[1]
      };
      resolve({
        errors: [errors],
        result: null
github YuzuJS / WinningJS-build / lib / doStylus.js View on Github external
files.forEach(function (fileName) {
        var fileContents = grunt.file.read(fileName);
        var newFileName = fileName.match(/(.*).styl/)[1] + ".css";
        var newFilePath = path.join(config.dest, newFileName);

        // NB: this isn't actually asynchronous; it just uses callbacks for some reason. That's what makes it possible
        // to push onto `newFileUrls`.
        stylus.render(fileContents, { filename: newFileName }, function (err, css) {
            if (err) {
                grunt.warn(err.message);
            } else {
                grunt.file.write(newFilePath, css);
                grunt.log.writeln("CSS file created at \"" + newFilePath + "\".");

                newFileUrls.push(urlize(newFilePath));
            }
        });
    });
github knpwrs / connect-static-transform / examples / standardExample.js View on Github external
transform: function (path, styl, send) {
    stylus.render(styl, {filename: path, compress: true}, function (err, css) {
      if (err) {
        throw err;
      }
      // Stylus keeps newlines and inline comments, even when compressing. Let's get rid of them:
      css = css.replace(/\n/g, '');
      css = css.replace(/\/\*.+\*\//g, '');
      // Send css to client
      send(css, {'Content-Type': 'text/css'});
    });
  }
});
github neuronetio / gantt-schedule-timeline-calendar / rollup.config.js View on Github external
load(id) {
      if (id.endsWith('.styl')) {
        const style = readFileSync(id, { encoding: 'utf8' });
        stylusLib.render(style, function(err, css) {
          if (err) throw err;
          result = css;
        });
        return 'var stylus=1;';
      }
      return null; // other ids should be handled as usually
    },
    writeBundle(bundle) {
github audreyt / ethercalc / node_modules / zappa / lib / zappa.js View on Github external
root_locals.stylus = function(obj) {
      var css, k, v, _results;
      _results = [];
      for (k in obj) {
        v = obj[k];
        _results.push(css = require('stylus').render(v, {
          filename: k
        }, function(err, css) {
          if (err) {
            throw err;
          }
          return routes.push({
            verb: 'get',
            path: k,
            handler: css,
            contentType: 'css'
          });
        }));
      }
      return _results;
    };
    root_locals.helper = function(obj) {
github vuejs / vue-component-compiler / compilers / stylus.js View on Github external
module.exports = function (raw, cb) {
  try {
    var stylus = require('stylus')
  } catch (err) {
    return cb(err)
  }
  stylus.render(raw, {}, cb)
}
github kristerkari / react-native-stylus-transformer / index.js View on Github external
function renderToCSS({ src, filename, options }) {
  return stylus.render(src, { filename });
}