Sha256: d0e47004a89673ecae312e8f7bd60273d49efe7de0b7883fc40bb6ee0b539bb2

Contents?: true

Size: 900 Bytes

Versions: 9

Compression:

Stored size: 900 Bytes

Contents

$.buildPath = (path, params...) ->
  extraParams = {}
  paramsHash = {}

  if $.isPlainObject(lastParam = params.pop()) then paramsHash = lastParam
  else params.push(lastParam)

  $.each params, (_, value) ->
    replacement = "/#{value}"
    path = path.replace /\/:[\w_]+/, replacement

  # try to insert parameters
  $.each paramsHash, (name, value) ->
    if path.match(new RegExp(":#{name}"))
      pattern = "(.*?)\\(([\\.\\/\\w]*?):#{name}(\\(.*?\\)|[^\\)]*)?\\)(.*)"
      replacement = "$1$2#{value}$3$4"
      path = path.replace new RegExp(pattern), replacement

      pattern = "(.*?):#{name}(.*)"
      replacement = "$1#{value}$2"
      path = path.replace new RegExp(pattern), replacement
    else extraParams[name] = value

  # cleanup
  path = path.replace(/\(.*\)/, '')

  # add extra params
  path += "?#{$.param(extraParams)}" unless $.isEmptyObject(extraParams)
  
  return path

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
js_routes-0.1.15 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.14 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.12 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.11 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.10 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.9 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.8 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.7 lib/assets/javascripts/jquery.pathBuilder.js.coffee
js_routes-0.1.6 lib/assets/javascripts/jquery.pathBuilder.js.coffee