How to use the stylus.utils 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 nodeca / nodeca.core / lib / system / init / bundle / styles / renderers / stylus.js View on Github external
module.exports = function (data, filename) {
  var renderer,
      result,
      imports = [];

  renderer = stylus(data, {
    paths:    [ path.dirname(filename) ],
    filename: filename,
    _imports: imports,
    'include css': true // include CSS on `@import`
  });

  // monkey-patch lookup with resolver
  stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
    return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
  };

  // render stylus file and restore lookup function
  result = renderer.render();
  stylus.utils.find = origFind;

  return {
    css: result,
    // array of imported file names, including current one
    imports: _.map(imports, function (entry) { return entry.path; })
  };
};
github nodeca / nodeca.core / lib / system / init / bundle / styles / renderers / stylus.js View on Github external
//


'use strict';


var _      = require('lodash');
var path   = require('path');
var stylus = require('stylus');


////////////////////////////////////////////////////////////////////////////////


// keep reference to original lookup function of stylus
var origFind = stylus.utils.find;


// resolves `/path/name` pathnames
function resolvePath(file) {
  file = String(file);

  if (file[0] !== '.') {
    try {
      file = require.resolve(file);
    } catch (err) {
      // do nothing - stylus should report itself
    }
  }

  return file;
}
github nodeca / nodeca.core / lib / bundler / plugins / stylus.js View on Github external
return Promise.resolve().then(() => {
    const stylus   = require('stylus');
    const origFind = stylus.utils.find;

    // monkey-patch lookup with resolver
    stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
      return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
    };

    let style = stylus(context.asset.source, {
      paths: [ path.dirname(context.asset.logicalPath) ],
      filename: context.asset.logicalPath,
      _imports: [],
      'include css': true,
      sourcemap: !context.bundler.sourceMaps ? false : {
        comment: false
      }
    });

    context.asset.source = style.render();
    // add Stylus `@import`s as dependencies of current asset
    _.forEach(style.options._imports, imported => {
github nodeca / nodeca.core / lib / bundler / plugins / stylus.js View on Github external
return Promise.resolve().then(() => {
    const stylus   = require('stylus');
    const origFind = stylus.utils.find;

    // monkey-patch lookup with resolver
    stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
      return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
    };

    let style = stylus(context.asset.source, {
      paths: [ path.dirname(context.asset.logicalPath) ],
      filename: context.asset.logicalPath,
      _imports: [],
      'include css': true,
      sourcemap: !context.bundler.sourceMaps ? false : {
        comment: false
      }
    });
github ServiceStack / Bundler / NuGet / Bundler / content / bundler / node_modules / nib / lib / nib.js View on Github external
/*!
 * nib
 * Copyright (c) 2010 TJ Holowaychuk 
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var stylus = require('stylus')
  , path = require('path')
  , nodes = stylus.nodes
  , utils = stylus.utils
  , Canvas

exports = module.exports = plugin;

// conditionally expose canvas-based APIs.

try {
  Canvas = require('canvas');

  var gradient = require('./nodes/gradient')
    , colorImage = require('./nodes/color-image')
} catch (err) {
  // ignore
}

/**
github colorjs / rainbowbot / node_modules / nib / lib / nib.js View on Github external
/*!
 * nib
 * Copyright (c) 2010 TJ Holowaychuk 
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var stylus = require('stylus')
  , nodes = stylus.nodes
  , utils = stylus.utils
  , Canvas

exports = module.exports = plugin;

// conditionally expose canvas-based APIs.

try {
  Canvas = require('canvas');

  var gradient = require('./nodes/gradient')
    , colorImage = require('./nodes/color-image')
} catch (err) {
  // ignore
}

/**
github aredotna / ervell / node_modules / nib / lib / nodes / color-image.js View on Github external
/**
 * Module dependencies.
 */

var stylus = require('stylus'),
    Canvas = require('canvas'),
    nodes = stylus.nodes,
    utils = stylus.utils;

/**
 * Expose `ColorImage`.
 */

exports = module.exports = ColorImage;

/**
 * Create a new `ColorImage` node with the given `color`.
 *
 * @param {Color} color node
 * @return {ColorImage}
 * @api public
 */

exports.create = function(color){
github ServiceStack / Bundler / NuGet / Bundler / content / bundler / node_modules / nib / lib / nodes / color-image.js View on Github external
/**
 * Module dependencies.
 */

var stylus = require('stylus')
  , Canvas = require('canvas')
  , nodes = stylus.nodes
  , utils = stylus.utils

/**
 * Expose `ColorImage`.
 */

exports = module.exports = ColorImage;

/**
 * Create a new `ColorImage` node with the given `color`.
 *
 * @param {Color} color node
 * @return {ColorImage}
 * @api public
 */

exports.create = function(color){
github aredotna / ervell / node_modules / nib / lib / nodes / gradient.js View on Github external
/**
 * Module dependencies.
 */

var stylus = require('stylus'),
    Canvas = require('canvas'),
    nodes = stylus.nodes,
    utils = stylus.utils;

/**
 * Expose `Gradient`.
 */

exports = module.exports = Gradient;

/**
 * Create a new `Gradient` node with the given `size`
 * and `start` position.
 *
 * @param {Number} size
 * @param {String|Ident|Literal} start
 * @return {Gradient}
 * @api public
 */
github ksc-fe / kpc / styles / functions.js View on Github external
style.define('exists', function(file) {
            return !!stylus.utils.lookup(file.string, this.paths);
        });