complete redesign: use nodejs on server instead of php - documentation to be updated
This commit is contained in:
		
							
								
								
									
										80
									
								
								nodejs/node_modules/stylus/lib/cache/fs.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								nodejs/node_modules/stylus/lib/cache/fs.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,80 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Module dependencies.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
var crypto = require('crypto')
 | 
			
		||||
  , fs = require('fs')
 | 
			
		||||
  , join = require('path').join
 | 
			
		||||
  , version = require('../../package').version
 | 
			
		||||
  , nodes = require('../nodes');
 | 
			
		||||
 | 
			
		||||
var FSCache = module.exports = function(options) {
 | 
			
		||||
  options = options || {};
 | 
			
		||||
  this._location = options['cache location'] || '.styl-cache';
 | 
			
		||||
  if (!fs.existsSync(this._location)) fs.mkdirSync(this._location);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set cache item with given `key` to `value`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @param {Object} value
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
FSCache.prototype.set = function(key, value) {
 | 
			
		||||
  fs.writeFileSync(join(this._location, key), JSON.stringify(value));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get cache item with given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Object}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
FSCache.prototype.get = function(key) {
 | 
			
		||||
  var data = fs.readFileSync(join(this._location, key), 'utf-8');
 | 
			
		||||
  return JSON.parse(data, FSCache.fromJSON);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check if cache has given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Boolean}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
FSCache.prototype.has = function(key) {
 | 
			
		||||
  return fs.existsSync(join(this._location, key));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Generate key for the source `str` with `options`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} str
 | 
			
		||||
 * @param {Object} options
 | 
			
		||||
 * @return {String}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
FSCache.prototype.key = function(str, options) {
 | 
			
		||||
  var hash = crypto.createHash('sha1');
 | 
			
		||||
  hash.update(str + version + options.prefix);
 | 
			
		||||
  return hash.digest('hex');
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * JSON to Stylus nodes converter.
 | 
			
		||||
 *
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
FSCache.fromJSON = function(key, val) {
 | 
			
		||||
  if (val && val.__type) {
 | 
			
		||||
    val.__proto__ = nodes[val.__type].prototype;
 | 
			
		||||
  }
 | 
			
		||||
  return val;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										25
									
								
								nodejs/node_modules/stylus/lib/cache/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								nodejs/node_modules/stylus/lib/cache/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Get cache object by `name`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String|Function} name
 | 
			
		||||
 * @param {Object} options
 | 
			
		||||
 * @return {Object}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
var getCache = module.exports = function(name, options){
 | 
			
		||||
  if ('function' == typeof name) return new name(options);
 | 
			
		||||
 | 
			
		||||
  var cache;
 | 
			
		||||
  switch (name){
 | 
			
		||||
    // case 'fs':
 | 
			
		||||
    //   cache = require('./fs')
 | 
			
		||||
    //   break;
 | 
			
		||||
    case 'memory':
 | 
			
		||||
      cache = require('./memory');
 | 
			
		||||
      break;
 | 
			
		||||
    default:
 | 
			
		||||
      cache = require('./null');
 | 
			
		||||
  }
 | 
			
		||||
  return new cache(options);
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										116
									
								
								nodejs/node_modules/stylus/lib/cache/memory.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								nodejs/node_modules/stylus/lib/cache/memory.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Module dependencies.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
var crypto = require('crypto')
 | 
			
		||||
  , nodes = require('../nodes');
 | 
			
		||||
 | 
			
		||||
var MemoryCache = module.exports = function(options) {
 | 
			
		||||
  options = options || {};
 | 
			
		||||
  this.limit = options['cache limit'] || 256;
 | 
			
		||||
  this._cache = {};
 | 
			
		||||
  this.length = 0;
 | 
			
		||||
  this.head = this.tail = null;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set cache item with given `key` to `value`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @param {Object} value
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
MemoryCache.prototype.set = function(key, value) {
 | 
			
		||||
  var clone = value.clone()
 | 
			
		||||
    , item;
 | 
			
		||||
 | 
			
		||||
  clone.filename = nodes.filename;
 | 
			
		||||
  clone.lineno = nodes.lineno;
 | 
			
		||||
  clone.column = nodes.column;
 | 
			
		||||
  item = { key: key, value: clone };
 | 
			
		||||
  this._cache[key] = item;
 | 
			
		||||
 | 
			
		||||
  if (this.tail) {
 | 
			
		||||
    this.tail.next = item;
 | 
			
		||||
    item.prev = this.tail;
 | 
			
		||||
  } else {
 | 
			
		||||
    this.head = item;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this.tail = item;
 | 
			
		||||
  if (this.length++ == this.limit) this.purge();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get cache item with given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Object}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
MemoryCache.prototype.get = function(key) {
 | 
			
		||||
  var item = this._cache[key]
 | 
			
		||||
    , val = item.value.clone();
 | 
			
		||||
 | 
			
		||||
  if (item == this.tail) return val;
 | 
			
		||||
  if (item.next) {
 | 
			
		||||
    if (item == this.head) this.head = item.next;
 | 
			
		||||
    item.next.prev = item.prev;
 | 
			
		||||
  }
 | 
			
		||||
  if (item.prev) item.prev.next = item.next;
 | 
			
		||||
 | 
			
		||||
  item.next = null;
 | 
			
		||||
  item.prev = this.tail;
 | 
			
		||||
 | 
			
		||||
  if (this.tail) this.tail.next = item;
 | 
			
		||||
  this.tail = item;
 | 
			
		||||
 | 
			
		||||
  return val;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check if cache has given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Boolean}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
MemoryCache.prototype.has = function(key) {
 | 
			
		||||
  return !!this._cache[key];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Generate key for the source `str` with `options`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} str
 | 
			
		||||
 * @param {Object} options
 | 
			
		||||
 * @return {String}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
MemoryCache.prototype.key = function(str, options) {
 | 
			
		||||
  var hash = crypto.createHash('sha1');
 | 
			
		||||
  hash.update(str + options.prefix);
 | 
			
		||||
  return hash.digest('hex');
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Remove the oldest item from the cache.
 | 
			
		||||
 *
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
MemoryCache.prototype.purge = function() {
 | 
			
		||||
  var item = this.head;
 | 
			
		||||
 | 
			
		||||
  if (this.head.next) {
 | 
			
		||||
    this.head = this.head.next;
 | 
			
		||||
    this.head.prev = null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this._cache[item.key] = item.prev = item.next = null;
 | 
			
		||||
  this.length--;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										50
									
								
								nodejs/node_modules/stylus/lib/cache/null.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								nodejs/node_modules/stylus/lib/cache/null.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Module dependencies.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
var NullCache = module.exports = function() {};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set cache item with given `key` to `value`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @param {Object} value
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
NullCache.prototype.set = function(key, value) {};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get cache item with given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Object}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
NullCache.prototype.get = function(key) {};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check if cache has given `key`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} key
 | 
			
		||||
 * @return {Boolean}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
NullCache.prototype.has = function(key) {
 | 
			
		||||
  return false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Generate key for the source `str` with `options`.
 | 
			
		||||
 *
 | 
			
		||||
 * @param {String} str
 | 
			
		||||
 * @param {Object} options
 | 
			
		||||
 * @return {String}
 | 
			
		||||
 * @api private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
NullCache.prototype.key = function(str, options) {
 | 
			
		||||
  return '';
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user