mdarby-scribd_fu 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,69 @@
1
+ h1. Scribd_fu
2
+
3
+ A Ruby on Rails plugin that streamlines interaction with the Scribd service (scribd.com), and even works with Attachment_fu!
4
+
5
+
6
+ h2. What it does
7
+
8
+ Scribd_fu hides out in the shadows like a document converting ninja, just waiting to process your data into a convenient Flash format (like YouTube) with the help of the black majick of Scribd.com. Imagine imbedding huge documents right inline with your web UI, no downloading, no necessary programs on the client side to view your data. It’s pretty damned cool.
9
+
10
+
11
+ h2. Requirements
12
+
13
+ Scribd_fu requires the wicked awesome Attachment_fu plugin. You probably already have it installed.
14
+ You also need the rscribd gem (sudo gem install rscribd will do the trick)
15
+
16
+
17
+ h2. How to Install & Use
18
+
19
+ # Install the rscribd gem
20
+ <pre>gem install rscribd</pre>
21
+ # Install the scribd_fu gem
22
+ <pre>sudo gem install mdarby-scribd_fu</pre>
23
+ # Add this line to your config/environment.rb file
24
+ <pre>config.gem 'mdarby-scribd_fu', :lib => 'scribd_fu'</pre>
25
+ # Enter the below line into any attachment_fu-using model that you’d like to Scribdify
26
+ <pre>acts_as_scribd_document</pre>
27
+ # Add the following fields into a new migration for the target model (and update your schema!):
28
+ <pre>
29
+ t.integer :scribd_id
30
+ t.string :scribd_access_key
31
+ t.boolean :is_public
32
+ </pre>
33
+ # Sign up for Scribd (it’s totally free)
34
+ # Copy the vendor/plugins/scribd.yml.example file to config/scribd.yml and fill out with your Scribd login credentials
35
+ # Now, when you upload a file that is convertible in the Scribd system, Scribd_fu will automatically handle the CRUD for you. No muss, no fuss.
36
+
37
+
38
+ h2. Access
39
+
40
+ You can set the default access on all documents by setting the 'access' key in the scribd.yml file to either 'private' or 'public'
41
+
42
+ You can also override the default access level and control access on a per-document basis by setting the 'is_public' attribute to either true or false. If this column is not defined, the default option in the scribd.yml will be used.
43
+
44
+ Please note that setting the access level only works before the document is initially uploaded to Scribd.
45
+
46
+
47
+ h2. Displaying
48
+
49
+ To view a Scribd document, just throw the below code into your view (where @document is an object of your Scribd/Attachment_fu model):
50
+ <pre><%= display_scribd(@document) %></pre>
51
+
52
+ That’s it!
53
+
54
+
55
+ h2. Notes
56
+
57
+ Note that scribd_fu will only upload the file to scribd. Scribd then has to
58
+ convert it to their iPaper format. Usually this is a pretty fast operation, but
59
+ if you want to be safe or have a contingency plan in case someone tries to
60
+ access the document and it isn't converted yet, the set of methods
61
+ conversion_complete?, conversion_successful?, and conversion_error? can be used
62
+ to determine the current conversion status of the document.
63
+
64
+
65
+ h2. About the Author
66
+
67
+ My name is Matt Darby. I’m a 29 year old professional Web Developer and IT Manager. I am the IT Manager and Lead Web Developer at Dynamix Engineering and recently earned a Master’s Degree in Computer Science from Franklin University in Columbus, OH.
68
+
69
+ Feel free to check out my "blog":http://blgo.matt-darby.com or to "recommend me":http://workingwithrails.com
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the act_as_scribd_document plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the act_as_scribd_document plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ActAsScribdDocument'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/scribd_fu.rb ADDED
@@ -0,0 +1,179 @@
1
+ module Scribd_fu
2
+
3
+ def self.included(base)
4
+ base.extend ActsAsScribdObject
5
+ end
6
+
7
+ module ActsAsScribdObject
8
+ def acts_as_scribd_document(options = {})
9
+ class_eval <<-END
10
+ include Scribd_fu::InstanceMethods
11
+ END
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+ def self.extended(base)
17
+ base.class_inheritable_accessor :scribd_options
18
+ base.before_destroy :destroy_scribd_document
19
+ base.after_save :upload_to_scribd
20
+ end
21
+
22
+ def validates_as_scribd_document
23
+ validates_presence_of :scribd_id, :scribd_access_id, :content_type
24
+ validate :scribd_attributes_valid?
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ @@content_types = ['application/pdf', 'application/msword', 'application/mspowerpoint', 'application/vnd.ms-powerpoint',
30
+ 'application/excel', 'application/vnd.ms-excel', 'application/postscript', 'text/plain', 'application/rtf',
31
+ 'application/vnd.oasis.opendocument.text', 'vnd.oasis.opendocument.presentation',
32
+ 'application/vnd.sun.xml.writer', 'application/vnd.sun.xml.impress',
33
+ 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.sun.xml.calc']
34
+
35
+ mattr_reader :content_types
36
+
37
+ def self.included(base)
38
+ base.extend ClassMethods
39
+
40
+ mattr_reader :scribd_config, :scribd_login
41
+
42
+ begin
43
+ require 'rscribd'
44
+ rescue LoadError
45
+ raise RequiredLibraryNotFoundError.new('rscribd could not be loaded')
46
+ end
47
+
48
+ begin
49
+ unless @@scribd_login
50
+ @@scribd_config = YAML.load_file("#{RAILS_ROOT}/config/scribd.yml").symbolize_keys
51
+
52
+ # Ensure we can connect to the Service
53
+ Scribd::API.instance.key = @@scribd_config[:scribd]['key'].to_s.strip
54
+ Scribd::API.instance.secret = @@scribd_config[:scribd]['secret'].to_s.strip
55
+
56
+ @@scribd_login = Scribd::User.login @@scribd_config[:scribd]['user'].to_s.strip, @@scribd_config[:scribd]['password'].to_s.strip
57
+ end
58
+ rescue
59
+ raise "config/scribd.yml file not found, or your credentials are incorrect."
60
+ end
61
+ end
62
+
63
+ def scribd_attributes_valid?
64
+ [:scribd_id, :scribd_access_id].each do |attr_name|
65
+ enum = scribd_options[attr_name]
66
+ errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
67
+ end
68
+ end
69
+
70
+ def scribdable?
71
+ content_types.include?(content_type)
72
+ end
73
+
74
+ def scribd_id=(id)
75
+ write_attribute :scribd_id, id.to_s.strip
76
+ end
77
+
78
+ def scribd_access_key=(key)
79
+ write_attribute :scribd_access_key, key.to_s.strip
80
+ end
81
+
82
+ def destroy_scribd_document
83
+ if scribd_document
84
+ if scribd_document.destroy
85
+ logger.info "[Scribd_fu] #{Time.now.rfc2822}: Removing Object #{id} successful"
86
+ else
87
+ logger.info "[Scribd_fu] #{Time.now.rfc2822}: Removing Object #{id} failed!"
88
+ end
89
+ end
90
+ end
91
+
92
+ def access_level
93
+ if self.respond_to?(:is_public) && self.is_public != nil
94
+ scribd_access = self.is_public ? 'public' : 'private'
95
+ else
96
+ scribd_access = scribd_config[:scribd]['access']
97
+ end
98
+
99
+ scribd_access
100
+ end
101
+
102
+ def final_path
103
+ if scribd_config[:scribd]['storage'].eql?('s3')
104
+ file_path = s3_url
105
+ else
106
+ file_path = full_filename
107
+ end
108
+
109
+ file_path
110
+ end
111
+
112
+ def upload_to_scribd
113
+ if scribdable? and self.scribd_id.blank?
114
+
115
+ if resource = scribd_login.upload(:file => "#{final_path}", :access => access_level)
116
+ logger.info "[Scribd_fu] #{Time.now.rfc2822}: Object #{id} successfully uploaded for conversion to iPaper."
117
+
118
+ self.scribd_id = resource.doc_id
119
+ self.scribd_access_key = resource.access_key
120
+
121
+ save
122
+ else
123
+ logger.info "[Scribd_fu] #{Time.now.rfc2822}: Object #{id} upload failed!"
124
+ end
125
+ end
126
+ end
127
+
128
+ # Sample of use in a view:
129
+ # image_tag(@attachment).thumbnail_url, :alt => @attachment.name)
130
+ def thumbnail_url
131
+ scribd_document ? scribd_document.thumbnail_url : nil
132
+ end
133
+
134
+ # Sample of use in a controller:
135
+ # render :inline => @attachment.thumbnail_file, :content_type => 'image/jpeg'
136
+ def thumbnail_file
137
+ scribd_document ? open(scribd_document.thumbnail_url).read : nil
138
+ end
139
+
140
+ # Responds true if the conversion is complete -- note that this gives no
141
+ # indication as to whether the conversion had an error or was succesful,
142
+ # just that the conversion completed.
143
+ #
144
+ # Note that this method still returns false if the model does not refer to a
145
+ # valid document. scribd_attributes_valid? should be used to determine the
146
+ # validity of the document.
147
+ def conversion_complete?
148
+ scribd_document && scribd_document.conversion_status != 'PROCESSING'
149
+ end
150
+
151
+ # Responds true if the document has been converted.
152
+ #
153
+ # Note that this method still returns false if the model does not refer to a
154
+ # valid document. scribd_attributes_valid? should be used to determine the
155
+ # validity of the document.
156
+ def conversion_successful?
157
+ scribd_document && scribd_document.conversion_status =~ /^DISPLAYABLE|DONE$/
158
+ end
159
+
160
+ # Responds true if there was a conversion error while converting
161
+ # to iPaper.
162
+ #
163
+ # Note that this method still returns false if the model does not refer to a
164
+ # valid document. scribd_attributes_valid? should be used to determine the
165
+ # validity of the document.
166
+ def conversion_error?
167
+ scribd_document && scribd_document.conversion_status == 'ERROR'
168
+ end
169
+
170
+ # Responds the Scribd::Document associated with this model, or nil if it
171
+ # does not exist.
172
+ def scribd_document
173
+ @scribd_document ||= scribd_login.find_document(scribd_id)
174
+ rescue Scribd::ResponseError # at minimum, the document was not found
175
+ nil
176
+ end
177
+ end
178
+
179
+ end
@@ -0,0 +1,14 @@
1
+ module Scribd_fu_Helper
2
+
3
+ def display_scribd(object, alt_text = '')
4
+ <<-END
5
+ <script type=\"text/javascript\" src=\"http://www.scribd.com/javascripts/view.js\"></script>
6
+ <div id=\"embedded_flash\">#{alt_text}</div>
7
+ <script type=\"text/javascript\">
8
+ var scribd_doc = scribd.Document.getDoc(#{object.scribd_id}, '#{object.scribd_access_key}');
9
+ scribd_doc.write(\"embedded_flash\");
10
+ </script>
11
+ END
12
+ end
13
+
14
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'scribd_fu'
2
+ require 'scribd_fu_helper'
3
+
4
+ ActiveRecord::Base.send(:include, Scribd_fu)
5
+ ActionView::Base.send(:include, Scribd_fu_Helper)
6
+
7
+ RAILS_DEFAULT_LOGGER.debug "** [Scribd_fu] loaded"
@@ -0,0 +1,9 @@
1
+ #Scribd Account Info
2
+
3
+ scribd:
4
+ key:
5
+ secret:
6
+ user:
7
+ password:
8
+ access:
9
+ #storage: s3 # Uncomment if Attachment_fu is using Amazon S3 for storage
data/scribd_fu.gemspec ADDED
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "scribd_fu"
3
+ s.version = "1.1"
4
+ s.date = "2008-12-14"
5
+ s.summary = "Quick and easy interactions with Scribd's iPaper service"
6
+ s.email = "matt@matt-darby.com"
7
+ s.homepage = "http://github.com/mdarby/scribd_fu/tree/master"
8
+ s.description = "A Rails plugin that streamlines interactions with the Scribd service"
9
+ s.has_rdoc = false
10
+ s.authors = ["Matt Darby"]
11
+ s.files = ["init.rb", "install.rb", "lib/scribd_fu.rb", "lib/scribd_fu_helper.rb", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.textile", "scribd.yml.example", "scribd_fu.gemspec", "uninstall.rb"]
12
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdarby-scribd_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.1"
5
+ platform: ruby
6
+ authors:
7
+ - Matt Darby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A Rails plugin that streamlines interactions with the Scribd service
17
+ email: matt@matt-darby.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - init.rb
26
+ - install.rb
27
+ - lib/scribd_fu.rb
28
+ - lib/scribd_fu_helper.rb
29
+ - MIT-LICENSE
30
+ - rails/init.rb
31
+ - Rakefile
32
+ - README.textile
33
+ - scribd.yml.example
34
+ - scribd_fu.gemspec
35
+ - uninstall.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/mdarby/scribd_fu/tree/master
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Quick and easy interactions with Scribd's iPaper service
62
+ test_files: []
63
+