onebox 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88403edb6cdc6198f956ebbbfa444ab6855098df
4
- data.tar.gz: 0dbd27e20e524df654834fdfac709b3590cad2d2
3
+ metadata.gz: 292535107d74004655646908fd33b6a4aba4229c
4
+ data.tar.gz: 7b2da58a31b11b745b7f0e4cffa96c050f190637
5
5
  SHA512:
6
- metadata.gz: d5f8f6bcc6892fc0e6dff02e6264db3f8be631004353cf63ca2a6dbc0b07f07843549a4180a895a64c98b8a87be451e23b1520306485e3c5a73fd3b9d2b6acfb
7
- data.tar.gz: 56927cce2f14d3b7149352f78ebfe3f8e91131fc1c17896f78855bf97924022b38ae373ef1ef2cb26855409c9b215a824b1943c198b71b72689323b778bb77a5
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", "~> <%= version %>"
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
 
@@ -38,7 +38,16 @@ module Onebox
38
38
  end
39
39
 
40
40
  def template
41
- File.read(File.join("templates", "#{template_name}.handlebars"))
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
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.0.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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta