microformats2 2.0.0.pre4 → 2.0.0.pre5

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.
data/README.md CHANGED
@@ -10,7 +10,7 @@ A work in progress.
10
10
 
11
11
  Implemented:
12
12
 
13
- * [parsing depth first, doc order](parse_a_document_for_microformats)
13
+ * [parsing depth first, doc order](http://microformats.org/wiki/microformats2-parsing#parse_a_document_for_microformats)
14
14
  * [parsing a p- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_p-_property)
15
15
  * [parsing a u- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_u-_property)
16
16
  * [parsing a dt- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_dt-_property)
@@ -33,7 +33,7 @@ Not Implemented:
33
33
 
34
34
  ## Current Version
35
35
 
36
- 2.0.0.pre4
36
+ 2.0.0.pre5
37
37
 
38
38
 
39
39
  ## Requirements
data/lib/microformats2.rb CHANGED
@@ -4,6 +4,7 @@ require "json"
4
4
  require "active_support/inflector"
5
5
 
6
6
  require "microformats2/version"
7
+ require "microformats2/parser"
7
8
  require "microformats2/format_parser"
8
9
  require "microformats2/property_parser"
9
10
  require "microformats2/collection"
@@ -22,17 +23,13 @@ require "microformats2/implied_property/url"
22
23
  module Microformats2
23
24
  class << self
24
25
  def parse(html)
25
- html = read_html(html)
26
- document = Nokogiri::HTML(html)
27
- Collection.new(document).parse
26
+ Parser.new.parse(html)
28
27
  end
29
28
 
30
29
  def read_html(html)
31
- open(html).read
32
- rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
33
- html
30
+ Parser.new.read_html(html)
34
31
  end
35
32
  end # class << self
36
33
 
37
34
  class InvalidPropertyPrefix < StandardError; end
38
- end
35
+ end
@@ -0,0 +1,25 @@
1
+ module Microformats2
2
+ class Parser
3
+ attr_reader :http_headers, :http_body
4
+
5
+ def initialize
6
+ @http_headers = {}
7
+ end
8
+
9
+ def parse(html, headers={})
10
+ html = read_html(html, headers)
11
+ document = Nokogiri::HTML(html)
12
+ Collection.new(document).parse
13
+ end
14
+
15
+ def read_html(html, headers={})
16
+ open(html, headers) do |response|
17
+ @http_headers = response.meta if response.respond_to?(:meta)
18
+ @http_body = response.read
19
+ end
20
+ @http_body
21
+ rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
22
+ @http_body = html
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Microformats2
2
- VERSION = "2.0.0.pre4"
2
+ VERSION = "2.0.0.pre5"
3
3
  end
@@ -26,5 +26,5 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency "guard-rspec", "~> 2.1.0"
27
27
  gem.add_development_dependency "rb-fsevent", "~> 0.9.1"
28
28
  gem.add_development_dependency "simplecov", "~> 0.7.1"
29
- gem.add_development_dependency "debugger", "~> 1.2.1"
29
+ gem.add_development_dependency "webmock", "~> 1.12.3"
30
30
  end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2::Parser do
5
+ let(:parser) { Microformats2::Parser.new }
6
+
7
+ describe "#http_headers" do
8
+ it "starts as a blank hash" do
9
+ parser.http_headers.should eq({})
10
+ end
11
+
12
+ describe "open file" do
13
+ before do
14
+ parser.parse("spec/support/lib/microformats2/simple.html")
15
+ end
16
+
17
+ it "doesn't save #http_headers" do
18
+ parser.http_headers.should eq({})
19
+ end
20
+ it "saves #http_body" do
21
+ parser.http_body.should include "<!DOCTYPE html>"
22
+ end
23
+ end
24
+
25
+ describe "http response" do
26
+ before do
27
+ stub_request(:get, "http://www.example.com/").
28
+ with(:headers => {"Accept"=>"*/*", "User-Agent"=>"Ruby"}).
29
+ to_return(:status => 200, :body => "abc", :headers => {"Content-Length" => 3})
30
+ parser.parse("http://www.example.com")
31
+ end
32
+
33
+ it "saves #http_headers" do
34
+ parser.http_headers.should eq({"content-length" => "3"})
35
+ end
36
+ it "saves #http_body" do
37
+ parser.http_body.should eq("abc")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -23,6 +23,9 @@ describe Microformats2 do
23
23
  Microformats2.read_html(html).should include "<div class=\"h-card\">"
24
24
  end
25
25
  it "can be a url to html" do
26
+ stub_request(:get, "http://google.com/").
27
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
28
+ to_return(:status => 200, :body => "google", :headers => {})
26
29
  html = "http://google.com"
27
30
  Microformats2.read_html(html).should include "google"
28
31
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ SimpleCov.start
4
4
  require 'rubygems'
5
5
  require 'rspec'
6
6
  require 'rspec/autorun'
7
+ require 'webmock/rspec'
7
8
 
8
9
  RSpec.configure do |config|
9
10
  config.order = "random"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microformats2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre4
4
+ version: 2.0.0.pre5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-01 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -140,13 +140,13 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: 0.7.1
142
142
  - !ruby/object:Gem::Dependency
143
- name: debugger
143
+ name: webmock
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
147
  - - ~>
148
148
  - !ruby/object:Gem::Version
149
- version: 1.2.1
149
+ version: 1.12.3
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ dependencies:
154
154
  requirements:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
- version: 1.2.1
157
+ version: 1.12.3
158
158
  description: parses HTML for microformats and return a collection of dynamically defined
159
159
  Ruby objects
160
160
  email:
@@ -179,6 +179,7 @@ files:
179
179
  - lib/microformats2/implied_property/name.rb
180
180
  - lib/microformats2/implied_property/photo.rb
181
181
  - lib/microformats2/implied_property/url.rb
182
+ - lib/microformats2/parser.rb
182
183
  - lib/microformats2/property.rb
183
184
  - lib/microformats2/property/date_time.rb
184
185
  - lib/microformats2/property/embedded.rb
@@ -192,6 +193,7 @@ files:
192
193
  - spec/lib/microformats2/implied_property/name_spec.rb
193
194
  - spec/lib/microformats2/implied_property/photo_spec.rb
194
195
  - spec/lib/microformats2/implied_property/url_spec.rb
196
+ - spec/lib/microformats2/parser_spec.rb
195
197
  - spec/lib/microformats2_spec.rb
196
198
  - spec/spec_helper.rb
197
199
  - spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.html
@@ -371,9 +373,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
371
373
  - - ! '>='
372
374
  - !ruby/object:Gem::Version
373
375
  version: '0'
374
- segments:
375
- - 0
376
- hash: 2813270681629112276
377
376
  required_rubygems_version: !ruby/object:Gem::Requirement
378
377
  none: false
379
378
  requirements:
@@ -391,6 +390,7 @@ test_files:
391
390
  - spec/lib/microformats2/implied_property/name_spec.rb
392
391
  - spec/lib/microformats2/implied_property/photo_spec.rb
393
392
  - spec/lib/microformats2/implied_property/url_spec.rb
393
+ - spec/lib/microformats2/parser_spec.rb
394
394
  - spec/lib/microformats2_spec.rb
395
395
  - spec/spec_helper.rb
396
396
  - spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.html
@@ -558,3 +558,4 @@ test_files:
558
558
  - spec/support/lib/microformats2/nested-property.js
559
559
  - spec/support/lib/microformats2/simple.html
560
560
  - spec/support/lib/microformats2/simple.js
561
+ has_rdoc: