nokogiri-html-ext 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b391309327d894afb0495dd2fcbe3e3555a0c41bd21937af25a134e0ad1d27ec
4
- data.tar.gz: 16e6cd74fd4485610a239edd904318973125de3225a1a5beca69a311fb79eda5
3
+ metadata.gz: 0aef0b60a4c542ff9bd3ee541ed06b42c6f758c9bfd8631c7fecccda288d01d5
4
+ data.tar.gz: d0bbda1b35409f6c9297fdcd9811dc7387d69f8cc980d9484aaa21deae4e2410
5
5
  SHA512:
6
- metadata.gz: dc29f44a0ed51d136b5c7e44ff646bfc6d024ac66308b7f539ce64e3ceaad3fe78faed345842946ed538ab4d4dd673a5d831a1cf2f1cc9689c429689c5815c0f
7
- data.tar.gz: 2e4ec5bba2a5678f854194ea5d1c1c3a054fd5ae11e62d61f6992f0a52afe87ba239abc6f5114a5e6494a3e1cab1fac0f42a9fe81a79e490f21b77bd63e24161
6
+ metadata.gz: c5d116103b9806d3b31d72b5d5caeeb806c077ac704d2a8d61a7fdefe8f819be1beea0f255912a642542a4a7fbbcc1ba80ef1c3e02309a439b8258700040279a
7
+ data.tar.gz: 669115b6d27c9e217f2ed0f993c1cf61dc957e6850c42706de522afa964d7fe651d17b3805d1439e270a0e58b028abaacfc58ddd4f1d30520bd012005b7336c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.2.0 / 2022-07-02
4
+
5
+ - Make `resolve_relative_url` method public (d132dd3)
6
+
3
7
  ## v0.1.0 / 2022-07-01
4
8
 
5
9
  - Initial release! 🎉
data/README.md CHANGED
@@ -43,6 +43,8 @@ gem install nokogiri-html-ext
43
43
  nokogiri-html-ext provides two helper methods for getting and setting a document's `<base>` element's `href` attribute. The first, `base_href`, retrieves the element's `href` attribute value if it exists.
44
44
 
45
45
  ```ruby
46
+ require 'nokogiri/html-ext'
47
+
46
48
  doc = Nokogiri::HTML('<html><body>Hello, world!</body></html>')
47
49
 
48
50
  doc.base_href
@@ -62,6 +64,8 @@ doc.base_href
62
64
  The `base_href=` method allows you to manipulate the document's `<base>` element.
63
65
 
64
66
  ```ruby
67
+ require 'nokogiri/html-ext'
68
+
65
69
  doc = Nokogiri::HTML('<html><body>Hello, world!</body></html>')
66
70
 
67
71
  doc.base_href = '/foo'
@@ -92,6 +96,8 @@ URL resolution uses Ruby's built-in URL parsing and normalizing capabilities. Ab
92
96
  An abbreviated example:
93
97
 
94
98
  ```ruby
99
+ require 'nokogiri/html-ext'
100
+
95
101
  markup = <<-HTML
96
102
  <html>
97
103
  <body>
@@ -124,6 +130,17 @@ doc.at_css('img').to_s
124
130
  #=> "<img src=\"https://jgarber.example/foo.png\" srcset=\"https://jgarber.example/foo/bar.png 720w\">"
125
131
  ```
126
132
 
133
+ ### `resolve_relative_url`
134
+
135
+ You may also resolve an arbitrary `String` representing a relative URL against the document's URL (or `<base>` element's `href` attribute value):
136
+
137
+ ```ruby
138
+ doc = Nokogiri::HTML('<html><base href="/foo/bar"></html>', 'https://jgarber.example')
139
+
140
+ doc.resolve_relative_url('biz/baz')
141
+ #=> "https://jgarber.example/foo/biz/baz"
142
+ ```
143
+
127
144
  ## Contributing
128
145
 
129
146
  Interested in helping improve nokogiri-html-ext? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/jgarber623/nokogiri-html-ext/blob/main/CONTRIBUTING.md) for details.
@@ -63,6 +63,21 @@ module Nokogiri
63
63
  end
64
64
  end
65
65
 
66
+ # Convert a relative URL to an absolute URL.
67
+ #
68
+ # @param url [String, #to_s]
69
+ #
70
+ # @return [String]
71
+ def resolve_relative_url(url)
72
+ url_str = url.to_s
73
+
74
+ uri_parser.unescape(
75
+ uri_parser.join(*[document.url.strip, base_href, url_str].compact.map { |u| uri_parser.escape(u) })
76
+ .normalize
77
+ .to_s
78
+ )
79
+ end
80
+
66
81
  # Convert the document's relative URLs to absolute URLs.
67
82
  #
68
83
  # @return [self]
@@ -84,14 +99,6 @@ module Nokogiri
84
99
 
85
100
  private
86
101
 
87
- def resolve_relative_url(url)
88
- uri_parser.unescape(
89
- uri_parser.join(*[document.url.strip, base_href, url].compact.map { |u| uri_parser.escape(u) })
90
- .normalize
91
- .to_s
92
- )
93
- end
94
-
95
102
  def resolve_relative_urls_for(attributes_map)
96
103
  attributes_map.each do |attribute, names|
97
104
  xpaths = names.map { |name| "//#{name}[@#{attribute}]" }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nokogiri
4
4
  module HTMLExt
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-html-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -44,7 +44,7 @@ licenses:
44
44
  - MIT
45
45
  metadata:
46
46
  bug_tracker_uri: https://github.com/jgarber623/nokogiri-html-ext/issues
47
- changelog_uri: https://github.com/jgarber623/nokogiri-html-ext/blob/v0.1.0/CHANGELOG.md
47
+ changelog_uri: https://github.com/jgarber623/nokogiri-html-ext/blob/v0.2.0/CHANGELOG.md
48
48
  rubygems_mfa_required: 'true'
49
49
  post_install_message:
50
50
  rdoc_options: []