docsplit_images 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
14
+
15
+ gem 'paperclip', '3.3.1'
16
+ gem 'docsplit', '0.6.4'
17
+ gem 'delayed_job_active_record', '0.3.2'
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.9)
5
+ activesupport (= 3.2.9)
6
+ builder (~> 3.0.0)
7
+ activerecord (3.2.9)
8
+ activemodel (= 3.2.9)
9
+ activesupport (= 3.2.9)
10
+ arel (~> 3.0.2)
11
+ tzinfo (~> 0.3.29)
12
+ activesupport (3.2.9)
13
+ i18n (~> 0.6)
14
+ multi_json (~> 1.0)
15
+ arel (3.0.2)
16
+ builder (3.0.4)
17
+ cocaine (0.4.2)
18
+ delayed_job (3.0.4)
19
+ activesupport (~> 3.0)
20
+ delayed_job_active_record (0.3.2)
21
+ activerecord (> 2.1.0)
22
+ delayed_job (~> 3.0.0)
23
+ docsplit (0.6.4)
24
+ git (1.2.5)
25
+ i18n (0.6.1)
26
+ jeweler (1.8.4)
27
+ bundler (~> 1.0)
28
+ git (>= 1.2.5)
29
+ rake
30
+ rdoc
31
+ json (1.7.5)
32
+ mime-types (1.19)
33
+ multi_json (1.3.7)
34
+ paperclip (3.3.1)
35
+ activemodel (>= 3.0.0)
36
+ activerecord (>= 3.0.0)
37
+ activesupport (>= 3.0.0)
38
+ cocaine (~> 0.4.0)
39
+ mime-types
40
+ rake (10.0.2)
41
+ rdoc (3.12)
42
+ json (~> 1.4)
43
+ shoulda (3.3.2)
44
+ shoulda-context (~> 1.0.1)
45
+ shoulda-matchers (~> 1.4.1)
46
+ shoulda-context (1.0.1)
47
+ shoulda-matchers (1.4.1)
48
+ activesupport (>= 3.0.0)
49
+ tzinfo (0.3.35)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler
56
+ delayed_job_active_record (= 0.3.2)
57
+ docsplit (= 0.6.4)
58
+ jeweler (~> 1.8.4)
59
+ paperclip (= 3.3.1)
60
+ rdoc (~> 3.12)
61
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 jameshuynh
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.markdown ADDED
@@ -0,0 +1,43 @@
1
+ # docsplit_images
2
+
3
+ Docsplit images is used to convert a document file (pdf, xls, xlsx, ppt, pptx, doc, docx, etc...) to a list of images
4
+
5
+ ## Installation
6
+
7
+ gem 'docsplit_images', '0.1.1', :git => 'git@github.com:RubifyTechnology/docsplit_images.git'
8
+
9
+ ## Setting Up
10
+
11
+ From terminal, type the command to install
12
+
13
+ bundle
14
+ rails g docsplit_images <table_name> <attachment_field_name>
15
+ # e.g rails generate docsplit_images asset document
16
+ rake db:migrate
17
+
18
+ In your model:
19
+
20
+ class Asset < ActiveRecord::Base
21
+ ...
22
+ attr_accessible :document
23
+ has_attached_file :document
24
+ docsplit_images_conversion_for :document
25
+ ...
26
+ end
27
+
28
+ ## Accessing list of images using ``document_images_list``
29
+
30
+ ``document_images_list`` will return a list of URL of images converting from the document
31
+
32
+ asset.document_images_list
33
+ # => [
34
+ "/system/myfile_revisions/files/000/000/019/images/SBA_Admin_workflow_1.png",
35
+ "/system/myfile_revisions/files/000/000/019/images/SBA_Admin_workflow_2.png", ...
36
+ ]
37
+
38
+ Then open your browser at http://localhost:3000 and fill in username: superadmin, password: password to login
39
+
40
+ * To configure email sender for devise, you can change it in ``config/config.yml`` - ``email_sender`` option
41
+ * You can configure application name in ``config/config.yml`` - ``project_name`` option
42
+
43
+ ## Usage
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = docsplit_images
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to docsplit_images
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 jameshuynh. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "docsplit_images"
18
+ gem.homepage = "http://github.com/jameshuynh/docsplit_images"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Split Images for your document}
21
+ gem.description = %Q{Split Images for your document in one line of code}
22
+ gem.email = "james@rubify.com"
23
+ gem.authors = ["jameshuynh"]
24
+ gem.version = File.exist?('VERSION') ? File.read('VERSION') : ""
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "docsplit_images #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "docsplit_images"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jameshuynh"]
12
+ s.date = "2012-11-22"
13
+ s.description = "Split Images for your document in one line of code"
14
+ s.email = "james@rubify.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "docsplit_images.gemspec",
30
+ "lib/docsplit_images.rb",
31
+ "lib/docsplit_images/conversion.rb",
32
+ "lib/generators/docsplit_images/docsplit_images_generator.rb",
33
+ "lib/generators/docsplit_images/templates/docsplit_images_migration.rb.erb",
34
+ "test/helper.rb",
35
+ "test/test_docsplit_images.rb"
36
+ ]
37
+ s.homepage = "http://github.com/jameshuynh/docsplit_images"
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.24"
41
+ s.summary = "Split Images for your document"
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<paperclip>, ["= 3.3.1"])
48
+ s.add_runtime_dependency(%q<docsplit>, ["= 0.6.4"])
49
+ s.add_runtime_dependency(%q<delayed_job_active_record>, ["= 0.3.2"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_development_dependency(%q<bundler>, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
54
+ else
55
+ s.add_dependency(%q<paperclip>, ["= 3.3.1"])
56
+ s.add_dependency(%q<docsplit>, ["= 0.6.4"])
57
+ s.add_dependency(%q<delayed_job_active_record>, ["= 0.3.2"])
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<paperclip>, ["= 3.3.1"])
65
+ s.add_dependency(%q<docsplit>, ["= 0.6.4"])
66
+ s.add_dependency(%q<delayed_job_active_record>, ["= 0.3.2"])
67
+ s.add_dependency(%q<shoulda>, [">= 0"])
68
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
69
+ s.add_dependency(%q<bundler>, [">= 0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,71 @@
1
+ module DocsplitImages
2
+ module Conversion
3
+ def self.included(base)
4
+
5
+ base.before_save :check_for_file_change
6
+ base.after_save :docsplit_images
7
+
8
+ def check_for_file_change
9
+ @file_has_changed = self.file.dirty?
10
+ true
11
+ end
12
+
13
+ def docsplit_images
14
+ if self.is_pdf_convertible? and @file_has_changed == true
15
+ self.delay.docsplit_images_process
16
+ end
17
+ true
18
+ end
19
+
20
+ def docsplit_images_process
21
+ parent_dir = File.dirname(File.dirname(self.send(self.class.docsplit_attachment_name).path))
22
+ FileUtils.rm_rf("#{parent_dir}/images")
23
+ FileUtils.mkdir("#{parent_dir}/images")
24
+ Docsplit.extract_images(self.send(self.class.docsplit_attachment_name).path, {:output => "#{parent_dir}/images"})
25
+ self.number_of_images_entry = Dir.entries("#{parent_dir}/images").size - 2
26
+ @file_has_changed = false
27
+ self.save(:validate => false)
28
+ end
29
+
30
+ ## paperclip overriding
31
+ def prepare_for_destroy
32
+ parent_dir = File.dirname(File.dirname(self.send(self.class.docsplit_attachment_name).path))
33
+ FileUtils.rm_rf("#{parent_dir}/images")
34
+ super
35
+ end
36
+
37
+ def is_pdf_convertible?
38
+ extname = File.extname(self.send("#{self.class.docsplit_attachment_name}_file_name")).downcase.gsub(".", "")
39
+ return ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp'].index( extname ) != nil
40
+ end
41
+
42
+ def document_images_folder
43
+ return "#{File.dirname(File.dirname(self.send(self.class.docsplit_attachment_name).url))}/images"
44
+ end
45
+
46
+ def document_images_list
47
+ if self.is_pdf_convertible?
48
+ list = []
49
+ image_base_folder = document_images_folder
50
+ original_file_name = File.basename(self.send(self.class.docsplit_attachment_name).url, ".*")
51
+ for i in 1..self.number_of_images_entry
52
+ list.push("#{image_base_folder}/#{original_file_name}_#{i}.png")
53
+ end
54
+ return list
55
+ else
56
+ return []
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ module ClassMethods
63
+ def docsplit_images_conversion_for(attribute)
64
+ self.instance_eval do
65
+ cattr_accessor :docsplit_attachment_name
66
+ self.docsplit_attachment_name = attribute
67
+ end
68
+ self.send(:include, DocsplitImages::Conversion)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'docsplit_images/conversion'
3
+ module DocsplitImages
4
+ class Engine < Rails::Engine
5
+ ActiveRecord::Base.send(:extend, DocsplitImages::ClassMethods)
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class DocsplitImagesGenerator < ActiveRecord::Generators::Base
4
+ argument :attachment_names, :required => true, :type => :array, :desc => "The names of the attachment(s) to add.",
5
+ :banner => "attachment_one attachment_two attachment_three ..."
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path('../templates', __FILE__)
9
+ end
10
+
11
+ def generate_migration
12
+ migration_template "docsplit_images_migration.rb.erb", "db/migrate/#{migration_file_name}"
13
+ end
14
+
15
+ protected
16
+
17
+ def migration_name
18
+ "add_docsplit_images_attribute_to_#{name.underscore.pluralize}"
19
+ end
20
+
21
+ def migration_file_name
22
+ "#{migration_name}.rb"
23
+ end
24
+
25
+ def migration_class_name
26
+ migration_name.camelize
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :<%= table_name %>, :number_of_images_entry, :integer, :default => 0
4
+ end
5
+
6
+ def self.down
7
+ remove_column :<%= table_name %>, :number_of_images_entry
8
+ end
9
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'docsplit_images'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestDocsplitImages < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docsplit_images
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - jameshuynh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-11-22 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: paperclip
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: docsplit
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: delayed_job_active_record
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.3.2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rdoc
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: "3.12"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: jeweler
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 1.8.4
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
92
+ description: Split Images for your document in one line of code
93
+ email: james@rubify.com
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.markdown
101
+ - README.rdoc
102
+ files:
103
+ - .document
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.markdown
108
+ - README.rdoc
109
+ - Rakefile
110
+ - VERSION
111
+ - docsplit_images.gemspec
112
+ - lib/docsplit_images.rb
113
+ - lib/docsplit_images/conversion.rb
114
+ - lib/generators/docsplit_images/docsplit_images_generator.rb
115
+ - lib/generators/docsplit_images/templates/docsplit_images_migration.rb.erb
116
+ - test/helper.rb
117
+ - test/test_docsplit_images.rb
118
+ homepage: http://github.com/jameshuynh/docsplit_images
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: -2321886849909627303
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.24
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Split Images for your document
148
+ test_files: []
149
+