microformats 4.0.0 → 4.0.1

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
  SHA1:
3
- metadata.gz: 5c09dd3a9534b0c5a36897e4be9b8897c893fd0c
4
- data.tar.gz: 5399942d007058cc68e35051ee38647594939df5
3
+ metadata.gz: 1c0e2d46df6df0a2df0e8dfa27d33e61e1327d1f
4
+ data.tar.gz: 0e1ad7b965a34f19fd3593f4740d93751c9ec022
5
5
  SHA512:
6
- metadata.gz: d2a67b6925a3109f46dbecf6eb0a2283ba88b23e00f66d54f93d083cef7af0fa96840982a7833db0f77afdbd5b0a306e9fab482dfb027c5b04d43dc0fd7e32ad
7
- data.tar.gz: 88f38a7593acc3393c58e1f1412e9f54e5b1ece357fda1596de67b2a13fb2dcd26c503a4435568bc3a66ebc73bd4d1146721c9b604b8beb9fd96bbe1f0bbbb95
6
+ metadata.gz: f5dc7e236af033b40fdf763c2682588ed08fce8fe6e38fbfcd3c32512e978835e87865780ca667a979e275ce28afe656d9a554298cd2389a2ab4e53369b83c08
7
+ data.tar.gz: 6a5f738f750ff5d66a444a86db2b2ba86771073c58ed215fbce9f91a5da95ff24170ef0318abb32f6ec2ab84c9caab1a3cd0b865a07c8526867bea1fe862a112
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  coverage
19
+ *.swp
data/README.md CHANGED
@@ -34,9 +34,9 @@ Not Implemented:
34
34
 
35
35
  ## Current Version
36
36
 
37
- 4.0.0
37
+ 4.0.1
38
38
 
39
- ![Version 4.0.0](https://img.shields.io/badge/VERSION-4.0.0-green.svg)
39
+ ![Version 4.0.1](https://img.shields.io/badge/VERSION-4.0.1-green.svg)
40
40
 
41
41
 
42
42
  ## Requirements
@@ -10,9 +10,9 @@ module Microformats
10
10
  end
11
11
 
12
12
  def absolutize
13
- #TODO: i'm sure this could be improved a bit
14
- return nil if relative.nil? or relative == ""
13
+ return base if relative.nil? or relative == ""
15
14
  return relative if relative =~ /^https?:\/\//
15
+ return base + relative if relative =~ /^#/
16
16
 
17
17
  uri = URI.parse(relative)
18
18
 
@@ -28,11 +28,11 @@ module Microformats
28
28
  document.traverse do |node|
29
29
  if not node.attribute('src').nil?
30
30
  absolute_url = Microformats::AbsoluteUri.new(node.attribute('src').value.to_s, base: @base).absolutize
31
- node.attribute('src').value = absolute_url
31
+ node.attribute('src').value = absolute_url.to_s
32
32
 
33
33
  elsif not node.attribute('href').nil?
34
34
  absolute_url = Microformats::AbsoluteUri.new(node.attribute('href').value.to_s, base: @base).absolutize
35
- node.attribute('href').value = absolute_url
35
+ node.attribute('href').value = absolute_url.to_s
36
36
  end
37
37
  end
38
38
  parse_node(document)
@@ -46,6 +46,9 @@ module Microformats
46
46
  @http_headers = response.meta if response.respond_to?(:meta)
47
47
  @http_body = response.read
48
48
  end
49
+ if @base.nil?
50
+ @base = html
51
+ end
49
52
  @http_body
50
53
  rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
51
54
  @http_body = html
@@ -1,3 +1,3 @@
1
1
  module Microformats
2
- VERSION = "4.0.0"
2
+ VERSION = "4.0.1"
3
3
  end
@@ -4,19 +4,21 @@ require "microformats/absolute_uri"
4
4
  describe Microformats::AbsoluteUri do
5
5
  describe "#absolutize" do
6
6
  subject { Microformats::AbsoluteUri.new(relative, base: base).absolutize }
7
- let(:base) { nil }
8
7
 
9
8
  context "when relative is nil" do
10
9
  let(:relative) { nil }
11
- it { should be_nil }
10
+ let(:base) { "http://example.com" }
11
+ it { should eq base }
12
12
  end
13
13
 
14
14
  context "when relative is an empty string" do
15
15
  let(:relative) { "" }
16
- it { should be_nil }
16
+ let(:base) { "http://example.com" }
17
+ it { should eq base }
17
18
  end
18
19
 
19
20
  context "when relative is a valid absolute URI" do
21
+ let(:base) { nil }
20
22
  let(:relative) { "http://google.com" }
21
23
  it { should eq("http://google.com") }
22
24
  end
@@ -38,9 +40,15 @@ describe Microformats::AbsoluteUri do
38
40
  let(:base) { nil }
39
41
  it { should eq("bar/qux") }
40
42
  end
43
+
44
+ context "and base has a subdir" do
45
+ let(:base) { "http://google.com/asdf.html" }
46
+ it { should eq("http://google.com/bar/qux") }
47
+ end
41
48
  end
42
49
 
43
50
  context "when relative is an invalid URI" do
51
+ let(:base) { nil }
44
52
  let(:relative) { "git@github.com:indieweb/microformats-ruby.git" }
45
53
  it { should eq("git@github.com:indieweb/microformats-ruby.git") }
46
54
  end
@@ -39,6 +39,20 @@ describe Microformats::Parser do
39
39
  end
40
40
  end
41
41
 
42
+ describe "edge cases" do
43
+ cases_dir = "spec/support/lib/edge_cases/"
44
+ Dir[File.join(cases_dir, "*")].keep_if { |f| f =~ /([.]js$)/ }.each do |json_file|
45
+ it "#{json_file.split("/").last}" do
46
+
47
+ html_file = json_file.gsub(/([.]js$)/, ".html")
48
+ html = open(html_file).read
49
+ json = open(json_file).read
50
+
51
+ expect(JSON.parse(Microformats.parse(html).to_json)).to eq(JSON.parse(json))
52
+ end
53
+ end
54
+ end
55
+
42
56
  describe "microformat-tests/tests" do
43
57
  cases_dir = "vendor/tests/tests/*"
44
58
  #cases_dir = "vendor/tests/tests/microformats-mixed"
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <base href="http://example.org/">
4
+ <body>
5
+ <div class="h-card">
6
+ <a href="/" class="u-url p-name">
7
+ Jessica Lynn Suttles
8
+ </a>
9
+ <a href="" class="u-url">
10
+ @jlsuttles
11
+ </a>
12
+ <a href="http://twitter.com/jlsuttles" class="u-url">
13
+ @jlsuttles
14
+ </a>
15
+ <time class="dt-bday" datetime="1990-10-15">
16
+ October 15, 1990
17
+ </time>
18
+ <div class="e-content">
19
+ <p>Vegan. Cat lover. Coder.</p>
20
+ </div>
21
+ </div>
22
+ </body>
23
+ </html>
@@ -0,0 +1,15 @@
1
+ { "items": [{
2
+ "type": ["h-card"],
3
+ "properties": {
4
+ "url": ["http://example.org/", "http://example.org/", "http://twitter.com/jlsuttles"],
5
+ "name": ["Jessica Lynn Suttles"],
6
+ "bday": ["1990-10-15"],
7
+ "content": [{
8
+ "value": "Vegan. Cat lover. Coder.",
9
+ "html": "\n <p>Vegan. Cat lover. Coder.</p>\n"
10
+ }]
11
+ }
12
+ }],
13
+ "rels": {},
14
+ "rel-urls": {}
15
+ }
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <base href="http://example.org/">
4
+ <body>
5
+ <div class="h-card">
6
+ <img src="" class="u-photo" />
7
+ <a href="/" class="u-url p-name">
8
+ Jessica Lynn Suttles
9
+ </a>
10
+ <a href="http://flickr.com" class="u-url">
11
+ @jlsuttles
12
+ </a>
13
+ <a href="http://twitter.com/jlsuttles" class="u-url">
14
+ @jlsuttles
15
+ </a>
16
+ <time class="dt-bday" datetime="1990-10-15">
17
+ October 15, 1990
18
+ </time>
19
+ <div class="e-content">
20
+ <p>Vegan. Cat lover. Coder.</p>
21
+ </div>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1,16 @@
1
+ { "items": [{
2
+ "type": ["h-card"],
3
+ "properties": {
4
+ "photo": ["http://example.org/"],
5
+ "url": ["http://example.org/", "http://flickr.com", "http://twitter.com/jlsuttles"],
6
+ "name": ["Jessica Lynn Suttles"],
7
+ "bday": ["1990-10-15"],
8
+ "content": [{
9
+ "value": "Vegan. Cat lover. Coder.",
10
+ "html": "\n <p>Vegan. Cat lover. Coder.</p>\n"
11
+ }]
12
+ }
13
+ }],
14
+ "rels": {},
15
+ "rel-urls": {}
16
+ }
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <base href="http://example.org/index.html">
4
+ <body>
5
+ <div class="h-card">
6
+ <a href="/" class="u-url p-name">
7
+ Jessica Lynn Suttles
8
+ </a>
9
+ <a href="relative/page.html" class="u-url">
10
+ @jlsuttles
11
+ </a>
12
+ <a href="http://twitter.com/jlsuttles" class="u-url">
13
+ @jlsuttles
14
+ </a>
15
+ <a href="#fragment" class="u-url">
16
+ something on this page
17
+ </a>
18
+ <a href="#" class="u-url">
19
+ this page
20
+ </a>
21
+ <time class="dt-bday" datetime="1990-10-15">
22
+ October 15, 1990
23
+ </time>
24
+ <div class="e-content">
25
+ <p>Vegan. Cat lover. Coder.</p>
26
+ </div>
27
+ </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,15 @@
1
+ { "items": [{
2
+ "type": ["h-card"],
3
+ "properties": {
4
+ "url": ["http://example.org/", "http://example.org/relative/page.html", "http://twitter.com/jlsuttles", "http://example.org/index.html#fragment", "http://example.org/index.html#" ],
5
+ "name": ["Jessica Lynn Suttles"],
6
+ "bday": ["1990-10-15"],
7
+ "content": [{
8
+ "value": "Vegan. Cat lover. Coder.",
9
+ "html": "\n <p>Vegan. Cat lover. Coder.</p>\n"
10
+ }]
11
+ }
12
+ }],
13
+ "rels": {},
14
+ "rel-urls": {}
15
+ }
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <base href="http://example.org/">
4
+ <body>
5
+ <div class="h-card">
6
+ <a href="/" class="u-url p-name">
7
+ Jessica Lynn Suttles
8
+ </a>
9
+ <a href="" class="u-url">
10
+ @jlsuttles
11
+ </a>
12
+ <a href="http://twitter.com/jlsuttles" class="u-url">
13
+ @jlsuttles
14
+ </a>
15
+ <time class="dt-bday" datetime="1990-10-15">
16
+ October 15, 1990
17
+ </time>
18
+ <div class="e-content">
19
+ <p>Vegan. Cat lover. Coder.</p>
20
+ </div>
21
+ </div>
22
+ </body>
23
+ </html>
@@ -0,0 +1,11 @@
1
+ { "items": [{
2
+ "type": ["h-card"],
3
+ "properties": {
4
+ "url": ["http://example.org/", "", "http://twitter.com/jlsuttles"],
5
+ "name": ["Jessica Lynn Suttles"],
6
+ "bday": ["1990-10-15"],
7
+ "content": ["<p>Vegan. Cat lover. Coder.</p>"]
8
+ }
9
+ }],
10
+ "rels": {}
11
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microformats
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Becker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-17 00:00:00.000000000 Z
13
+ date: 2017-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -179,6 +179,14 @@ files:
179
179
  - spec/support/cases/microformats.org/microformats-2/microformats-2-8.js
180
180
  - spec/support/cases/microformats.org/microformats-2/microformats-2-9.html
181
181
  - spec/support/cases/microformats.org/microformats-2/microformats-2-9.js
182
+ - spec/support/lib/edge_cases/blank_href.html
183
+ - spec/support/lib/edge_cases/blank_href.js
184
+ - spec/support/lib/edge_cases/blank_src.html
185
+ - spec/support/lib/edge_cases/blank_src.js
186
+ - spec/support/lib/edge_cases/relative.html
187
+ - spec/support/lib/edge_cases/relative.js
188
+ - spec/support/lib/microformats/blank_href.html
189
+ - spec/support/lib/microformats/blank_href.js
182
190
  - spec/support/lib/microformats/implied_property/name-fail.html
183
191
  - spec/support/lib/microformats/implied_property/name-pass.html
184
192
  - spec/support/lib/microformats/implied_property/photo-fail.html
@@ -500,7 +508,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
500
508
  version: '0'
501
509
  requirements: []
502
510
  rubyforge_project:
503
- rubygems_version: 2.6.8
511
+ rubygems_version: 2.5.1
504
512
  signing_key:
505
513
  specification_version: 4
506
514
  summary: Microformats and microformats2 parser
@@ -529,6 +537,14 @@ test_files:
529
537
  - spec/support/cases/microformats.org/microformats-2/microformats-2-8.js
530
538
  - spec/support/cases/microformats.org/microformats-2/microformats-2-9.html
531
539
  - spec/support/cases/microformats.org/microformats-2/microformats-2-9.js
540
+ - spec/support/lib/edge_cases/blank_href.html
541
+ - spec/support/lib/edge_cases/blank_href.js
542
+ - spec/support/lib/edge_cases/blank_src.html
543
+ - spec/support/lib/edge_cases/blank_src.js
544
+ - spec/support/lib/edge_cases/relative.html
545
+ - spec/support/lib/edge_cases/relative.js
546
+ - spec/support/lib/microformats/blank_href.html
547
+ - spec/support/lib/microformats/blank_href.js
532
548
  - spec/support/lib/microformats/implied_property/name-fail.html
533
549
  - spec/support/lib/microformats/implied_property/name-pass.html
534
550
  - spec/support/lib/microformats/implied_property/photo-fail.html