lib/scribd_fu.rb in mdarby-scribd_fu-2.0.3 vs lib/scribd_fu.rb in mdarby-scribd_fu-2.0.4
- old
+ new
@@ -27,10 +27,13 @@
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template'
]
+ # RegExp that matches AWS S3 URLs
+ S3 = /^https?:\/\/s3.amazonaws.com/
+
# Available parameters for the JS API
# http://www.scribd.com/publisher/api/api?method_name=Javascript+API
Available_JS_Params = [ :height, :width, :page, :my_user_id, :search_query,
:jsapi_version, :disable_related_docs, :mode, :auto_size ]
@@ -87,15 +90,13 @@
config[:access] || 'private'
end
# Load, store, and return the associated iPaper document
def load_ipaper_document(id)
- begin
- @document ||= scribd_user.find_document(id)
- rescue
- raise ScribdFuError, "Scribd Document ##{id} not found!"
- end
+ # Yes, catch-all rescues are bad, but the end rescue
+ # should return nil, so laziness FTW.
+ scribd_user.find_document(id) rescue nil
end
# Replace spaces with '%20' (needed by Paperclip models).
def escape(str)
str.gsub(' ', '%20')
@@ -219,15 +220,13 @@
ScribdFu::destroy(ipaper_document) if ipaper_document
end
# Display the iPaper document in a view
def display_ipaper(options = {})
- alt = options.has_key?(:alt) ? options[:alt] : ""
-
<<-END
<script type="text/javascript" src="http://www.scribd.com/javascripts/view.js"></script>
- <div id="embedded_flash">#{alt}</div>
+ <div id="embedded_flash">#{options.delete(:alt)}</div>
<script type="text/javascript">
var scribd_doc = scribd.Document.getDoc(#{ipaper_id}, '#{ipaper_access_key}');
#{js_params(options)}
scribd_doc.write("embedded_flash");
</script>
@@ -251,6 +250,6 @@
end
end
# Let's do this.
-ActiveRecord::Base.send(:include, ScribdFu) if Object.const_defined?("ActiveRecord")
\ No newline at end of file
+ActiveRecord::Base.send(:include, ScribdFu) if Object.const_defined?("ActiveRecord")