Sha256: 5b3690e04866d708473decc23fc1ce7faee28a8113d6e811e50aef9d13f288c1

Contents?: true

Size: 1.58 KB

Versions: 61

Compression:

Stored size: 1.58 KB

Contents

(function() {
  if (!this.require) {
    var modules = {}, cache = {};

    var require = function(name, root) {
      var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
      module   = cache[path] || cache[indexPath];
      if (module) {
        return module;
      } else if (fn = modules[path] || modules[path = indexPath]) {
        module = {id: path, exports: {}};
        cache[path] = module.exports;
        fn(module.exports, function(name) {
          return require(name, dirname(path));
        }, module);
        return cache[path] = module.exports;
      } else {
        throw 'module ' + name + ' not found';
      }
    };

    var expand = function(root, name) {
      var results = [], parts, part;
      // If path is relative
      if (/^\.\.?(\/|$)/.test(name)) {
        parts = [root, name].join('/').split('/');
      } else {
        parts = name.split('/');
      }
      for (var i = 0, length = parts.length; i < length; i++) {
        part = parts[i];
        if (part == '..') {
          results.pop();
        } else if (part != '.' && part != '') {
          results.push(part);
        }
      }
      return results.join('/');
    };

    var dirname = function(path) {
      return path.split('/').slice(0, -1).join('/');
    };

    this.require = function(name) {
      return require(name, '');
    };

    this.require.define = function(bundle) {
      for (var key in bundle) {
        modules[key] = bundle[key];
      }
    };

    this.require.modules = modules;
    this.require.cache   = cache;
  }

  return this.require;
}).call(this);

Version data entries

61 entries across 61 versions & 5 rubygems

Version Path
linner-hc-1.0.0 vendor/require_definition.js
sprockets4-commonjs-0.0.7 assets/sprockets/commonjs.js
roli-sprockets-commonjs-0.0.10 assets/sprockets/commonjs.js
linner-0.12.0 vendor/require_definition.js
linner-0.11.6 vendor/require_definition.js
linner-0.11.5 vendor/require_definition.js
linner-0.11.4 vendor/require_definition.js
linner-0.11.3 vendor/require_definition.js
linner-0.11.2 vendor/require_definition.js
linner-0.11.1 vendor/require_definition.js
linner-0.11.0 vendor/require_definition.js
linner-0.10.0 vendor/require_definition.js
linner-0.9.1 vendor/require_definition.js
linner-0.9.0 vendor/require_definition.js
linner-0.8.7 vendor/require_definition.js
linner-0.8.6 vendor/require_definition.js
linner-0.8.5 vendor/require_definition.js
linner-0.8.4 vendor/require_definition.js
linner-0.8.3 vendor/require_definition.js
linner-0.8.2 vendor/require_definition.js