_.each(options, function(value, key) { if (key === 'urlfunc') { // Custom name of function for embedding images as Data URI if (_.isString(value)) { s.define(value, stylus.url()); } else { s.define(value.name, stylus.url({ limit: value.limit !== null ? value.limit : 30000, paths: value.paths ? value.paths : [] })); } } else if (key === 'use') { value.forEach(function(func) { if (_.isFunction(func)) { s.use(func()); } }); } else if (key === 'define') { for (var defineName in value) { s.define(defineName, value[defineName], shouldUseRawDefine(defineName)); } } else if (key === 'rawDefine') { // do nothing. } else if (key === 'import') { value.forEach(function(stylusModule) { s.import(stylusModule); }); } else if (key === 'resolve url') { s.define('url', stylus.resolver()); } else { s.set(key, value); } });
compile: function(str, path) { return stylus(str) .set('filename', path) .set('compress', true) .define('x-data-uri', stylus.url({ paths: [ ] })) .use(nib()); }
it( sName, function( done ) { var sPath = "test/cases/" + oTest + ".styl", sStylusCase = fs.readFileSync( sPath, "utf8" ).replace( rReturn, "" ), sCSSExpected = fs.readFileSync( "test/cases/" + oTest + ".css", "utf8" ).replace( rReturn, "" ), oStylus; ( oStylus = stylus( sStylusCase ) ) .use( koutoSwiss() ) .set( "filename", sPath ) .include( __dirname + "/cases/img" ) .define( "url", stylus.url() ); if ( ~oTest.indexOf("compress") ) { oStylus.set("compress", true); } oStylus.render( function( oError, sCSSActual ) { if( oError ) { if( oError.message.indexOf( "expected" ) > -1 ) { oError.message = oError.message.substring( 0, oError.message.indexOf( "expected" ) ); } return done( oError ); } sCSSActual .trim() .should .equal( sCSSExpected.trim() ); done(); } ); } );
, compile: function (str, lpath) { return stylus(str) .set('filename', lpath) .set('warn', true) .set('compress', true) .define('url', stylus.url({ paths: [ path.join( clientdir, 'public','css')] })) }
gulp.task(name+'-stylus', [], function() { return gulp.src('./lib/'+name+'/*.styl') .pipe( stylus({ define: { 'url': stylus_itself.url() } }) ) .pipe( prefix('last 20 versions', 'ie 8', 'ie 9') ) .pipe( gulp.dest('./generated/'+name+'/') ); });
_.each(options, function(value, key) { if (key === 'urlfunc') { s.define(value, stylus.url()); } else { s.set(key, value); } });
toArray(opts.urlfunc).forEach(urlfunc => { const urlOptions = { name: 'data-uri', paths: styl.get('paths'), limit: false, ...urlfunc } styl.define(urlOptions.name, stylus.url(urlOptions)) })
compile: function(str, path) { return stylus(str) .define('url', stylus.url({ paths: [o.paths.root.images] })) .set('compress', true) .set('filename', path) .include(nib.path); }
compile: function (str, path) { return stylus(str) .set('filename', path) .set('compress', true) .set('force', true) .use(autoprefixer(['last 2 version', '> 1%', 'ie 8', 'ie 7'])) // .use(csso()) .define('url64', stylus.url()); }
function compile(str, path) { return stylus(str) .set('filename', path) .use(nib()) .define('url', stylus.url({ paths : [__dirname + '/public'], limit : 10000 })); }
_.each(options, function(value, key) { if (key === 'urlfunc') { // Custom name of function to embed images as Data URI s.define(value, stylus.url()); } else { s.set(key, value); } });
// Custom compile configuration for Stylus function compile(str, path) { return stylus(str) .set('filename', path) .set('compress', false) .set('include css', true) .define('url', stylus.url({ limit: 60000 })) .use(nib()); }
function compile(str, path) { return stylus(str) .define('url', stylus.url({ paths : [__dirname + "/app/public/stylesheets"], limit : 10000 })) .set('filename', path) .set('compress', true) .use(nib()); }
write: function (src, dst, options, callback) { if (!fsys.isFileSync(src)) { return callback(new Error('source file not found. path:', src)); } _.defaults(options || (options = {}), DEFAULT_OPTIONS); var encode = options.encode; var compress = options.compress; var firebug = options.firebug; var linenos = options.linenos; var urlopt = options.url; var raw = fs.readFileSync(src, encode); var styl = stylus(raw) .set('filename', dst) .set('compress', compress) .set('firebug', firebug) .set('linenos', linenos) .define('b64', stylus.url(urlopt)) ; if(options.nib) { // use nib library styl.use(nib()); } // define functions and constant values if (options.fn && Object.keys(options.fn).length) { styl.use(function (styl) { _.each(options.fn, function (fn, name) { if (_.isFunction(fn)) { styl.define(name, function (data) { return fn(data && data.val); }); } else { styl.define(name, function () { return fn; }); } }); }); } styl.render(function (err, css) { err && callback(err, css); fs.writeFileSync(dst, css, encode); callback(null, css); }); }
it(test.name, function() { var stylPath = path.join(test.path, test.name + ".styl"), cssPath = path.join(test.path, test.name + ".css"), expected = css.normalize(fs.readFileSync(cssPath, "utf8")); stylus(fs.readFileSync(stylPath, "utf8")) .use(fn()) .set("filename", stylPath) .define("url", stylus.url()) .render(function(err, compiled) { if (err) throw err; var actual = css.normalize(compiled); actual.should.equal(expected); }); });
function exeStylus(src, options, fn) { var s = stylus(src) .define('url', stylus.url({ paths: [__dirname + '/../client/assets/a/b'] })) .use(nib()) .import('nib'); _.each(options, function(value, key) { s.set(key, value); }); s.render(function(err, css) { if (err) { log.error(err); } fn(err, css); }); }
it(name, function(){ var path = 'test/cases/' + test + '.styl'; var styl = fs.readFileSync(path, 'utf8').replace(/\r/g, ''); var css = fs.readFileSync('test/cases/' + test + '.css', 'utf8').replace(/\r/g, '').trim(); var style = stylus(styl) .use(nib()) .set('filename', path) .define('url', stylus.url()); if (~test.indexOf('compress')) style.set('compress', true); style.render(function(err, actual){ if (err) throw err; actual.trim().should.equal(css); }); });
function Stylus(filePath, content, options, cb) { var styl = stylus(content) .set('filename', filePath) .use(nib()) .import('nib'); if (options.url) { styl.define('url', stylus.url({ paths: options.url })); } styl.render(function (err, css) { if (err) { console.log('[ERROR] Stylus processing error: ', err); process.exit(-1); } cb(null, css); }); }
return function (style) { style.include(__dirname); // List images of a directory as an array style.define('imagelist', imagelist); // Base64-encode images that are smaller than 3000 bytes style.define('url', stylus.url({paths: [pub], limit: 3000})); // Makes it easy to separate out filenames style.define('basename', function (path, ext) { return basename(path.val, ext.val || null); }); // Use nib style.use(nib())['import']('nib'); }
it(name, function (done) { var path = 'test/cases/' + test + '.styl'; var styl = fs.readFileSync(path, 'utf8').replace(/\r/g, ''); var css = fs.readFileSync('test/cases/' + test + '.css', 'utf8').replace(/\r/g, '').trim(); // get stylus ready to render our test var style = stylus(styl) .use(ui()) .set('filename', path) .define('url', stylus.url()); // if the case has "compress" in the file name, then compress the output if (~test.indexOf('compress')) style.set('compress', true); // render the stylus file and assert that it matches the CSS file style.render(function (err, actual) { if (err) throw err; expect(actual.trim()).to.equal(css); done(); }); });
grunt.util._.each(options, function(value, key) { if (key === 'urlfunc') { // Custom name of function for embedding images as Data URI s.define(value, stylus.url()); } else if (key === 'use') { value.forEach(function(func) { if (typeof func === 'function') { s.use(func()); } }); } else if (key === 'define') { for (var defineName in value) { s.define(defineName, value[defineName]); } } else if (key === 'import') { value.forEach(function(stylusModule) { s.import(stylusModule); }); } else { s.set(key, value); } });
function stylusBuild(stylpath, csspath) { var styl = readUtfFile(stylpath); if (!styl) error('Cannot open stylesheet ' + stylpath + '.'); var compiler = stylus(styl) .set('filename', stylpath) .set('compress', !isDebug) .set('include css', true) .define('embedurl', stylus.url()); compiler.render(function(err, css) { if (err) { warning('Stylus error.' + '\n\n' + err.message || err.stack); } fs.writeFile(csspath, css, function(err) { if (err) { error('Cannot write file ' + csspath + '.'); } }); }); }
use: [stylusMixin, styl => { styl.define('url', stylus.url()) }],
opts.urlFn.forEach(function (el) { s.define(el, stylus.url()); });
return function(style) { style.include(__dirname); style.define('data-url', stylus.url({ limit: 10000 // ~10k })); };
it(name, function () { var style = stylus(test.styl).use(px2rem()).set('filename', test.name).define('url', stylus.url()); if (~test.styl.indexOf('compress')) style.set('compress', true); style.render(function (error, actual) { if (error) throw error; actual.replace(/\s+/g, '').trim().should.equal(test.css); }); });
options.urlFunc.forEach(function(args){ s.define(args, stylus.url()); });
function compile(str, path) { return stylus(str).define('url', stylus.url({ limit: 1000000 })); }
return function(style) { style.define('url', stylus.url({ paths: [__dirname + '/client'] })); };
function render_html(ndoc, options) { var file, str, fn, list, id, obj; // prepare rendering function // TODO: store it for further reuse, and get rid of jade dependency? file = path.join(__dirname, 'html', 'templates', 'layout.jade'); str = fs.readFileSync(file, 'utf8'); fn = Jade.compile(str, { filename: file, pretty: false }); options.github = template(options.github || '', {package: options.package}); // it's illegal to have slashes in HTML elements ids. // replace them with dashes list = ndoc.list; for (id in list) { if (list.hasOwnProperty(id)) { obj = list[id]; // path should be HTML valid id obj.path = obj.path.replace(/\//g, '-'); } } // render link // N.B. logic is way tricky to move to templates. // beside, this function is used as parameter in some Array#map() operations function link(obj, short, classes) { if (typeof obj === 'string') { obj = list[obj] || {id: obj}; } // broken link. `options.brokenLinks` define action if (!obj.path) { return obj.id; /*if (options.brokenLinks === 'throw') { throw 'Link is broken: ' + obj.id; } return options.brokenLinks === 'show' ? '[[' + obj.id + ']]' : obj.id;*/ } // var r = '<a href="#' + obj.path + '" class="' + (classes || []).join(' ') + '" title="' + obj.id + (obj.type ? ' (' + obj.type + ')' : '') + '" data-id="' + obj.id.toLowerCase() + '">'; r += typeof short === 'string' ? short : short ? obj.name : obj.id; r += '</a>'; return r; } // convert markdown to HTML function markdown(text, nohl) { var r, codes; marked.setOptions({ gfm: true, pedantic: false, sanitize: false, highlight: nohl ? null : marked_highlight }); r = marked(text); // FIXME // desugar [[foo#bar]] tokens into local links // N.B. in order to not apply conversion in <code> blocks, // we first store replace code blocks with nonces codes = {}; r = r.replace(/(<code>[\s\S]*?<\/code>)/g, function (all, def) { var nonce = Math.random().toString().substring(2); codes[nonce] = def; return '@-=@=-@' + nonce + '@-=@=-@'; }); // convert [[link]] to links r = r.replace(/\[\[([\s\S]+?)\]\]/g, function (all, def) { def = def.split(/\s+/); id = def.shift(); // invalid references don't produce links if (!list[id]) { if (options.brokenLinks === 'throw') { throw 'Link is broken: ' + all + '\n' + r; } return options.brokenLinks === 'show' ? all : id; } var obj = _.extend({name: def.join(' ') || id}, list[id]); return link(obj, false, ['link-short']); }); // restore code blocks, given previously stored nonces r = r.replace(/@-=@=-@(\d+)@-=@=-@/g, function (all, nonce) { return codes[nonce]; }); // return r; } // given signature object, recompose its textual representation function signature(obj, sig) { if (typeof obj === 'string') { obj = list[obj]; } var r = obj.id; if (sig.args) { r += '('; sig.args.forEach(function (arg, idx) { var skip_first, a, value; // skip the first bound argument for prototype methods skip_first = obj.bound && obj.id.indexOf('#') >= 0; a = arg.name; // argument can be callback if (arg.args) { a = signature({id: a}, arg); } if (!idx && skip_first) { return; //a = '@' + a; } if (typeof arg.default_value !== 'undefined') { // apply custom stringifier value = JSON.stringify(arg.default_value, function (k, v) { if (v instanceof RegExp) { // FIXME: get rid of quotes, if possible v = v.source; } else if (v === 'null') { v = null; } return v; }); a = a + ' = ' + value; } // compensate for possibly skipped first argument if (idx > (skip_first ? 1 : 0)) { a = ', ' + a; } if (arg.ellipsis) { a += '...'; } if (arg.optional) { a = '[' + a + ']'; } r += a; }); r += ')'; } return r; } var stylesPath = path.join(__dirname , 'html/stylesheets/main.css.styl'); var templatePath = path.join(__dirname , 'html/templates/layout.jade'); var err, css, html; // Render CSS stylus(fs.readFileSync(stylesPath, 'utf8')) .set('filename', stylesPath) .include(require('nib').path) .define('url', stylus.url()) .render(function(e, val) { // hack to make sync rendering if (e) { err = e; } css = val; }); if (err) { throw err; } // collect context for rendering function var vars = _.extend({}, options, { // data list: ndoc.list, tree: ndoc.tree, css: css, // helpers date: (new Date()).toUTCString(), link: link, markdown: markdown, signature: signature, showInternals: !!options.showInternals, // options filename: templatePath }); // render HTML jade.render(fs.readFileSync(templatePath, 'utf8'), vars, function (e, val) { if (e) { err = e; } html = val; }); if (err) { throw err; } if (fs.existsSync(options.output)) { throw "Output directory '" + options.output + "' already exists"; } FsTools.mkdirSync(options.output); fs.writeFileSync(path.join(options.output, 'index.html'), html); }