url-resolver 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +60 -2
- data/lib/url-resolver.rb +15 -16
- data/lib/url-resolver/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4d3d0a1522053daf7c576fc4916b6b1348ccde7
|
4
|
+
data.tar.gz: ec934c75d42624fa974e0a3f45d9b550d923095a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537d12ab6ae16036806c35c8e945084a47840fb1b390525140d568b722578558a99ef44cf1f7b5a767d73fe8806908ade75dcfe8e0fed410a5bb845fc6d0920a
|
7
|
+
data.tar.gz: 7be23d8465e2fc600473dbe28af380c299272751eeba2b43597a57f7bd21db6d70622e5614529e7ec62fbe33a61e158d56ac6f1ad3f387310fabf056b53dc26b
|
data/README.md
CHANGED
@@ -2,8 +2,66 @@
|
|
2
2
|
[](https://codeclimate.com/github/alexpchin/url-resolver)
|
3
3
|
[](https://codeclimate.com/github/alexpchin/url-resolver)
|
4
4
|
|
5
|
-
##
|
5
|
+
## UPDATE
|
6
|
+
I've noticed from this [stackoverflow article](http://stackoverflow.com/questions/4861517/getting-the-absolute-url-when-extracting-links) that you can actually use Ruby's URI library to resolve paths:
|
7
|
+
|
8
|
+
```
|
9
|
+
absolute_uri = URI.join(page_url, href).to_s
|
10
|
+
```
|
11
|
+
|
12
|
+
This gem was created quickly as part of another project and I missed this fact.
|
13
|
+
|
14
|
+
```
|
15
|
+
require 'uri'
|
6
16
|
|
17
|
+
# The URL of the page with the links
|
18
|
+
page_url = 'http://foo.com/zee/zaw/zoom.html'
|
19
|
+
|
20
|
+
# A variety of links to test.
|
21
|
+
hrefs = %w[
|
22
|
+
http://zork.com/ http://zork.com/#id
|
23
|
+
http://zork.com/bar http://zork.com/bar#id
|
24
|
+
http://zork.com/bar/ http://zork.com/bar/#id
|
25
|
+
http://zork.com/bar/jim.html http://zork.com/bar/jim.html#id
|
26
|
+
/bar /bar#id
|
27
|
+
/bar/ /bar/#id
|
28
|
+
/bar/jim.html /bar/jim.html#id
|
29
|
+
jim.html jim.html#id
|
30
|
+
../jim.html ../jim.html#id
|
31
|
+
../ ../#id
|
32
|
+
#id
|
33
|
+
]
|
34
|
+
|
35
|
+
hrefs.each do |href|
|
36
|
+
root_href = URI.join(page_url,href).to_s
|
37
|
+
puts "%-32s -> %s" % [ href, root_href ]
|
38
|
+
end
|
39
|
+
#=> http://zork.com/ -> http://zork.com/
|
40
|
+
#=> http://zork.com/#id -> http://zork.com/#id
|
41
|
+
#=> http://zork.com/bar -> http://zork.com/bar
|
42
|
+
#=> http://zork.com/bar#id -> http://zork.com/bar#id
|
43
|
+
#=> http://zork.com/bar/ -> http://zork.com/bar/
|
44
|
+
#=> http://zork.com/bar/#id -> http://zork.com/bar/#id
|
45
|
+
#=> http://zork.com/bar/jim.html -> http://zork.com/bar/jim.html
|
46
|
+
#=> http://zork.com/bar/jim.html#id -> http://zork.com/bar/jim.html#id
|
47
|
+
#=> /bar -> http://foo.com/bar
|
48
|
+
#=> /bar#id -> http://foo.com/bar#id
|
49
|
+
#=> /bar/ -> http://foo.com/bar/
|
50
|
+
#=> /bar/#id -> http://foo.com/bar/#id
|
51
|
+
#=> /bar/jim.html -> http://foo.com/bar/jim.html
|
52
|
+
#=> /bar/jim.html#id -> http://foo.com/bar/jim.html#id
|
53
|
+
#=> jim.html -> http://foo.com/zee/zaw/jim.html
|
54
|
+
#=> jim.html#id -> http://foo.com/zee/zaw/jim.html#id
|
55
|
+
#=> ../jim.html -> http://foo.com/zee/jim.html
|
56
|
+
#=> ../jim.html#id -> http://foo.com/zee/jim.html#id
|
57
|
+
#=> ../ -> http://foo.com/zee/
|
58
|
+
#=> ../#id -> http://foo.com/zee/#id
|
59
|
+
#=> #id -> http://foo.com/zee/zaw/zoom.html#id
|
60
|
+
```
|
61
|
+
|
62
|
+
So consider this gem as deprecated.
|
63
|
+
|
64
|
+
## Installation
|
7
65
|
Add this line to your application's Gemfile:
|
8
66
|
|
9
67
|
```ruby
|
@@ -23,7 +81,7 @@ Or install it yourself as:
|
|
23
81
|
To resolve a partial file path use:
|
24
82
|
|
25
83
|
```
|
26
|
-
UrlResolver
|
84
|
+
UrlResolver.resolve(url, path_to_resolve)
|
27
85
|
```
|
28
86
|
|
29
87
|
## Contributing
|
data/lib/url-resolver.rb
CHANGED
@@ -4,22 +4,21 @@ require "uri"
|
|
4
4
|
module UrlResolver
|
5
5
|
|
6
6
|
def self.resolve(url=nil, path_to_resolve=nil)
|
7
|
-
|
8
|
-
raise ArgumentError, "You need to provide a path to resolve." if path_to_resolve.nil?
|
7
|
+
URI.join(url, path_to_resolve).to_s
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
URI.join(url, path_to_resolve).to_s
|
15
|
-
end
|
16
|
-
else
|
17
|
-
path_to_resolve
|
18
|
-
end
|
19
|
-
end
|
9
|
+
## Deprecated
|
10
|
+
# raise ArgumentError, "You need to provide a root url." if url.nil?
|
11
|
+
# raise ArgumentError, "You need to provide a path to resolve." if path_to_resolve.nil?
|
20
12
|
|
21
|
-
|
13
|
+
# if !path_to_resolve.include?("http")
|
14
|
+
# if path_to_resolve.include?("//")
|
15
|
+
# "http:#{path_to_resolve}"
|
16
|
+
# else
|
17
|
+
# URI.join(url, path_to_resolve).to_s
|
18
|
+
# end
|
19
|
+
# else
|
20
|
+
# path_to_resolve
|
21
|
+
# end
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
# Could use Regex at some point
|
25
|
-
# [/^http/], [/^\/\//]
|
24
|
+
end
|
data/lib/url-resolver/version.rb
CHANGED