Compare commits
1 commit
master
...
nested-plu
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ad9969e36c |
19 changed files with 129 additions and 235 deletions
|
@ -1,4 +1,4 @@
|
|||
language: ruby
|
||||
rvm:
|
||||
- 2.2.3
|
||||
script: bundle exec rspec
|
||||
- 1.9.3
|
||||
script: bundle exec rspec spec
|
||||
|
|
36
LICENSE.md
36
LICENSE.md
|
@ -1,36 +0,0 @@
|
|||
# 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.
|
22
LICENSE.txt
Normal file
22
LICENSE.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
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.
|
90
README.md
90
README.md
|
@ -1,16 +1,11 @@
|
|||
# Microformats2 (ruby)
|
||||
# Microformats2
|
||||
|
||||
[](https://travis-ci.org/indieweb/microformats2-ruby)
|
||||
[](https://codeclimate.com/github/indieweb/microformats2-ruby)
|
||||
[](https://travis-ci.org/G5/microformats2)
|
||||
[](https://codeclimate.com/github/G5/microformats2)
|
||||
|
||||
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:
|
||||
|
@ -33,42 +28,34 @@ 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 compatible support for microformats v1
|
||||
* backwards compatable support for microformats v1
|
||||
|
||||
|
||||
## Current Version
|
||||
|
||||
2.0.2
|
||||
|
||||

|
||||
2.0.0.pre5
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
* [nokogiri](https://github.com/sparklemotion/nokogiri)
|
||||
* [json](https://github.com/flori/json)
|
||||
* [activesupport](https://github.com/rails/rails/tree/master/activesupport)
|
||||
* "nokogiri", "~> 1.5.6"
|
||||
* "json", "~> 1.7.6"
|
||||
* "activesupport", "~> 3.2.12"
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem "microformats2"
|
||||
```
|
||||
gem 'microformats2'
|
||||
|
||||
And then execute:
|
||||
|
||||
```
|
||||
bundle
|
||||
```
|
||||
$ bundle
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
```
|
||||
gem install microformats2
|
||||
```
|
||||
$ gem install microformats2
|
||||
|
||||
|
||||
## Usage
|
||||
|
@ -76,27 +63,12 @@ gem install microformats2
|
|||
```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
|
||||
|
@ -107,8 +79,6 @@ collection.to_json
|
|||
* 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
|
||||
|
||||
|
@ -121,27 +91,49 @@ collection.to_json
|
|||
7. Create new Pull Request
|
||||
|
||||
If you find bugs, have feature requests or questions, please
|
||||
[file an issue](https://github.com/indieweb/microformats2-ruby/issues).
|
||||
[file an issue](https://github.com/G5/microformats2/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
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Microformats2 (ruby) is dedicated to the public domain using Creative Commons -- CC0 1.0 Universal.
|
||||
Copyright (c) 2013 G5
|
||||
|
||||
http://creativecommons.org/publicdomain/zero/1.0
|
||||
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.
|
||||
|
|
|
@ -4,7 +4,6 @@ require "json"
|
|||
require "active_support/inflector"
|
||||
|
||||
require "microformats2/version"
|
||||
require "microformats2/absolute_uri"
|
||||
require "microformats2/parser"
|
||||
require "microformats2/format_parser"
|
||||
require "microformats2/property_parser"
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
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
|
|
@ -88,7 +88,7 @@ module Microformats2
|
|||
|
||||
if rel_values.member?("alternate")
|
||||
alternate_inst = {}
|
||||
alternate_inst["url"] = Microformats2::AbsoluteUri.new(@base, rel.attribute("href").text).absolutize
|
||||
alternate_inst["url"] = absolutize(rel.attribute("href").text)
|
||||
alternate_inst["rel"] = (rel_values - ["alternate"]).join(" ")
|
||||
unless rel.attribute("media").nil?
|
||||
alternate_inst["media"] = rel.attribute("media").text
|
||||
|
@ -103,12 +103,21 @@ module Microformats2
|
|||
else
|
||||
rel_values.each do |rel_value|
|
||||
@rels[rel_value] = [] unless @rels.has_key?(rel_value)
|
||||
unless rel.attribute("href").nil?
|
||||
@rels[rel_value] << Microformats2::AbsoluteUri.new(@base, rel.attribute("href").text).absolutize
|
||||
end
|
||||
@rels[rel_value] << absolutize(rel.attribute("href").text)
|
||||
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
|
||||
|
|
|
@ -40,9 +40,9 @@ module Microformats2
|
|||
|
||||
def parse_implied_properties
|
||||
ip = []
|
||||
ip << ImpliedProperty::Name.new(@element, @base).parse unless property_present?(:name)
|
||||
ip << ImpliedProperty::Name.new(@element).parse unless property_present?(:name)
|
||||
ip << ImpliedProperty::Url.new(@element, @base).parse unless property_present?(:url)
|
||||
ip << ImpliedProperty::Photo.new(@element, @base).parse unless property_present?(:photo)
|
||||
ip << ImpliedProperty::Photo.new(@element).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 if current.respond_to? :<<
|
||||
current << value
|
||||
else
|
||||
send("#{mn.pluralize}=", [value])
|
||||
end
|
||||
|
|
|
@ -6,10 +6,6 @@ module Microformats2
|
|||
"photo"
|
||||
end
|
||||
|
||||
def to_s
|
||||
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def name_map
|
||||
|
|
|
@ -7,7 +7,19 @@ module Microformats2
|
|||
end
|
||||
|
||||
def to_s
|
||||
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
|
||||
@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
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -25,7 +25,7 @@ module Microformats2
|
|||
end
|
||||
|
||||
def formats
|
||||
@formats ||= format_classes.length >=1 ? FormatParser.parse(@element, @base) : []
|
||||
@formats ||= format_classes.length >=1 ? FormatParser.parse(@element) : []
|
||||
end
|
||||
|
||||
def to_hash
|
||||
|
|
|
@ -3,7 +3,19 @@ module Microformats2
|
|||
class Url < Foundation
|
||||
|
||||
def to_s
|
||||
@to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize
|
||||
@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
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -15,8 +27,7 @@ module Microformats2
|
|||
"img" => "src",
|
||||
"object" => "data",
|
||||
"abbr" => "title",
|
||||
"data" => "value",
|
||||
"input" => "value" }
|
||||
"data" => "value" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Microformats2
|
||||
VERSION = "2.0.2"
|
||||
VERSION = "2.0.0.pre5"
|
||||
end
|
||||
|
|
|
@ -6,25 +6,25 @@ require 'microformats2/version'
|
|||
Gem::Specification.new do |gem|
|
||||
gem.name = "microformats2"
|
||||
gem.version = Microformats2::VERSION
|
||||
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.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.summary = %q{microformats2 parser}
|
||||
gem.homepage = "https://github.com/indieweb/microformats2-ruby"
|
||||
gem.homepage = "https://github.com/G5/microformats2"
|
||||
|
||||
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"
|
||||
gem.add_runtime_dependency "json"
|
||||
gem.add_runtime_dependency "activesupport"
|
||||
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_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"
|
||||
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"
|
||||
end
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
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
|
|
@ -73,6 +73,11 @@ describe Microformats2::Collection do
|
|||
@collection.card.contents.first.should be_kind_of Microformats2::Property::Embedded
|
||||
end
|
||||
end
|
||||
describe "h-card with a plurally-named nested tag" do
|
||||
it "is properly parsed" do
|
||||
expect(@collection.card.hours.to_s).to eql("")
|
||||
end
|
||||
end
|
||||
describe "Format.add_property" do
|
||||
let(:value) { "bar" }
|
||||
it "creates the attr" do
|
||||
|
@ -138,20 +143,6 @@ 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"
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<!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>
|
|
@ -1,16 +0,0 @@
|
|||
{ "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": {}
|
||||
}
|
|
@ -18,6 +18,7 @@
|
|||
<div class="e-content">
|
||||
<p>Vegan. Cat lover. Coder.</p>
|
||||
</div>
|
||||
<span class="p-hours"></span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue