tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/3] git commit: Add utility to extend an existing URL with new query parameters
Date Fri, 23 Aug 2013 23:02:15 GMT
Updated Branches:
  refs/heads/master 1ae5f834c -> b88f6fce5


Add utility to extend an existing URL with new query parameters


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/e5e5bcb8
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/e5e5bcb8
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/e5e5bcb8

Branch: refs/heads/master
Commit: e5e5bcb880cf385be81ad92a325914d8d40e3d12
Parents: 1ae5f83
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Aug 23 15:56:37 2013 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Aug 23 15:56:37 2013 -0700

----------------------------------------------------------------------
 .../META-INF/modules/t5/core/utils.coffee       | 52 +++++++++++++-------
 1 file changed, 34 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e5e5bcb8/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee
index ee2ccd4..39af431 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/utils.coffee
@@ -15,27 +15,43 @@
 ## t5/core/utils
 #
 # A few handy functions.
-define ["underscore"], (_) ->
+define ["underscore"],
 
-  trim = (input) ->
-    if String.prototype.trim
-      input.trim()
-    else
-      input.replace(/^\s+/, '').replace(/\s+$/, '')
+  (_) ->
 
-  exports =
-    startsWith: (string, pattern) -> (string.lastIndexOf pattern) is 0
-    # Trims leading and trailing whitespace from a string. Delegates to String.prototype.trim
if present.
-    trim: trim
-    # Determines if the input is a blank string, or null, or an empty array.
-    isBlank: (input) ->
+    trim = (input) ->
+      if String.prototype.trim
+        input.trim()
+      else
+        input.replace(/^\s+/, '').replace(/\s+$/, '')
 
-        return true if input is null
+    # Extends a URL, adding parameters and values from the params object. The values must
already
+    # be URI encoded.
+    extendURL = (url, params) ->
 
-        if _.isArray input
-          return input.length is 0
+      sep = if url.indexOf("?") >= 0 then "&" else "?"
 
-        return (exports.trim input).length is 0
+      for name, value of params
+        url = url + sep + name + "=" + value
+        sep = "&"
 
-    # Splits the input string into words separated by whitespace
-    split: (str) -> _(str.split " ").reject((s) -> s is "")
+      return url
+
+    exports =
+      trim: trim
+      extendURL: extendURL
+
+      startsWith: (string, pattern) -> (string.lastIndexOf pattern) is 0
+      # Trims leading and trailing whitespace from a string. Delegates to String.prototype.trim
if present.
+      # Determines if the input is a blank string, or null, or an empty array.
+      isBlank: (input) ->
+
+          return true if input is null
+
+          if _.isArray input
+            return input.length is 0
+
+          return (exports.trim input).length is 0
+
+      # Splits the input string into words separated by whitespace
+      split: (str) -> _(str.split " ").reject((s) -> s is "")


Mime
View raw message