onebox 1.0.0 → 1.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 +4 -4
- data/README.md +88 -6
- data/lib/onebox/engine.rb +10 -1
- data/lib/onebox/version.rb +2 -2
- data/spec/lib/onebox/engine_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 292535107d74004655646908fd33b6a4aba4229c
|
4
|
+
data.tar.gz: 7b2da58a31b11b745b7f0e4cffa96c050f190637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 544481fff1bba95af38f1467c35b509d5aa8f6a725f6912ab7f63d31055f2d0073ffce2962b3d546eb06834ddc2d81bcb01eb108d963661c4987e2729b590a23
|
7
|
+
data.tar.gz: 8b7970957af9cd698f52e242d6092acbaca945dd8fbe3f45617d471562c787b8c00b7223846342ca5cd08f4801b097e4fee9892b9d6ae8973ced5c4e34f7d67f
|
data/README.md
CHANGED
@@ -47,14 +47,9 @@ Onebox currently has support for page, image, and video URLs from these sites:
|
|
47
47
|
Using onebox
|
48
48
|
===============
|
49
49
|
|
50
|
-
You can include onebox modules into a class like so:
|
51
|
-
|
52
50
|
``` ruby
|
53
51
|
require "onebox"
|
54
52
|
```
|
55
|
-
TODO: write example
|
56
|
-
|
57
|
-
|
58
53
|
|
59
54
|
The `Gemfile` file would look like this:
|
60
55
|
|
@@ -62,7 +57,94 @@ The `Gemfile` file would look like this:
|
|
62
57
|
# source/Gemfile
|
63
58
|
source "https://rubygems.org"
|
64
59
|
|
65
|
-
gem "onebox", "~>
|
60
|
+
gem "onebox", "~> 1.0"
|
61
|
+
```
|
62
|
+
|
63
|
+
How to create a new onebox
|
64
|
+
===========================
|
65
|
+
|
66
|
+
1. Create new onebox engine
|
67
|
+
|
68
|
+
``` ruby
|
69
|
+
# in lib/onebox/engine/name_onebox.rb
|
70
|
+
|
71
|
+
module Onebox
|
72
|
+
module Engine
|
73
|
+
class NameOnebox
|
74
|
+
include Engine
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def extracted_data
|
79
|
+
{
|
80
|
+
url: @url,
|
81
|
+
name: @body.css("h1").inner_text,
|
82
|
+
image: @body.css("#main-image").first["src"],
|
83
|
+
description: @body.css("#postBodyPS").inner_text
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
2. Create new onebox spec
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
# in spec/lib/onebox/engine/name_spec.rb
|
95
|
+
require "spec_helper"
|
96
|
+
|
97
|
+
describe Onebox::Engine::NameOnebox do
|
98
|
+
let(:link) { "http://yoursitename.com" }
|
99
|
+
let(:html) { described_class.new(link).to_html }
|
100
|
+
|
101
|
+
before do
|
102
|
+
fake(link, response("name.response"))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns video title" do
|
106
|
+
expect(html).to include("title")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns video photo" do
|
110
|
+
expect(html).to include("photo.jpg")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns video description" do
|
114
|
+
expect(html).to include("description")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns URL" do
|
118
|
+
expect(html).to include(link)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
3. Create new handlebars template
|
124
|
+
|
125
|
+
``` html
|
126
|
+
# in templates/name.handlebars
|
127
|
+
<div class="onebox">
|
128
|
+
<a href="{{url}}">
|
129
|
+
<h1>{{name}}</h1>
|
130
|
+
<h2 class="host">yoursitename.com</h2>
|
131
|
+
<img src="{{image}}" />
|
132
|
+
<p>{{description}}</p>
|
133
|
+
</a>
|
134
|
+
</div>
|
135
|
+
```
|
136
|
+
|
137
|
+
4. Create new fixture from HTML response
|
138
|
+
|
139
|
+
``` bash
|
140
|
+
curl --output spec/fixtures/name.response -L -X -GET http://yoursitename.com
|
141
|
+
```
|
142
|
+
|
143
|
+
5. Require in Engine module
|
144
|
+
|
145
|
+
``` ruby
|
146
|
+
# in lib/onebox/engine/engine.rb
|
147
|
+
require_relative "engine/name_onebox"
|
66
148
|
```
|
67
149
|
|
68
150
|
|
data/lib/onebox/engine.rb
CHANGED
@@ -38,7 +38,16 @@ module Onebox
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def template
|
41
|
-
File.read(
|
41
|
+
File.read(template_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def template_path
|
45
|
+
File.join(root, "templates", "#{template_name}.handlebars")
|
46
|
+
end
|
47
|
+
|
48
|
+
# returns the gem root directory
|
49
|
+
def root
|
50
|
+
Gem::Specification.find_by_name("onebox").gem_dir
|
42
51
|
end
|
43
52
|
|
44
53
|
# calculates handlebars template name for onebox using name of engine
|
data/lib/onebox/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Onebox
|
2
|
-
VERSION = "1.0.
|
3
|
-
end
|
2
|
+
VERSION = "1.0.1"
|
3
|
+
end
|
@@ -51,6 +51,16 @@ describe Onebox::Engine do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe "#template_path" do
|
55
|
+
it "returns file path for onebox template" do
|
56
|
+
class OneboxEngineVoo
|
57
|
+
include Onebox::Engine
|
58
|
+
end
|
59
|
+
result = OneboxEngineVoo.new("http://amazon.com").send(:template_path)
|
60
|
+
expect(result).to eq("/home/jzeta/Projects/rgsoc/onebox/templates/enginevoo.handlebars")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
54
64
|
describe ".===" do
|
55
65
|
it "returns true if argument matches the matcher" do
|
56
66
|
class OneboxEngineFoo
|