# Code coverage report for lib/compiler.js

## Statements: 100% (34 / 34) Branches: 100% (5 / 5) Functions: 100% (7 / 7) Lines: 100% (34 / 34) Ignored: none

All files » lib/ » compiler.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    491
    1
    1
    1
    1
    9
    9
    9

    1
    17
    17
    17
    17
    17
    4
    4

    17
    17

    8

    3

    6

    17
    24
    24
    24
    13
    13
    13
    13
    4
    4
    4

    13

    11

     (function(){
      var σ, parseUrl, last, slice$ = [].slice;
      σ = require('highland');
      parseUrl = require('url').parse;
      last = function(arg$){
        var x;
        x = arg$[arg$.length - 1];
        return x;
      };
      exports.compilePath = function(path){
        var ident, sigil, params, paramReg, reg;
        ident = '[a-z$_][a-z0-9$_]*';
        sigil = ':';
        params = [];
        paramReg = path.replace(RegExp(sigil + '(' + ident + ')', 'ig'), function(m, param){
          params.push(param);
          return '([^\\/]+)';
        });
        reg = (function(){
          switch (false) {
          case path !== '/':
            return /^\/$/;
          case '/' !== last(path):
            return RegExp('^' + paramReg + '?', 'i');
          default:
            return RegExp('^' + paramReg + '\\/?$', 'i');
          }
        }());
        return function(url){
          var pathname, that, route, vals, i, val;
          pathname = parseUrl(url).pathname;
          if ((that = reg.exec(pathname)) != null) {
            route = that[0], vals = slice$.call(that, 1);
            return σ([(function(){
              var i$, ref$, len$, results$ = {};
              for (i$ = 0, len$ = (ref$ = vals).length; i$ < len$; ++i$) {
                i = i$;
                val = ref$[i$];
                results$[params[i]] = val;
              }
              return results$;
            }())]);
          } else {
            return σ([]);
          }
        };
      };
    }).call(this);