fiddle_fart 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/fiddle_fart.gemspec +24 -0
- data/lib/fiddle_fart.rb +9 -0
- data/lib/fiddle_fart/codepen.rb +42 -0
- data/lib/fiddle_fart/jsbin.rb +42 -0
- data/lib/fiddle_fart/jsfiddle.rb +37 -0
- data/lib/fiddle_fart/parser.rb +18 -0
- data/lib/fiddle_fart/plnkr.rb +39 -0
- data/lib/fiddle_fart/version.rb +3 -0
- data/spec/lib/fiddle_fart_spec.rb +67 -0
- data/spec/spec_helper.rb +8 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 117342388b791fe00d41af20503959f5cb698066
|
4
|
+
data.tar.gz: 5fa008d010d8e58651228436411ccc029f2eaa3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34176024d0fcf9b21c5ab6c526032542511f044334f8975dc18e8f345b6236a7a339e91c6ec27c2e25b8ce4a294a2fb766f4d5a7bb148218774b9892efde82e5
|
7
|
+
data.tar.gz: 5c5a17128e31e9b948cc2abb9343bee6624bac5449250d8f2077515816ca9489f790af42294fbb719fdb22846649681e8779835d6c8e28e1875b7f6a34bffa11
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Eric Berry
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# FiddleFart
|
2
|
+
|
3
|
+
FiddleFart is the parsing tool which takes a URL from any of the
|
4
|
+
following services and normalizes the embed data.
|
5
|
+
|
6
|
+
* [jsfiddle.net](http://jsfiddle.net)
|
7
|
+
* [jsbin.com](http://jsbin.com)
|
8
|
+
* [codepen.io](http://codepen.io)
|
9
|
+
* [plnkr.co](http://plnkr.co)
|
10
|
+
|
11
|
+
The goal of this gem is to make it very easy to extract out embed
|
12
|
+
URLs (for use in other *future* applications).
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'fiddle_fart'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install fiddle_fart
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'fiddle_fart'
|
32
|
+
|
33
|
+
url = "http://jsbin.com/eyOlOFI/7/edit"
|
34
|
+
obj = FiddleFart::Parser.parse(url)
|
35
|
+
obj.embed_url # => "http://jsbin.com/eyOlOFI/7/embed"
|
36
|
+
|
37
|
+
url = "http://codepen.io/cmykw/pen/krqIt"
|
38
|
+
obj = FiddleFart::Parser.parse(url)
|
39
|
+
obj.share_link # => "http://codepen.io/cmykw/full/krqIt"
|
40
|
+
|
41
|
+
url = "http://jsfiddle.net/cavneb/sKfS8/"
|
42
|
+
obj = FiddleFart::Parser.parse(url)
|
43
|
+
obj.embed_url # => "http://jsfiddle.net/cavneb/sKfS8//embedded/result/"
|
44
|
+
|
45
|
+
url = "http://plnkr.co/edit/ZTArBF?p=info"
|
46
|
+
obj = FiddleFart::Parser.parse(url)
|
47
|
+
obj.embed_url # => "http://embed.plnkr.co/ZTArBF/preview"
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( http://github.com/<my-github-username>/fiddle_fart/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/fiddle_fart.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fiddle_fart/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fiddle_fart"
|
8
|
+
spec.version = FiddleFart::VERSION
|
9
|
+
spec.authors = ["Eric Berry"]
|
10
|
+
spec.email = ["cavneb@gmail.com"]
|
11
|
+
spec.summary = "Parse embed data from jsfiddle, jsbin, codepen and plnkr"
|
12
|
+
spec.description = %q{FiddleFart is the parsing tool which takes a URL from any of the following services and normalizes the embed data.}
|
13
|
+
spec.homepage = "https://github.com/cavneb/fiddle_fart"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/fiddle_fart.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module FiddleFart
|
2
|
+
class Codepen
|
3
|
+
attr_accessor :id, :username
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
attrs.each { |k,v| instance_variable_set("@#{k}", v) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(url)
|
10
|
+
obj = self.new
|
11
|
+
host, domain, username, view, id = url.scan(/([^\/^:]+)/).flatten
|
12
|
+
obj.id = id
|
13
|
+
obj.username = username
|
14
|
+
obj
|
15
|
+
end
|
16
|
+
|
17
|
+
def share_link
|
18
|
+
"http://codepen.io/#{@username}/full/#{@id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit_link
|
22
|
+
"http://codepen.io/#{@username}/pen/#{@id}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def embed_url
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def as_json
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_json
|
34
|
+
{
|
35
|
+
edit_link: edit_link,
|
36
|
+
embed_url: embed_url,
|
37
|
+
share_link: share_link
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module FiddleFart
|
2
|
+
class Jsbin
|
3
|
+
attr_accessor :id, :revision
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
attrs.each { |k,v| instance_variable_set("@#{k}", v) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(url)
|
10
|
+
obj = self.new
|
11
|
+
host, domain, id, revision = url.scan(/([^\/^:]+)/).flatten
|
12
|
+
obj.id = id
|
13
|
+
obj.revision = revision
|
14
|
+
obj
|
15
|
+
end
|
16
|
+
|
17
|
+
def share_link
|
18
|
+
"http://jsbin.com/eVIyOTE/#{@id}/#{@revision}/"
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit_link
|
22
|
+
"http://jsbin.com/eVIyOTE/#{@id}/#{@revision}/edit"
|
23
|
+
end
|
24
|
+
|
25
|
+
def embed_url
|
26
|
+
"http://jsbin.com/#{@id}/#{@revision}/embed"
|
27
|
+
end
|
28
|
+
|
29
|
+
def as_json
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_json
|
34
|
+
{
|
35
|
+
edit_link: edit_link,
|
36
|
+
embed_url: embed_url,
|
37
|
+
share_link: share_link
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FiddleFart
|
2
|
+
class Jsfiddle
|
3
|
+
attr_accessor :id, :username, :revision
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
attrs.each { |k,v| instance_variable_set("@#{k}", v) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(url)
|
10
|
+
obj = self.new
|
11
|
+
host, domain, username, id, revision = url.scan(/([^\/^:]+)/).flatten
|
12
|
+
obj.id = id
|
13
|
+
obj.username = username
|
14
|
+
obj.revision = revision
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit_link
|
19
|
+
"http://jsfiddle.net/#{@username}/#{@id}/#{@revision}/"
|
20
|
+
end
|
21
|
+
|
22
|
+
def embed_url
|
23
|
+
"http://jsfiddle.net/#{@username}/#{@id}/#{@revision}/embedded/result/"
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :share_link, :embed_url
|
27
|
+
|
28
|
+
def as_json
|
29
|
+
{
|
30
|
+
edit_link: edit_link,
|
31
|
+
embed_url: embed_url,
|
32
|
+
share_link: share_link
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FiddleFart
|
2
|
+
class Parser
|
3
|
+
def self.parse(url)
|
4
|
+
if url.downcase.include? 'jsfiddle'
|
5
|
+
return Jsfiddle.parse(url)
|
6
|
+
elsif url.downcase.include? 'jsbin'
|
7
|
+
return Jsbin.parse(url)
|
8
|
+
elsif url.downcase.include? 'codepen.io'
|
9
|
+
return Codepen.parse(url)
|
10
|
+
elsif url.downcase.include? 'plnkr'
|
11
|
+
return Plnkr.parse(url)
|
12
|
+
else
|
13
|
+
raise "Invalid URL"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FiddleFart
|
2
|
+
class Plnkr
|
3
|
+
attr_accessor :id, :username
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
attrs.each { |k,v| instance_variable_set("@#{k}", v) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(url)
|
10
|
+
obj = self.new
|
11
|
+
if url.include?("embed.plnkr")
|
12
|
+
host, domain, id, view = url.scan(/([^\/^:]+)/).flatten
|
13
|
+
else
|
14
|
+
host, domain, view, id = url.scan(/([^\/^:]+)/).flatten
|
15
|
+
end
|
16
|
+
obj.id = id.split("?").first
|
17
|
+
obj
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit_link
|
21
|
+
"http://plnkr.co/edit/#{@id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def embed_url
|
25
|
+
"http://embed.plnkr.co/#{@id}/preview"
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :share_link, :embed_url
|
29
|
+
|
30
|
+
def as_json
|
31
|
+
{
|
32
|
+
edit_link: edit_link,
|
33
|
+
embed_url: embed_url,
|
34
|
+
share_link: share_link
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "FiddleFart" do
|
4
|
+
|
5
|
+
it "parser" do
|
6
|
+
["http://jsfiddle.net/cavneb/XbDEM/3/", "http://jsfiddle.net/cavneb/XbDEM/3/embedded/result/"].each do |url|
|
7
|
+
obj = FiddleFart::Parser.parse(url)
|
8
|
+
obj.should be_an_instance_of(FiddleFart::Jsfiddle)
|
9
|
+
end
|
10
|
+
["http://jsbin.com/eVIyOTE/3/edit", "http://jsbin.com/eVIyOTE/3/", "http://jsbin.com/eVIyOTE/3/edit?html,output",
|
11
|
+
"http://emberjs.jsbin.com/eVIyOTE/3/edit", "http://emberjs.jsbin.com/eVIyOTE/3/", "http://emberjs.jsbin.com/eVIyOTE/3/edit?html,css,js,output"].each do |url|
|
12
|
+
obj = FiddleFart::Parser.parse(url)
|
13
|
+
obj.should be_an_instance_of(FiddleFart::Jsbin)
|
14
|
+
end
|
15
|
+
["http://codepen.io/cxanthos/pen/hbgIL", "http://codepen.io/cxanthos/details/hbgIL"].each do |url|
|
16
|
+
obj = FiddleFart::Parser.parse(url)
|
17
|
+
obj.should be_an_instance_of(FiddleFart::Codepen)
|
18
|
+
end
|
19
|
+
["http://plnkr.co/edit/bN8Z0j?p=preview", "http://plnkr.co/edit/bN8Z0j", "http://embed.plnkr.co/bN8Z0j/preview"].each do |url|
|
20
|
+
obj = FiddleFart::Parser.parse(url)
|
21
|
+
obj.should be_an_instance_of(FiddleFart::Plnkr)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "jsfiddle" do
|
26
|
+
["http://jsfiddle.net/cavneb/XbDEM/3/", "http://jsfiddle.net/cavneb/XbDEM/3/embedded/result/"].each do |url|
|
27
|
+
it url do
|
28
|
+
pe = FiddleFart::Jsfiddle.parse(url)
|
29
|
+
pe.id.should == "XbDEM"
|
30
|
+
pe.username.should == "cavneb"
|
31
|
+
pe.revision.should == "3"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "jsbin" do
|
37
|
+
["http://jsbin.com/eVIyOTE/3/edit", "http://jsbin.com/eVIyOTE/3/", "http://jsbin.com/eVIyOTE/3/edit?html,output",
|
38
|
+
"http://emberjs.jsbin.com/eVIyOTE/3/edit", "http://emberjs.jsbin.com/eVIyOTE/3/", "http://emberjs.jsbin.com/eVIyOTE/3/edit?html,css,js,output"].each do |url|
|
39
|
+
it url do
|
40
|
+
pe = FiddleFart::Jsbin.parse(url)
|
41
|
+
pe.id.should == "eVIyOTE"
|
42
|
+
pe.revision.should == "3"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "codepen" do
|
48
|
+
["http://codepen.io/cxanthos/pen/hbgIL", "http://codepen.io/cxanthos/details/hbgIL"].each do |url|
|
49
|
+
it url do
|
50
|
+
pe = FiddleFart::Codepen.parse(url)
|
51
|
+
pe.id.should == "hbgIL"
|
52
|
+
pe.username.should == "cxanthos"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "plnkr" do
|
58
|
+
["http://plnkr.co/edit/bN8Z0j?p=preview", "http://plnkr.co/edit/bN8Z0j", "http://embed.plnkr.co/bN8Z0j/preview"].each do |url|
|
59
|
+
it url do
|
60
|
+
pe = FiddleFart::Plnkr.parse(url)
|
61
|
+
pe.id.should == "bN8Z0j"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fiddle_fart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Berry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: FiddleFart is the parsing tool which takes a URL from any of the following
|
56
|
+
services and normalizes the embed data.
|
57
|
+
email:
|
58
|
+
- cavneb@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- fiddle_fart.gemspec
|
70
|
+
- lib/fiddle_fart.rb
|
71
|
+
- lib/fiddle_fart/codepen.rb
|
72
|
+
- lib/fiddle_fart/jsbin.rb
|
73
|
+
- lib/fiddle_fart/jsfiddle.rb
|
74
|
+
- lib/fiddle_fart/parser.rb
|
75
|
+
- lib/fiddle_fart/plnkr.rb
|
76
|
+
- lib/fiddle_fart/version.rb
|
77
|
+
- spec/lib/fiddle_fart_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: https://github.com/cavneb/fiddle_fart
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Parse embed data from jsfiddle, jsbin, codepen and plnkr
|
103
|
+
test_files:
|
104
|
+
- spec/lib/fiddle_fart_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
has_rdoc:
|