angular_url_parser_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 963fd33277a5fa7a144b73be6fe592d37138add6
4
+ data.tar.gz: 732abc229fe1e1ccc68385080d715d02896c9603
5
+ SHA512:
6
+ metadata.gz: 2cc2176ef15e94b1b07f81902d97e8881e0b994952c8b2ee0545e1d7e09a294ec9728fe6e9d09540bc7596c9f6a62aee194b0e443e7b88b83bb12cd5cfd7b56d
7
+ data.tar.gz: 4b8a96b3a8fe1242d3b113116ab15ca999f34e955f3059ce77b61a7f65850513729873007ce96e034fd2387d04068a7b64c07dd7e5f6ecbd540983dda07864a8
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular_url_parser_rails.gemspec
4
+ gemspec
@@ -0,0 +1,66 @@
1
+ # Angular URL parser
2
+ Angular service to get simple methods to manipulate url parts
3
+
4
+ > Demo: http://yllieth.github.io/angular-url-parser/app/index.html
5
+
6
+ ## Installation
7
+
8
+ In your `Gemfile`, add the following line:
9
+ ```ruby
10
+ gem 'angular_url_parser_rails'
11
+ ```
12
+
13
+ In your `application.js`, add the following line:
14
+ ```
15
+ //= require angular-url-parser
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```javascript
21
+ angular
22
+ .module('YOUR-ANGULAR-APP-NAME', [
23
+ 'ngUrlParser'
24
+ ])
25
+ .controller('demoCtrl', function(urlParser) {
26
+ this.parts = urlParser.parse();
27
+ this.protocol = urlParser.getProtocol();
28
+ this.host = urlParser.getHost();
29
+ this.hostname = urlParser.getHostname();
30
+ this.port = urlParser.getPort();
31
+ this.route = urlParser.getRoute();
32
+ this.routeAttributes = urlParser.getRouteAttributes();
33
+ this.queryString = urlParser.getQuerystring();
34
+ this.option = urlParser.getOption();
35
+ this.hash = urlParser.getHash();
36
+ })
37
+ ```
38
+
39
+ - `getProtocol([string] url): string` : Return the protocol of the given url - Example: _"http:"_, _"https:"_, ...
40
+ - `getHost([string] url): string` : Return the host of the given url (without port) - Example: _"github.com"_, _"localhost"_, ...
41
+ - `getHostname([string] url): string` : Return the hostname of the given url (with port) - Example: _"github.com"_, _"localhost:3000"_, ...
42
+ - `getPort([string] url): string` : Return the port of the given url - Example: _""_, _"3000"_, ...
43
+ - `getRoute([string] url): string` : Return the main parts of the given url
44
+ - `getRouteAttributes([string] url): array` : Return the list of parts of the given url
45
+ - `getQuerystring([string] url): string` : Return the part of the given url with options
46
+ - `getOption([string] param, [string] url): object|string` : Return a specific option in the url's options, or all options in an object
47
+ - `getHash([string] url): string` : Return the hash of the given url
48
+ - `parse([string] url): object` : Return parsed url in an object:
49
+ ```json
50
+ // urlParser.parse('http://localhost:3000/models?sort=asc#quantiles')
51
+
52
+ {
53
+ "protocol": "http:",
54
+ "host": "localhost:3000",
55
+ "hostname": "localhost",
56
+ "port": "3000",
57
+ "pathname": "/models",
58
+ "search": "?sort=asc",
59
+ "searchObject": { "sort": "asc" },
60
+ "hash": "quantiles"
61
+ }
62
+ ```
63
+
64
+ # Contributing
65
+
66
+ See https://github.com/yllieth/angular-url-parser
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'angular_url_parser_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "angular_url_parser_rails"
8
+ spec.version = AngularUrlParserRails::VERSION
9
+ spec.authors = ["Sylvain RAGOT"]
10
+ spec.email = ["sylvnimes@hotmail.com"]
11
+
12
+ spec.summary = %q{Get simple methods to manipulate url parts}
13
+ spec.description = %q{Get simple methods to manipulate url parts}
14
+ spec.homepage = "https://github.com/yllieth/angular-url-parser"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "angular_url_parser_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "angular_url_parser_rails/version"
2
+
3
+ module AngularUrlParserRails
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module AngularUrlParserRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Angular service to get simple methods to manipulate url parts
3
+ *
4
+ * @version 0.0.2 - 2016-07-27
5
+ * @link https://github.com/yllieth/angular-url-parser
6
+ * @license MIT License, http://www.opensource.org/licenses/MIT
7
+ */
8
+ angular
9
+ .module('ngUrlParser', [])
10
+ .factory('urlParser', function () {
11
+ 'use strict';
12
+
13
+ function urlParser(url) {
14
+ var parser = document.createElement('a'), searchObject = {}, queries, split, i;
15
+
16
+ // Let the browser do the work
17
+ parser.href = url;
18
+
19
+ // Convert query string to object
20
+ queries = parser.search.replace(/^\?/, '').split('&');
21
+
22
+ for( i = 0; i < queries.length; i++ ) {
23
+ split = queries[i].split('=');
24
+ searchObject[split[0]] = split[1];
25
+ }
26
+
27
+ return {
28
+ protocol: parser.protocol, // ex: http:
29
+ host: parser.host, // ex: localhost:3000
30
+ hostname: parser.hostname, // ex: localhost
31
+ port: parser.port, // ex: 3000
32
+ pathname: parser.pathname, // ex: /models
33
+ search: parser.search,
34
+ searchObject: searchObject,
35
+ hash: parser.hash
36
+ };
37
+ }
38
+
39
+ return {
40
+ /**
41
+ * Returns an object with url parts placed in different properties
42
+ *
43
+ * @param {string} [url] - location.href if not specified
44
+ * @returns {{protocol, host, hostname, port, pathname, search, searchObject, hash}}
45
+ */
46
+ parse: function (url) {
47
+ url = url || window.location.href;
48
+ return urlParser(url);
49
+ },
50
+
51
+ /**
52
+ * Returns the protocol part of the given url
53
+ *
54
+ * Example:
55
+ * > Input: 'http://localhost:3000/models?sort=asc'
56
+ * > Output: 'http:'
57
+ *
58
+ * @param {string} [url] - location.href if not specified
59
+ * @returns {string}
60
+ */
61
+ getProtocol: function (url) {
62
+ url = url || window.location.href;
63
+ return this.parse(url).protocol;
64
+ },
65
+
66
+ /**
67
+ * Returns the host part of the given url
68
+ *
69
+ * Example:
70
+ * > Input: 'http://localhost:3000/models?sort=asc'
71
+ * > Output: 'localhost:3000'
72
+ *
73
+ * @param {string} [url] - location.href if not specified
74
+ * @returns {string}
75
+ */
76
+ getHost: function (url) {
77
+ url = url || window.location.href;
78
+ return this.parse(url).host;
79
+ },
80
+
81
+ /**
82
+ * Returns the hostname part of the given url
83
+ *
84
+ * Example:
85
+ * > Input: 'http://localhost:3000/models?sort=asc'
86
+ * > Output: 'localhost'
87
+ *
88
+ * @param {string} [url] - location.href if not specified
89
+ * @returns {string}
90
+ */
91
+ getHostname: function (url) {
92
+ url = url || window.location.href;
93
+ return this.parse(url).hostname;
94
+ },
95
+
96
+ /**
97
+ * Returns the port of the given url
98
+ *
99
+ * Example:
100
+ * > Input: 'http://localhost:3000/models?sort=asc'
101
+ * > Output: '3000'
102
+ *
103
+ * @param {string} [url] - location.href if not specified
104
+ * @returns {string}
105
+ */
106
+ getPort: function (url) {
107
+ url = url || window.location.href;
108
+ return this.parse(url).port;
109
+ },
110
+
111
+ /**
112
+ * Returns the pathname part of the given url
113
+ *
114
+ * Example:
115
+ * > Input: 'http://localhost:3000/models?sort=asc'
116
+ * > Output: '/models'
117
+ *
118
+ * @param {string} [url] - location.href if not specified
119
+ * @returns {string}
120
+ */
121
+ getRoute: function (url) {
122
+ url = url || window.location.href;
123
+ return this.parse(url).pathname;
124
+ },
125
+
126
+ /**
127
+ * Returns the list of element in the pathname part of the given url
128
+ *
129
+ * Example:
130
+ * > Input: 'http://localhost:3000/models/047256ce-850c-4408-83eb-4da873690b1c?sort=asc'
131
+ * > Output: ['models', '047256ce-850c-4408-83eb-4da873690b1c']
132
+ *
133
+ * @param {string} [url] - location.href if not specified
134
+ * @returns {Array}
135
+ */
136
+ getRouteAttributes: function(url) {
137
+ return this.getRoute(url).split('/');
138
+ },
139
+
140
+ /**
141
+ * Returns the query part of the given url
142
+ *
143
+ * Example:
144
+ * > Input: 'http://localhost:3000/models?sort=asc'
145
+ * > Output: '?sort=asc'
146
+ *
147
+ * @param {string} [url] - location.href if not specified
148
+ * @returns {string}
149
+ */
150
+ getQuerystring: function (url) {
151
+ url = url || window.location.href;
152
+ return this.parse(url).search;
153
+ },
154
+
155
+ /**
156
+ * Returns a single option or the whole query string of the given url
157
+ *
158
+ * Example:
159
+ * > Input: 'http://localhost:3000/models?sort=asc'
160
+ * > Output: {sort: 'asc'}
161
+ *
162
+ * > Input: 'http://localhost:3000/models?sort=asc' - sort
163
+ * > Output: 'asc'
164
+ *
165
+ * @param {string} [param] -
166
+ * @param {string} [url] - location.href if not specified
167
+ * @returns {object} if param is not defined
168
+ * @returns {string} if param is a valid parameter of the given url
169
+ */
170
+ getOption: function (param, url) {
171
+ url = url || window.location.href;
172
+
173
+ var searchOject = this.parse(url).searchObject;
174
+
175
+ if (typeof param === 'string') {
176
+ return (searchOject.hasOwnProperty(param) === true)
177
+ ? searchOject[param]
178
+ : null;
179
+ } else {
180
+ return searchOject;
181
+ }
182
+ },
183
+
184
+ /**
185
+ * Returns the hash part of the given url
186
+ *
187
+ * Example:
188
+ * > Input: 'http://localhost:3000/models?sort=asc#quantiles'
189
+ * > Output: 'quantiles'
190
+ *
191
+ * @param {string} [url] - location.href if not specified
192
+ * @returns {string}
193
+ */
194
+ getHash: function (url) {
195
+ url = url || window.location.href;
196
+ return this.parse(url).hash;
197
+ }
198
+ };
199
+ });
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular_url_parser_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sylvain RAGOT
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Get simple methods to manipulate url parts
42
+ email:
43
+ - sylvnimes@hotmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".idea/vcs.xml"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - angular_url_parser_rails.gemspec
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/angular_url_parser_rails.rb
57
+ - lib/angular_url_parser_rails/version.rb
58
+ - vendor/assets/javascripts/angular-url-parser.js
59
+ homepage: https://github.com/yllieth/angular-url-parser
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Get simple methods to manipulate url parts
82
+ test_files: []