mdarby-scribd_fu 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scribd_fu.rb +8 -9
- data/lib/scribd_fu/attachment_fu.rb +4 -14
- data/lib/scribd_fu/paperclip.rb +3 -14
- data/scribd_fu.gemspec +2 -2
- data/spec/scribd_fu_spec.rb +8 -0
- metadata +2 -2
data/lib/scribd_fu.rb
CHANGED
@@ -29,6 +29,9 @@ module ScribdFu
|
|
29
29
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.template'
|
30
30
|
]
|
31
31
|
|
32
|
+
# RegExp that matches AWS S3 URLs
|
33
|
+
S3 = /^https?:\/\/s3.amazonaws.com/
|
34
|
+
|
32
35
|
# Available parameters for the JS API
|
33
36
|
# http://www.scribd.com/publisher/api/api?method_name=Javascript+API
|
34
37
|
Available_JS_Params = [ :height, :width, :page, :my_user_id, :search_query,
|
@@ -89,11 +92,9 @@ module ScribdFu
|
|
89
92
|
|
90
93
|
# Load, store, and return the associated iPaper document
|
91
94
|
def load_ipaper_document(id)
|
92
|
-
|
93
|
-
|
94
|
-
rescue
|
95
|
-
raise ScribdFuError, "Scribd Document ##{id} not found!"
|
96
|
-
end
|
95
|
+
# Yes, catch-all rescues are bad, but the end rescue
|
96
|
+
# should return nil, so laziness FTW.
|
97
|
+
scribd_user.find_document(id) rescue nil
|
97
98
|
end
|
98
99
|
|
99
100
|
# Replace spaces with '%20' (needed by Paperclip models).
|
@@ -221,11 +222,9 @@ module ScribdFu
|
|
221
222
|
|
222
223
|
# Display the iPaper document in a view
|
223
224
|
def display_ipaper(options = {})
|
224
|
-
alt = options.has_key?(:alt) ? options[:alt] : ""
|
225
|
-
|
226
225
|
<<-END
|
227
226
|
<script type="text/javascript" src="http://www.scribd.com/javascripts/view.js"></script>
|
228
|
-
<div id="embedded_flash">#{alt}</div>
|
227
|
+
<div id="embedded_flash">#{options.delete(:alt)}</div>
|
229
228
|
<script type="text/javascript">
|
230
229
|
var scribd_doc = scribd.Document.getDoc(#{ipaper_id}, '#{ipaper_access_key}');
|
231
230
|
#{js_params(options)}
|
@@ -253,4 +252,4 @@ module ScribdFu
|
|
253
252
|
end
|
254
253
|
|
255
254
|
# Let's do this.
|
256
|
-
ActiveRecord::Base.send(:include, ScribdFu) if Object.const_defined?("ActiveRecord")
|
255
|
+
ActiveRecord::Base.send(:include, ScribdFu) if Object.const_defined?("ActiveRecord")
|
@@ -5,36 +5,26 @@ module ScribdFu
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module InstanceMethods
|
8
|
-
|
8
|
+
|
9
9
|
def self.included(base)
|
10
10
|
base.extend ClassMethods
|
11
11
|
end
|
12
12
|
|
13
13
|
# Returns a URL for a thumbnail for this model's attachment.
|
14
|
-
#
|
15
|
-
# If Scribd does not provide a thumbnail URL, then Attachment_fu's
|
16
|
-
# thumbnail is fallen back on by returning the value of
|
17
|
-
# <tt>public_filename(:thumb)</tt>.
|
18
|
-
#
|
19
|
-
# Sample use in a view:
|
20
|
-
# <%= image_tag(@attachment.thumbnail_url, :alt => @attachment.name) %>
|
21
14
|
def thumbnail_url
|
22
15
|
(ipaper_document && ipaper_document.thumbnail_url) || public_filename(:thumb)
|
23
16
|
end
|
24
17
|
|
18
|
+
# Returns the content type for this model's attachment.
|
25
19
|
def get_content_type
|
26
20
|
self.content_type
|
27
21
|
end
|
28
22
|
|
29
23
|
# Yields the correct path to the file, either the local filename or the S3 URL.
|
30
24
|
def file_path
|
31
|
-
|
32
|
-
public_filename
|
33
|
-
else
|
34
|
-
"#{RAILS_ROOT}/public#{public_filename}"
|
35
|
-
end
|
25
|
+
public_filename =~ ScribdFu::S3 ? public_filename : "#{RAILS_ROOT}/public#{public_filename}"
|
36
26
|
end
|
37
27
|
end
|
38
|
-
|
28
|
+
|
39
29
|
end
|
40
30
|
end
|
data/lib/scribd_fu/paperclip.rb
CHANGED
@@ -5,7 +5,7 @@ module ScribdFu
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module InstanceMethods
|
8
|
-
|
8
|
+
|
9
9
|
def self.included(base)
|
10
10
|
base.extend ClassMethods
|
11
11
|
end
|
@@ -15,14 +15,7 @@ module ScribdFu
|
|
15
15
|
self.send("#{prefix}_content_type")
|
16
16
|
end
|
17
17
|
|
18
|
-
# Returns a URL for a thumbnail for the
|
19
|
-
#
|
20
|
-
# If Scribd does not provide a thumbnail URL, then Paperclip's thumbnail
|
21
|
-
# is fallen back on by returning the value of
|
22
|
-
# <tt>attribute.url(:thumb)</tt>.
|
23
|
-
#
|
24
|
-
# Sample use in a view:
|
25
|
-
# <%= image_tag(@attachment.thumbnail_url, :alt => @attachment.name) %>
|
18
|
+
# Returns a URL for a thumbnail for the attached file object.
|
26
19
|
def thumbnail_url
|
27
20
|
begin
|
28
21
|
(ipaper_document && ipaper_document.thumbnail_url) || attached_file.url(:thumb)
|
@@ -35,11 +28,7 @@ module ScribdFu
|
|
35
28
|
# stored on S3, this is a full S3 URI, while it is a full path to the
|
36
29
|
# local file if the file is stored locally.
|
37
30
|
def file_path
|
38
|
-
|
39
|
-
attached_file.url
|
40
|
-
else
|
41
|
-
attached_file.path
|
42
|
-
end
|
31
|
+
attached_file.url =~ ScribdFu::S3 ? attached_file.url : attached_file.path
|
43
32
|
end
|
44
33
|
|
45
34
|
|
data/scribd_fu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "scribd_fu"
|
3
|
-
s.version = "2.0.
|
4
|
-
s.date = "2009-04-
|
3
|
+
s.version = "2.0.4"
|
4
|
+
s.date = "2009-04-12"
|
5
5
|
s.summary = "Quick and easy interactions with Scribd's iPaper service"
|
6
6
|
s.email = "matt@matt-darby.com"
|
7
7
|
s.homepage = "http://github.com/mdarby/scribd_fu/tree/master"
|
data/spec/scribd_fu_spec.rb
CHANGED
@@ -105,6 +105,10 @@ describe "An AttachmentFu model" do
|
|
105
105
|
@document.save
|
106
106
|
end
|
107
107
|
|
108
|
+
it "should not error out when deleted" do
|
109
|
+
lambda {@document.destroy}.should_not raise_error(ScribdFu::ScribdFuError)
|
110
|
+
end
|
111
|
+
|
108
112
|
end
|
109
113
|
|
110
114
|
end
|
@@ -283,6 +287,10 @@ describe "Viewing an iPaper document" do
|
|
283
287
|
@document.display_ipaper.gsub(/\s{2,}/, "").should == "<script type=\"text/javascript\" src=\"http://www.scribd.com/javascripts/view.js\"></script><div id=\"embedded_flash\"></div><script type=\"text/javascript\">var scribd_doc = scribd.Document.getDoc(doc_id, 'access_key');scribd_doc.write(\"embedded_flash\");</script>\n"
|
284
288
|
end
|
285
289
|
|
290
|
+
it "should allow custom alt text" do
|
291
|
+
@document.display_ipaper(:alt => "something").should =~ /.*<div id="embedded_flash">something<\/div>.*/
|
292
|
+
end
|
293
|
+
|
286
294
|
it "should allow custom Javascript params" do
|
287
295
|
options = {:height => 100, :width => 100}
|
288
296
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdarby-scribd_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Darby
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|