jQuery-URL-Parser-Rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ *.log
2
+ *.sqlite3
3
+ /pkg/*
4
+ .bundle
5
+ .ruby-version
6
+ spec/database.yml
7
+ tmp*.sw?
8
+ *.sw?
9
+ tmp
10
+ *.gem
11
+ *.lock
12
+ .idea/*
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2013 Dirk Eisenberg
2
+ Copyright (c) 2012 Mark Perkins, http://allmarkedup.com/
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,200 @@
1
+ (jQuery) URL Parser v2.2 - Rails Gem
2
+ ====================================
3
+
4
+ An AMD compatible utility to parse urls and provide easy access to their attributes (such as the protocol, host, port etc), path segments, querystring parameters, fragment parameters and more.
5
+
6
+ The core parser functionality is based on the [Regex URI parser by Steven Levithan](http://blog.stevenlevithan.com/archives/parseuri), and the query string parsing is handled by a modified version of [node-querystring](https://github.com/visionmedia/node-querystring).
7
+
8
+ **Note this used to have a jQuery dependency - this is now optional. See below for details**
9
+
10
+ **License:** Available for use under a MIT-style license. If you need a different license for any reason please just let me know.
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Add the following line into your Gemfile
16
+
17
+ ```ruby
18
+ gem 'jQuery-URL-Parser-Rails'
19
+ ```
20
+
21
+ and require the purl library in the application.js file
22
+
23
+ ```javascript
24
+ //= require purl
25
+ ```
26
+
27
+ To jQuery or *not* to jQuery, that is the question...
28
+ ----------------------------------------------------
29
+
30
+ This utility can be used in two ways - with jQuery or without. There is just one file (purl.js) for both versions - if jQuery is included on the page before it then it will provide the 'jQuery-style' interface (see examples below), otherwise it will be accessible via the global `purl` variable.
31
+
32
+ The jQuery version has an additional feature that lets it extract the URL from a jQuery element object, where appropriate.
33
+
34
+ Specifying the URL to parse
35
+ ---------------------------
36
+
37
+ There are a few different ways to choose what URL to parse:
38
+
39
+ ``` javascript
40
+ /*---- jQuery version -----*/
41
+ var url = $.url(); // parse the current page URL
42
+ var url = $.url('http://allmarkedup.com'); // pass in a URI as a string and parse that
43
+ var url = $('#myElement').url(); // extract the URL from the selected element and parse that - will work on any element with a `src`, `href` or `action` attribute.
44
+
45
+ /*---- plain JS version -----*/
46
+ var url = purl(); // parse the current page URL
47
+ var url = purl('http://allmarkedup.com'); // pass in a URI as a string and parse that
48
+ ```
49
+
50
+ URL attributes
51
+ --------------
52
+
53
+ The `.attr()` method is used to return information on various parts of the URL. For example:
54
+
55
+ ``` javascript
56
+ var url = $.url('http://allmarkedup.com/folder/dir/index.html?item=value'); // jQuery version
57
+ var url = purl('http://allmarkedup.com/folder/dir/index.html?item=value'); // plain JS version
58
+ url.attr('protocol'); // returns 'http'
59
+ url.attr('path'); // returns '/folder/dir/index.html'
60
+ ```
61
+
62
+ The attributes available for querying are:
63
+
64
+ * **source** - the whole url being parsed
65
+ * **protocol** - eg. http, https, file, etc
66
+ * **host** - eg. www.mydomain.com, localhost etc
67
+ * **port** - eg. 80
68
+ * **relative** - the relative path to the file including the querystring (eg. /folder/dir/index.html?item=value)
69
+ * **path** - the path to the file (eg. /folder/dir/index.html)
70
+ * **directory** - the directory part of the path (eg. /folder/dir/)
71
+ * **file** - the basename of the file eg. index.html
72
+ * **query** - the entire querystring if it exists, eg. item=value&item2=value2
73
+ * **fragment** (also available as **anchor**) - the entire string after the # symbol
74
+
75
+ There are also a few more obscure ones available too if you want to dig about a bit ;-)
76
+
77
+ If you don't specify an attribute then this method will return an object literal with all the available attribute key:value pairs in it.
78
+
79
+ Query string parameters
80
+ -----------------------
81
+
82
+ The `.param()` method is used to return the values of querystring parameters.
83
+
84
+ Pass in a string to access that parameter's value:
85
+
86
+ ``` javascript
87
+ /*---- jQuery version -----*/
88
+ $.url('http://allmarkedup.com?sky=blue&grass=green').param('sky'); // returns 'blue'
89
+
90
+ /*---- plain JS version -----*/
91
+ purl('http://allmarkedup.com?sky=blue&grass=green').param('sky'); // returns 'blue'
92
+ ```
93
+
94
+ If no argument is passed in it will return an object literal containing a key:value map of all the querystring parameters.
95
+
96
+ ``` javascript
97
+ /*---- jQuery version -----*/
98
+ $.url('http://allmarkedup.com?sky=blue&grass=green').param(); // returns { 'sky':'blue', 'grass':'green' }
99
+
100
+ /*---- plain JS version -----*/
101
+ purl('http://allmarkedup.com?sky=blue&grass=green').param(); // returns { 'sky':'blue', 'grass':'green' }
102
+ ```
103
+
104
+ Note that the `.param()` method will work on both ampersand-split and semicolon-split querystrings.
105
+
106
+ *As of version 2.2 the param method now handles array-style query string params.*
107
+
108
+ URL segments
109
+ -----------------------
110
+
111
+ The `.segment()` method is used to return values of individual segments from the URL's path.
112
+
113
+ Pass in an integer value to get the value of that segment - note however that the count is *not* zero-indexed like an array - i.e. `.segment(1)` returns the *first* segment, not the second one.
114
+
115
+ You can also pass in negative values, in which case it will count back from the end of the path rather than forwards from the start.
116
+
117
+ ``` javascript
118
+ var url = $.url('http://allmarkedup.com/folder/dir/example/index.html'); // jQuery version
119
+ var url = purl('http://allmarkedup.com/folder/dir/example/index.html'); // plain JS version
120
+ url.segment(1); // returns 'folder'
121
+ url.segment(-2); // returns 'example'
122
+ ```
123
+ If no argument is passed in it will return an array of all the segments (which will be zero-indexed!).
124
+
125
+ ``` javascript
126
+ $.url('http://allmarkedup.com/folder/dir/example/index.html').segment(); // jQuery version - returns ['folder','dir','example','index.html']
127
+ purl('http://allmarkedup.com/folder/dir/example/index.html').segment(); // plain JS version - returns ['folder','dir','example','index.html']
128
+ ```
129
+
130
+ Fragment parameters and/or segments
131
+ -------------------------------
132
+
133
+ Some sites and apps also use the hash fragment to store querystring-style key value pairs (eg. `http://test.com/#sky=blue&grass=green`), or slash-delimited paths (eg. `http://test.com/#/about/us/`).
134
+
135
+ There are two methods available for extracting information from fragments of these types - `.fparam()` and `.fsegment()`, both of which behave indentically to their `.param()` and `.segment()` counterparts but act on the fragment rather than the main URL.
136
+
137
+ ``` javascript
138
+ /*---- jQuery version -----*/
139
+ $.url('http://test.com/#sky=blue&grass=green').fparam('grass'); // returns 'green'
140
+ $.url('http://test.com/#/about/us/').fsegment(1); // returns 'about'
141
+
142
+ /*---- plain JS version -----*/
143
+ purl('http://test.com/#sky=blue&grass=green').fparam('grass'); // returns 'green'
144
+ purl('http://test.com/#/about/us/').fsegment(1); // returns 'about'
145
+ ```
146
+
147
+ Strict mode and relative URLs
148
+ --------------------
149
+
150
+ Internally this plugin uses Steven Levithan's excellent Regex URI parser, which has two modes - loose and strict. This plugin uses the loose mode by default (i.e. strict mode set to `false`), which deviates slightly from the specs but can produce more intuitive results in some situations. However, loose mode will not correctly parse relative URLs, so you can optionally enable strict mode when calling the plugin as follows:
151
+
152
+ ``` javascript
153
+ /*---- jQuery version -----*/
154
+ var url = $.url(true); // parse the current page URL in strict mode
155
+ var url = $.url('http://allmarkedup.com',true); // pass in a URI as a string and parse that in strict mode
156
+ var url = $('#myElement').url(true); // extract the URL from the selected element and parse that in strict mode
157
+
158
+ /*---- plain JS version -----*/
159
+ var url = purl(true); // parse the current page URL in strict mode
160
+ var url = purl('http://allmarkedup.com',true); // pass in a URI as a string and parse that in strict mode
161
+ ```
162
+
163
+
164
+ A note on improperly encoded URLs
165
+ ---------------------------------
166
+
167
+ If you attempt to use this plugin to parse a URL that has an invalid character encoding in it, it will throw a `URIError` Exception. This will happen if the URL has a percentage sign followed by either a non-numeric character or a numeric value of greater than 80 (i.e. 128 in decimal).
168
+
169
+ If there is a chance you may end up parsing a badly encoded URL you should probably wrap your calls to this plugin in a try/catch block to prevent this causing unforseen problems.
170
+
171
+ Thanks to [steve78b](https://github.com/steve78b) for pointing this out.
172
+
173
+ Older versions and compatability
174
+ ---------------------------------
175
+
176
+ Please note that v2.x is **not** backwards compatible with v1.x of this plugin. v1.1 is still [available for download](https://github.com/allmarkedup/jQuery-URL-Parser/zipball/v1.1) should you need it for some reason.
177
+
178
+ Testing
179
+ -------
180
+
181
+ @omarqureshi has kindly contributed some unit tests, which can be run using [http://busterjs.org](buster.js). The tests only currently cover the non-jQuery version.
182
+
183
+ To run you'll need to have Buster installed (requires node and npm);
184
+
185
+ ```
186
+ $ npm install -g buster
187
+ ```
188
+
189
+ Once it's installed, just do:
190
+
191
+ ```
192
+ $ cd /path/to/jQuery-URL-Parser
193
+ $ buster static
194
+ ```
195
+
196
+ Buster will then start up a server and give you a url (like `http://localhost:8956`) which you can navigate to with your browser of choice to see the test results.
197
+
198
+
199
+
200
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/JQueryUrlParserRails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "jQuery-URL-Parser-Rails"
6
+ gem.version = JQueryUrlParserRails::VERSION
7
+ gem.authors = ["Dirk Eisenberg"]
8
+ gem.email = ["dirk.eisenberg@gmail.com"]
9
+ gem.description = %q{Simple way to integrate the url parameters jquery plugin in the asset pipeline of rails}
10
+ gem.summary = "Simple way to integrate the url parameters jquery plugin in the asset pipeline of rails"
11
+ gem.homepage = 'https://github.com/dei79/jQuery-URL-Parser-Rails'
12
+ gem.license = "MIT"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ if File.exists?('UPGRADING')
20
+ gem.post_install_message = File.read('UPGRADING')
21
+ end
22
+
23
+ gem.add_dependency "railties", "~> 3.1"
24
+ end
@@ -0,0 +1,271 @@
1
+ /*
2
+ * JQuery URL Parser plugin, v2.2.1
3
+ * Developed and maintanined by Mark Perkins, mark@allmarkedup.com
4
+ * Source repository: https://github.com/allmarkedup/jQuery-URL-Parser
5
+ * Licensed under an MIT-style license. See https://github.com/allmarkedup/jQuery-URL-Parser/blob/master/LICENSE for details.
6
+ */
7
+
8
+ ;(function(factory) {
9
+ if (typeof define === 'function' && define.amd) {
10
+ // AMD available; use anonymous module
11
+ if ( typeof jQuery !== 'undefined' ) {
12
+ define(['jquery'], factory);
13
+ } else {
14
+ define([], factory);
15
+ }
16
+ } else {
17
+ // No AMD available; mutate global vars
18
+ if ( typeof jQuery !== 'undefined' ) {
19
+ factory(jQuery);
20
+ } else {
21
+ factory();
22
+ }
23
+ }
24
+ })(function($, undefined) {
25
+
26
+ var tag2attr = {
27
+ a : 'href',
28
+ img : 'src',
29
+ form : 'action',
30
+ base : 'href',
31
+ script : 'src',
32
+ iframe : 'src',
33
+ link : 'href'
34
+ },
35
+
36
+ key = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'fragment'], // keys available to query
37
+
38
+ aliases = { 'anchor' : 'fragment' }, // aliases for backwards compatability
39
+
40
+ parser = {
41
+ strict : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, //less intuitive, more accurate to the specs
42
+ loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
43
+ },
44
+
45
+ toString = Object.prototype.toString,
46
+
47
+ isint = /^[0-9]+$/;
48
+
49
+ function parseUri( url, strictMode ) {
50
+ var str = decodeURI( url ),
51
+ res = parser[ strictMode || false ? 'strict' : 'loose' ].exec( str ),
52
+ uri = { attr : {}, param : {}, seg : {} },
53
+ i = 14;
54
+
55
+ while ( i-- ) {
56
+ uri.attr[ key[i] ] = res[i] || '';
57
+ }
58
+
59
+ // build query and fragment parameters
60
+ uri.param['query'] = parseString(uri.attr['query']);
61
+ uri.param['fragment'] = parseString(uri.attr['fragment']);
62
+
63
+ // split path and fragement into segments
64
+ uri.seg['path'] = uri.attr.path.replace(/^\/+|\/+$/g,'').split('/');
65
+ uri.seg['fragment'] = uri.attr.fragment.replace(/^\/+|\/+$/g,'').split('/');
66
+
67
+ // compile a 'base' domain attribute
68
+ uri.attr['base'] = uri.attr.host ? (uri.attr.protocol ? uri.attr.protocol+'://'+uri.attr.host : uri.attr.host) + (uri.attr.port ? ':'+uri.attr.port : '') : '';
69
+
70
+ return uri;
71
+ };
72
+
73
+ function getAttrName( elm ) {
74
+ var tn = elm.tagName;
75
+ if ( typeof tn !== 'undefined' ) return tag2attr[tn.toLowerCase()];
76
+ return tn;
77
+ }
78
+
79
+ function promote(parent, key) {
80
+ if (parent[key].length == 0) return parent[key] = {};
81
+ var t = {};
82
+ for (var i in parent[key]) t[i] = parent[key][i];
83
+ parent[key] = t;
84
+ return t;
85
+ }
86
+
87
+ function parse(parts, parent, key, val) {
88
+ var part = parts.shift();
89
+ if (!part) {
90
+ if (isArray(parent[key])) {
91
+ parent[key].push(val);
92
+ } else if ('object' == typeof parent[key]) {
93
+ parent[key] = val;
94
+ } else if ('undefined' == typeof parent[key]) {
95
+ parent[key] = val;
96
+ } else {
97
+ parent[key] = [parent[key], val];
98
+ }
99
+ } else {
100
+ var obj = parent[key] = parent[key] || [];
101
+ if (']' == part) {
102
+ if (isArray(obj)) {
103
+ if ('' != val) obj.push(val);
104
+ } else if ('object' == typeof obj) {
105
+ obj[keys(obj).length] = val;
106
+ } else {
107
+ obj = parent[key] = [parent[key], val];
108
+ }
109
+ } else if (~part.indexOf(']')) {
110
+ part = part.substr(0, part.length - 1);
111
+ if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
112
+ parse(parts, obj, part, val);
113
+ // key
114
+ } else {
115
+ if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
116
+ parse(parts, obj, part, val);
117
+ }
118
+ }
119
+ }
120
+
121
+ function merge(parent, key, val) {
122
+ if (~key.indexOf(']')) {
123
+ var parts = key.split('['),
124
+ len = parts.length,
125
+ last = len - 1;
126
+ parse(parts, parent, 'base', val);
127
+ } else {
128
+ if (!isint.test(key) && isArray(parent.base)) {
129
+ var t = {};
130
+ for (var k in parent.base) t[k] = parent.base[k];
131
+ parent.base = t;
132
+ }
133
+ set(parent.base, key, val);
134
+ }
135
+ return parent;
136
+ }
137
+
138
+ function parseString(str) {
139
+ return reduce(String(str).split(/&|;/), function(ret, pair) {
140
+ try {
141
+ pair = decodeURIComponent(pair.replace(/\+/g, ' '));
142
+ } catch(e) {
143
+ // ignore
144
+ }
145
+ var eql = pair.indexOf('='),
146
+ brace = lastBraceInKey(pair),
147
+ key = pair.substr(0, brace || eql),
148
+ val = pair.substr(brace || eql, pair.length),
149
+ val = val.substr(val.indexOf('=') + 1, val.length);
150
+
151
+ if ('' == key) key = pair, val = '';
152
+
153
+ return merge(ret, key, val);
154
+ }, { base: {} }).base;
155
+ }
156
+
157
+ function set(obj, key, val) {
158
+ var v = obj[key];
159
+ if (undefined === v) {
160
+ obj[key] = val;
161
+ } else if (isArray(v)) {
162
+ v.push(val);
163
+ } else {
164
+ obj[key] = [v, val];
165
+ }
166
+ }
167
+
168
+ function lastBraceInKey(str) {
169
+ var len = str.length,
170
+ brace, c;
171
+ for (var i = 0; i < len; ++i) {
172
+ c = str[i];
173
+ if (']' == c) brace = false;
174
+ if ('[' == c) brace = true;
175
+ if ('=' == c && !brace) return i;
176
+ }
177
+ }
178
+
179
+ function reduce(obj, accumulator){
180
+ var i = 0,
181
+ l = obj.length >> 0,
182
+ curr = arguments[2];
183
+ while (i < l) {
184
+ if (i in obj) curr = accumulator.call(undefined, curr, obj[i], i, obj);
185
+ ++i;
186
+ }
187
+ return curr;
188
+ }
189
+
190
+ function isArray(vArg) {
191
+ return Object.prototype.toString.call(vArg) === "[object Array]";
192
+ }
193
+
194
+ function keys(obj) {
195
+ var keys = [];
196
+ for ( prop in obj ) {
197
+ if ( obj.hasOwnProperty(prop) ) keys.push(prop);
198
+ }
199
+ return keys;
200
+ }
201
+
202
+ function purl( url, strictMode ) {
203
+ if ( arguments.length === 1 && url === true ) {
204
+ strictMode = true;
205
+ url = undefined;
206
+ }
207
+ strictMode = strictMode || false;
208
+ url = url || window.location.toString();
209
+
210
+ return {
211
+
212
+ data : parseUri(url, strictMode),
213
+
214
+ // get various attributes from the URI
215
+ attr : function( attr ) {
216
+ attr = aliases[attr] || attr;
217
+ return typeof attr !== 'undefined' ? this.data.attr[attr] : this.data.attr;
218
+ },
219
+
220
+ // return query string parameters
221
+ param : function( param ) {
222
+ return typeof param !== 'undefined' ? this.data.param.query[param] : this.data.param.query;
223
+ },
224
+
225
+ // return fragment parameters
226
+ fparam : function( param ) {
227
+ return typeof param !== 'undefined' ? this.data.param.fragment[param] : this.data.param.fragment;
228
+ },
229
+
230
+ // return path segments
231
+ segment : function( seg ) {
232
+ if ( typeof seg === 'undefined' ) {
233
+ return this.data.seg.path;
234
+ } else {
235
+ seg = seg < 0 ? this.data.seg.path.length + seg : seg - 1; // negative segments count from the end
236
+ return this.data.seg.path[seg];
237
+ }
238
+ },
239
+
240
+ // return fragment segments
241
+ fsegment : function( seg ) {
242
+ if ( typeof seg === 'undefined' ) {
243
+ return this.data.seg.fragment;
244
+ } else {
245
+ seg = seg < 0 ? this.data.seg.fragment.length + seg : seg - 1; // negative segments count from the end
246
+ return this.data.seg.fragment[seg];
247
+ }
248
+ }
249
+
250
+ };
251
+
252
+ };
253
+
254
+ if ( typeof $ !== 'undefined' ) {
255
+
256
+ $.fn.url = function( strictMode ) {
257
+ var url = '';
258
+ if ( this.length ) {
259
+ url = $(this).attr( getAttrName(this[0]) ) || '';
260
+ }
261
+ return purl( url, strictMode );
262
+ };
263
+
264
+ $.url = purl;
265
+
266
+ } else {
267
+ window.purl = purl;
268
+ }
269
+
270
+ });
271
+
@@ -0,0 +1,6 @@
1
+ # load rails
2
+ require 'rails'
3
+
4
+ # it's an engine
5
+ require 'JQueryUrlParserRails/engine'
6
+ require 'JQueryUrlParserRails/version'
@@ -0,0 +1,6 @@
1
+ require "JQueryUrlParserRails/version"
2
+
3
+ module JQueryUrlParserRails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module JQueryUrlParserRails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,13 @@
1
+ var config = module.exports;
2
+
3
+ config["Tests"] = {
4
+ rootPath: "../",
5
+ environment: "browser",
6
+ sources: [
7
+ "purl.js"
8
+ ],
9
+
10
+ tests: [
11
+ "test/purl-tests.js"
12
+ ]
13
+ }
@@ -0,0 +1,79 @@
1
+ buster.spec.expose();
2
+
3
+ testSuite = function(url) {
4
+ it('should have a protocol of http', function() {
5
+ expect(url.attr('protocol')).toBe('http');
6
+ });
7
+
8
+ it('should have a path of /folder/dir/index.html', function() {
9
+ expect(url.attr('path')).toBe('/folder/dir/index.html');
10
+ });
11
+
12
+ /* should it? */
13
+ it('should have an unset port', function() {
14
+ expect(url.attr('port')).toBe('');
15
+ });
16
+
17
+ it('should have an host of allmarkedup.com', function() {
18
+ expect(url.attr('host')).toBe('allmarkedup.com');
19
+ });
20
+
21
+ it('should have a relative path of /folder/dir/index.html?item=value#foo', function() {
22
+ expect(url.attr('relative')).toBe('/folder/dir/index.html?item=value#foo');
23
+ });
24
+
25
+ it('should have a path of /folder/dir/index.html', function() {
26
+ expect(url.attr('path')).toBe('/folder/dir/index.html');
27
+ });
28
+
29
+ it('should have a directory of /folder/dir/', function() {
30
+ expect(url.attr('directory')).toBe('/folder/dir/');
31
+ });
32
+
33
+ it('should have a file of index.html', function() {
34
+ expect(url.attr('file')).toBe('index.html');
35
+ });
36
+
37
+ it('should have a querystring of item=value', function() {
38
+ expect(url.attr('query')).toBe('item=value');
39
+ });
40
+
41
+ it('should have an anchor of foo', function() {
42
+ expect(url.attr('anchor')).toBe('foo');
43
+ expect(url.attr('fragment')).toBe('foo');
44
+ });
45
+
46
+ it('should have a param() of item: "value"', function() {
47
+ expect(url.param()).toBeObject({item: 'value'})
48
+ });
49
+
50
+ it('should have a param("item") of "value"', function() {
51
+ expect(url.param('item')).toBe('value')
52
+ });
53
+
54
+ it('should have a segment() of ["folder","dir","index.html"]', function() {
55
+ expect(url.segment()).toEqual(["folder","dir","index.html"])
56
+ });
57
+
58
+ it('should have a segment(1) of "folder"', function() {
59
+ expect(url.segment(1)).toBe("folder");
60
+ });
61
+
62
+ it('should have a segment(-1) of "folder"', function() {
63
+ expect(url.segment(-1)).toBe("index.html");
64
+ });
65
+ }
66
+
67
+ describe("purl in non-strict mode", function () {
68
+
69
+ testSuite(purl('http://allmarkedup.com/folder/dir/index.html?item=value#foo'));
70
+
71
+ });
72
+
73
+
74
+ describe("purl in strict mode", function () {
75
+
76
+ testSuite(purl('http://allmarkedup.com/folder/dir/index.html?item=value#foo',
77
+ true));
78
+
79
+ });
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jQuery-URL-Parser-Rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dirk Eisenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: Simple way to integrate the url parameters jquery plugin in the asset
31
+ pipeline of rails
32
+ email:
33
+ - dirk.eisenberg@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .idea/jQuery-URL-Parser-Rails.iml
40
+ - LICENSE
41
+ - README.md
42
+ - jQuery-URL-Parser-Rails.gemspec
43
+ - lib/assets/javascripts/purl.js
44
+ - lib/jQuery-URL-Parser-Rails.rb
45
+ - lib/jQueryURLParserRails/engine.rb
46
+ - lib/jQueryURLParserRails/version.rb
47
+ - test/buster.js
48
+ - test/purl-tests.js
49
+ homepage: https://github.com/dei79/jQuery-URL-Parser-Rails
50
+ licenses:
51
+ - MIT
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.23
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Simple way to integrate the url parameters jquery plugin in the asset pipeline
74
+ of rails
75
+ test_files:
76
+ - test/buster.js
77
+ - test/purl-tests.js