Sha256: b51af6518278c0bd849a785318755b0e394fec7cdc7f9223312a70e8de7f8093

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

(function(object) {
  'use strict';

  object.serializeParams = function(obj, prefix) {
    var p,
        str = [];

    for (p in obj) {
      if (obj.hasOwnProperty(p)) {
        var k = prefix ? prefix + '[' + p + ']' : p,
            v = obj[p];

        str.push((v !== null && typeof v === 'object') ?
          object.serializeParams(v, k) :
          encodeURIComponent(k) + '=' + encodeURIComponent(v));
      }
    }

    return str.join('&');
  }

  object.pathBuilder = function(path) {
    var newPath = [];

    if (path.constructor === Array) {
      newPath = path.map(function(segment) { return segment; });
    } else if (path.constructor === Object) {
      newPath = Object.keys(path).map(function(resource) {
                  return [
                    resource,
                    path[resource]
                  ].join('/');
                });
    } else if (path.constructor === String) {
      newPath = [path];
    }

    return newPath.filter(Boolean).join('/').toLowerCase();
  }

  object.mountScope = function() {
    var mount = '<%= Rails.application.routes.url_helpers.archangel_path %>';

    return mount.replace(/\/$/, '');
  }

  object.authScope = function() {
    return '<%= Archangel.configuration.auth_path %>';
  }

  object.backendScope = function() {
    return '<%= Archangel.configuration.backend_path %>';
  }

  object.frontendScope = function() {
    return '<%= Archangel.configuration.frontend_path %>';
  }

  object.mountedAt = function() {
    return mountScope();
  };

  object.rootPath = function() {
    return object.pathBuilder(object.mountScope());
  };

  object.pathFor = function(path, args) {
    var finalPath = object.pathBuilder(path),
        options = object.serializeParams(args || {});

    if (options.length !== 0) {
      finalPath = finalPath + '?' + options;
    }

    return '/' + finalPath;
  };

  object.route = {
    rootPath: object.rootPath()
  };

  return object;

}(Archangel || {}));

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
archangel-0.0.5 app/assets/javascripts/archangel/object/routes.js.erb
archangel-0.0.4 app/assets/javascripts/archangel/object/routes.js.erb
archangel-0.0.3 app/assets/javascripts/archangel/object/routes.js.erb
archangel-0.0.2 app/assets/javascripts/archangel/object/routes.js.erb