Compare commits

...
Sign in to create a new pull request.

43 commits

Author SHA1 Message Date
f78162fd41 While parsing check for existance of attribute
When parsing rel attributes, check for existance of the href attribute
before extracting the text, sometimes like in this post somewhere
https://www.patreon.com/posts/jeenas-excellent-6467133 it might be empty
and causes an exception. All the other uses above this one check that too.
2016-08-03 21:40:11 +02:00
Shane Becker
945ffe6c6e Version bump to 2.0.2 2016-05-04 14:07:03 -07:00
Shane Becker
12417d5096 Merge pull request #37 from jeena/master
Don't crash if it's not possible to attach to property
2016-05-04 14:01:11 -07:00
Jeena
a54c64034d Don't crash if it's not possible to attach to property
Normally one can attach to properties, but if it is of a type URL then
it crashes hard. This check just drops everything which can't be
attached by `<<`.
2016-04-24 02:11:56 +02:00
Shane Becker
a00edda73d Merge pull request #36 from ckruse/master
fix: typo compatable -> compatible
2016-02-24 15:08:58 -08:00
Christian Kruse
086bed9d54 fix: typo compatable -> compatible 2016-02-19 21:40:17 +01:00
Shane Becker
6edf5721d1 Update name 2015-12-23 12:37:54 -08:00
Shane Becker
7b62671ad2 Bold is **, not * 2015-12-23 12:35:04 -08:00
Shane Becker
b6b37b0700 Add TODO for using the mf2 test suite 2015-12-23 12:34:07 -08:00
Shane Becker
7647446ea8 Clean up README
And remove Guard command
2015-12-23 12:28:22 -08:00
Shane Becker
dc884bdc2b Status update 2015-12-23 11:56:37 -08:00
Shane Becker
408145f52a Merge pull request #33 from jeena/master
Resolve relative URLs (bugfix)
2015-12-22 17:19:41 -08:00
Shane Becker
1a3f86f797 Merge pull request #23 from indieweb/add-spec-for-p-h-foo
Add spec for nested format with property of same name
2015-12-22 17:11:54 -08:00
Shane Becker
bba83be9b4 Remove reference to G5 2015-12-22 16:55:41 -08:00
Shane Becker
412a94e576 Remove reference to G5 2015-12-22 16:52:52 -08:00
Shane Becker
5dcc2df60d Remove campfire notifications 2015-12-22 16:12:42 -08:00
Shane Becker
22f5de54dd Capitalize gem description 2015-12-22 15:37:49 -08:00
Shane Becker
59a316712a Add me to authors list in gemspec 2015-12-22 15:37:21 -08:00
Shane Becker
aff63658ce Change license file to CC0. 2015-12-22 15:33:22 -08:00
Shane Becker
82f2b13dc2 Change license to CC0. 2015-12-22 15:14:18 -08:00
Shane Becker
a7dcd994b8 Update Code Climate badge 2015-12-22 14:49:35 -08:00
Shane Becker
baf6060dfb Change /g5 links to /indieweb in README 2015-12-22 14:46:14 -08:00
Jeena
6c90f01ae7 Resolve relative URLs (bugfix)
When the <base> tag is used, the @base wasn't handed down all the way to URLs
and photos, this patch fixes this problem.

In addition to that it also makes it possible to handle u-url on <input> tags.
2015-08-21 21:17:54 +02:00
Michael Mitchell
1e9e65cf9e Update README.md 2015-08-10 10:56:06 -07:00
Jessica Suttles
5aeb8cef40 Merge pull request #30 from barnabywalters/patch-1
Added usage examples of collection.to_hash and .to_json
2014-06-11 09:49:17 -07:00
Barnaby Walters
96ed937040 Added usage examples of collection.to_hash and .to_json
As per @aaronpk wanting this feature to the point of considering creating a separate parser — turns out it is possible, just a little buried!
2014-06-11 16:45:17 +00:00
Jessica Lynn Suttles
0734bc5c44 Add .travis.yml campfire template 2014-03-10 16:12:55 -07:00
Jessica Lynn Suttles
840fdff624 Bump version to 2.0.1 2014-03-10 15:56:27 -07:00
Jessica Lynn Suttles
afe70d6b6d Merge pull request #27 from G5/allow-invalid-uri-as-u-properties
Allow u-* properties to be invalid URIs
2014-03-10 15:48:03 -07:00
Jessica Lynn Suttles
86d89eecf4 Merge pull request #28 from G5/let-it-be
Convert a spec to an explicit subject and lets.
2014-03-10 14:04:12 -07:00
Don Petersen
fd6ea19652 Convert a spec to an explicit subject and lets. 2014-03-10 20:54:22 +00:00
Jessica Lynn Suttles
cb918e2dd1 Add specs for Microformats2::AbsoluteUri 2014-03-10 12:26:24 -07:00
Jessica Lynn Suttles
d8545d9930 Do not log URI::InvalidURIError error message 2014-03-07 16:41:34 -08:00
Jessica Lynn Suttles
25f5fda178 Allow u-* properties to be invalid URIs 2014-03-07 14:19:51 -08:00
jessicard
d85c12c606 adds jessicard to authors in gemspec 2014-02-25 15:58:34 -08:00
jessicard
bbff5ac389 adds jessicard to list of contributors 2014-02-25 15:56:14 -08:00
Jessica Lynn Suttles
78927d36b8 Bump version to 2.0.0
Fixes #24
2014-02-25 15:23:57 -08:00
Jessica Lynn Suttles
ed10fa8823 Remove version constraints from dependencies 2014-02-25 15:19:27 -08:00
Jessica Dillon & Jessica Lynn Suttles
b972df4334 Add a usage example for nested microformats to README
Fixes #25
2014-02-25 15:11:45 -08:00
Jessica Dillon & Jessica Lynn Suttles
2ac4cff54b Add spec for nested format with property of same name 2013-12-12 15:11:51 -08:00
Jessica Dillon & Jessica Lynn Suttles
68bfe0fb2e Update Campfire config for Travis CI 2013-11-17 16:16:52 -08:00
Jessica Dillon & Jessica Lynn Suttles
b83c2118f6 Fix .travis.yml file 2013-11-17 16:09:45 -08:00
Jessica Dillon & Jessica Lynn Suttles
1869adb60e Add Campfire notifications for Travis CI 2013-11-17 16:00:25 -08:00
18 changed files with 235 additions and 123 deletions

View file

@ -1,4 +1,4 @@
language: ruby
rvm:
- 1.9.3
script: bundle exec rspec spec
- 2.2.3
script: bundle exec rspec

36
LICENSE.md Normal file
View file

@ -0,0 +1,36 @@
# Creative Commons Legal Code
## CC0 1.0 Universal
http://creativecommons.org/publicdomain/zero/1.0
Official translations of this legal tool are available> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
### _Statement of Purpose_
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
**1. Copyright and Related Rights.** A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
2. moral rights retained by the original author(s) and/or performer(s);
3. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
**2. Waiver.** To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
**3. Public License Fallback.** Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
**4. Limitations and Disclaimers.**
1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

View file

@ -1,22 +0,0 @@
Copyright (c) 2013 G5
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,11 +1,16 @@
# Microformats2
# Microformats2 (ruby)
[![Build Status](https://travis-ci.org/G5/microformats2.png?branch=master)](https://travis-ci.org/G5/microformats2)
[![Code Climate](https://codeclimate.com/github/G5/microformats2.png)](https://codeclimate.com/github/G5/microformats2)
[![Build Status](https://travis-ci.org/indieweb/microformats2-ruby.png?branch=master)](https://travis-ci.org/indieweb/microformats2-ruby)
[![Code Climate](https://codeclimate.com/github/indieweb/microformats2-ruby/badges/gpa.svg)](https://codeclimate.com/github/indieweb/microformats2-ruby)
A Ruby gem to parse HTML containing one or more [microformats2](http://microformats.org/wiki/microformats-2)
and return a collection of dynamically defined Ruby objects.
## Development Status
This gem sat unmaintained for quite a long time. It's now under new management. Work will begin shortly on getting it on par with the other Microformats2 parsers and the current state of the spec. (2015-12-23)
A work in progress.
Implemented:
@ -28,34 +33,42 @@ Not Implemented:
* [value-class-pattern](http://microformats.org/wiki/value-class-pattern)
* [include-pattern](http://microformats.org/wiki/include-pattern)
* recognition of [vendor extensions](http://microformats.org/wiki/microformats2#VENDOR_EXTENSIONS)
* backwards compatable support for microformats v1
* backwards compatible support for microformats v1
## Current Version
2.0.0.pre5
2.0.2
![Version 2.0.2](https://img.shields.io/badge/VERSION-2.0.2-green.svg)
## Requirements
* "nokogiri", "~> 1.5.6"
* "json", "~> 1.7.6"
* "activesupport", "~> 3.2.12"
* [nokogiri](https://github.com/sparklemotion/nokogiri)
* [json](https://github.com/flori/json)
* [activesupport](https://github.com/rails/rails/tree/master/activesupport)
## Installation
Add this line to your application's Gemfile:
gem 'microformats2'
```ruby
gem "microformats2"
```
And then execute:
$ bundle
```
bundle
```
Or install it yourself as:
$ gem install microformats2
```
gem install microformats2
```
## Usage
@ -63,12 +76,27 @@ Or install it yourself as:
```ruby
require "microformats2"
source = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
source = "<div class='h-card'><p class='p-name'>Jessica Lynn Suttles</p></div>"
collection = Microformats2.parse(source)
# using singular accessors
collection.card.name.to_s #=> "Jessica Lynn Suttles"
# using plural accessors
collection.cards.first.names.first.to_s #=> "Jessica Lynn Suttles"
source = "<article class='h-entry'>
<h1 class='p-name'>Microformats 2</h1>
<div class='h-card p-author'><p class='p-name'>Jessica Lynn Suttles</p></div>
</article>"
collection = Microformats2.parse(source)
collection.entry.name.to_s #=> "Microformats 2"
# accessing nested microformats
collection.entry.author.format.name.to_s #=> "Jessica Lynn Suttles"
# getting a copy of the canonical microformats2 hash structure
collection.to_hash
# the above, as JSON in a string
collection.to_json
```
* `source` can be a URL, filepath, or HTML
@ -79,6 +107,8 @@ collection.cards.first.names.first.to_s #=> "Jessica Lynn Suttles"
* Shane Becker / [@veganstraightedge](https://github.com/veganstraightedge)
* Chris Stringer / [@jcstringer](https://github.com/jcstringer)
* Michael Mitchell / [@variousred](https://github.com/variousred)
* Jessica Dillon / [@jessicard](https://github.com/jessicard)
## Contributions
@ -91,49 +121,27 @@ collection.cards.first.names.first.to_s #=> "Jessica Lynn Suttles"
7. Create new Pull Request
If you find bugs, have feature requests or questions, please
[file an issue](https://github.com/G5/microformats2/issues).
[file an issue](https://github.com/indieweb/microformats2-ruby/issues).
## Specs
**TODO** remove this and use the [microformats tests repo](https://github.com/microformats/tests) instead.
To update spec cases that are scraped from other sites.
**Warning:** This could break specs.
```bash
```
rake specs:update
```
To run specs
```bash
rake spec
```
To keep specs running
```bash
guard
rake spec
```
## License
Copyright (c) 2013 G5
Microformats2 (ruby) is dedicated to the public domain using Creative Commons -- CC0 1.0 Universal.
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
http://creativecommons.org/publicdomain/zero/1.0

View file

@ -4,6 +4,7 @@ require "json"
require "active_support/inflector"
require "microformats2/version"
require "microformats2/absolute_uri"
require "microformats2/parser"
require "microformats2/format_parser"
require "microformats2/property_parser"

View file

@ -0,0 +1,26 @@
module Microformats2
class AbsoluteUri
attr_accessor :base, :relative
def initialize(base, relative)
@base = base
@relative = relative
end
def absolutize
return nil if relative.nil? or relative == ""
uri = URI.parse(relative)
if base && !uri.absolute?
uri = URI.join(base.to_s, relative.to_s)
end
uri.normalize!
uri.to_s
rescue URI::BadURIError, URI::InvalidURIError => e
relative.to_s
end
end
end

View file

@ -88,7 +88,7 @@ module Microformats2
if rel_values.member?("alternate")
alternate_inst = {}
alternate_inst["url"] = absolutize(rel.attribute("href").text)
alternate_inst["url"] = Microformats2::AbsoluteUri.new(@base, rel.attribute("href").text).absolutize
alternate_inst["rel"] = (rel_values - ["alternate"]).join(" ")
unless rel.attribute("media").nil?
alternate_inst["media"] = rel.attribute("media").text
@ -103,21 +103,12 @@ module Microformats2
else
rel_values.each do |rel_value|
@rels[rel_value] = [] unless @rels.has_key?(rel_value)
@rels[rel_value] << absolutize(rel.attribute("href").text)
unless rel.attribute("href").nil?
@rels[rel_value] << Microformats2::AbsoluteUri.new(@base, rel.attribute("href").text).absolutize
end
end
end
end
end
def absolutize(href)
uri = URI.parse(href)
if @base && !uri.absolute?
uri = URI.join(@base, href)
end
uri.normalize!
uri.to_s
end
end
end

View file

@ -40,9 +40,9 @@ module Microformats2
def parse_implied_properties
ip = []
ip << ImpliedProperty::Name.new(@element).parse unless property_present?(:name)
ip << ImpliedProperty::Name.new(@element, @base).parse unless property_present?(:name)
ip << ImpliedProperty::Url.new(@element, @base).parse unless property_present?(:url)
ip << ImpliedProperty::Photo.new(@element).parse unless property_present?(:photo)
ip << ImpliedProperty::Photo.new(@element, @base).parse unless property_present?(:photo)
ip.compact.each do |property|
save_property_name(property.method_name)
define_method(property.method_name)
@ -102,7 +102,7 @@ module Microformats2
send("#{mn}=", value)
end
if current = send(mn.pluralize)
current << value
current << value if current.respond_to? :<<
else
send("#{mn.pluralize}=", [value])
end

View file

@ -6,6 +6,10 @@ module Microformats2
"photo"
end
def to_s
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
end
protected
def name_map

View file

@ -7,19 +7,7 @@ module Microformats2
end
def to_s
@to_s = absolutize(super.to_s) if super.to_s != ""
end
# TODO: make dry, repeated in Collection
def absolutize(href)
uri = URI.parse(href)
if @base && !uri.absolute?
uri = URI.join(@base, href)
end
uri.normalize!
uri.to_s
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
end
protected

View file

@ -25,7 +25,7 @@ module Microformats2
end
def formats
@formats ||= format_classes.length >=1 ? FormatParser.parse(@element) : []
@formats ||= format_classes.length >=1 ? FormatParser.parse(@element, @base) : []
end
def to_hash

View file

@ -3,19 +3,7 @@ module Microformats2
class Url < Foundation
def to_s
@to_s = absolutize(super.to_s)
end
# TODO: make dry, repeated in Collection
def absolutize(href)
uri = URI.parse(href)
if @base && !uri.absolute?
uri = URI.join(@base, href)
end
uri.normalize!
uri.to_s
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
end
protected
@ -27,7 +15,8 @@ module Microformats2
"img" => "src",
"object" => "data",
"abbr" => "title",
"data" => "value" }
"data" => "value",
"input" => "value" }
end
end
end

View file

@ -1,3 +1,3 @@
module Microformats2
VERSION = "2.0.0.pre5"
VERSION = "2.0.2"
end

View file

@ -6,25 +6,25 @@ require 'microformats2/version'
Gem::Specification.new do |gem|
gem.name = "microformats2"
gem.version = Microformats2::VERSION
gem.authors = ["Jessica Lynn Suttles"]
gem.email = ["jlsuttles@gmail.com"]
gem.description = %q{parses HTML for microformats and return a collection of dynamically defined Ruby objects}
gem.authors = ["Shane Becker", "Jessica Lynn Suttles", "Jessica Dillon"]
gem.email = ["veganstraightedge@gmail.com", "jlsuttles@gmail.com", "jessicard@mac.com"]
gem.description = %q{Parses HTML for microformats and return a collection of dynamically defined Ruby objects}
gem.summary = %q{microformats2 parser}
gem.homepage = "https://github.com/G5/microformats2"
gem.homepage = "https://github.com/indieweb/microformats2-ruby"
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.add_runtime_dependency "nokogiri", ">= 1.5.6"
gem.add_runtime_dependency "json", ">= 1.7.6"
gem.add_runtime_dependency "activesupport", ">= 3.2.13"
gem.add_runtime_dependency "nokogiri"
gem.add_runtime_dependency "json"
gem.add_runtime_dependency "activesupport"
gem.add_development_dependency "rake", "~> 10.0.0"
gem.add_development_dependency "rspec", "~> 2.11.0"
gem.add_development_dependency "guard-rspec", "~> 2.1.0"
gem.add_development_dependency "rb-fsevent", "~> 0.9.1"
gem.add_development_dependency "simplecov", "~> 0.7.1"
gem.add_development_dependency "webmock", "~> 1.12.3"
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "guard-rspec"
gem.add_development_dependency "rb-fsevent"
gem.add_development_dependency "simplecov"
gem.add_development_dependency "webmock"
end

View file

@ -0,0 +1,48 @@
require "spec_helper"
require "microformats2/absolute_uri"
describe Microformats2::AbsoluteUri do
describe "#absolutize" do
subject { Microformats2::AbsoluteUri.new(base, relative).absolutize }
let(:base) { nil }
context "when relative is nil" do
let(:relative) { nil }
it { should be_nil }
end
context "when relative is an empty string" do
let(:relative) { "" }
it { should be_nil }
end
context "when relative is a valid absolute URI" do
let(:relative) { "http://google.com" }
it { should eq("http://google.com/") }
end
context "when relative is a valid non-absolute URI" do
let(:relative) { "bar/qux" }
context "and base is present but not absolute" do
let(:base) { "foo" }
it { should eq("bar/qux") }
end
context "and base is present and absolute" do
let(:base) { "http://google.com" }
it { should eq("http://google.com/bar/qux") }
end
context "and base is not present" do
let(:base) { nil }
it { should eq("bar/qux") }
end
end
context "when relative is an invalid URI" do
let(:relative) { "git@github.com:indieweb/microformats2-ruby.git" }
it { should eq("git@github.com:indieweb/microformats2-ruby.git") }
end
end
end

View file

@ -138,6 +138,20 @@ describe Microformats2::Collection do
end
end
describe "nested-format-with-property-of-same-name.html" do
before do
html = "spec/support/lib/microformats2/nested-format-with-property-of-same-name.html"
@collection = Microformats2.parse(html)
end
describe "#to_json" do
it "should match nested-format-with-property-of-same-name.js" do
json = "spec/support/lib/microformats2/nested-format-with-property-of-same-name.js"
json = open(json).read
JSON.parse(@collection.to_json).should == JSON.parse(json)
end
end
end
describe "nested-format-with-property.html" do
before do
html = "spec/support/lib/microformats2/nested-format-with-property.html"

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>
<div class="h-card">
<div class="p-adr h-adr">
<span class="p-street-address">
123 Rainbow Lane
</span>
</a>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,16 @@
{ "items": [{
"type": ["h-card"],
"properties": {
"adr": [{
"value": "123 Rainbow Lane",
"type": ["h-adr"],
"properties": {
"street-address": ["123 Rainbow Lane"],
"name": ["123 Rainbow Lane"]
}
}],
"name": ["123 Rainbow Lane"]
}
}],
"rels": {}
}