asposeslides 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe0567df4a3a8940985484d6884fecc962d45243
4
+ data.tar.gz: df20b69632d3ef5ac3e1bcc178b94a9256caf00b
5
+ SHA512:
6
+ metadata.gz: 43af50b1b93e29141fb9044f84bef344a0af5277ed0518483f04345b299577a0516fb4a80ce4eb961c2a898cbabbc1a42871d6122a1d300555f913f436fef148
7
+ data.tar.gz: c36ebad06841035a61b7a82f81fc43a75336a0fb6efb2f871c248d6b7f92d0e8cd2b9dce2bd19799b229fb866d95c04c02f3306df85325ef4818c755e44a3501
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
16
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asposeslides.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sanjeev Mishra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Asposeslides
2
+
3
+ Aspose slides is a gem that helps you use the aspose slides for JAVA (http://docs.aspose.com:8082/docs/display/slidesjava/Product+Overview) library from within your ruby/rails project. This library has been tested with aspose.slides-14.9.0
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'asposeslides'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install asposeslides
20
+
21
+ ## Usage : Rails app
22
+
23
+ * Create a file aspose.yml under app/config folder. This file specifies the path to your aspose slides for Java path. Put the following lines in that file:
24
+ ```yaml
25
+ development:
26
+ jar_dir: /path/to/your/asposeslides/jars/directory
27
+ test:
28
+ jar_dir: /path/to/your/asposeslides/jars/directory
29
+ ```
30
+ * Next you need to initialize the aspose library. Aspose is a paid library and therefor you need to buy the appropriate license and provide the path to the licensed java library to initialize the gem.
31
+ * Create a file called aspose.rb under the initializer app/config/initializers folder. Put the following lines in the file
32
+ ```ruby
33
+ Asposeslides.configure_aspose_slides YAML.load(File.read('config/aspose.yml'))[Rails.env]
34
+ ```
35
+ * Now is the time to include the required files for working with the powerpoint presentations. Following is an example of merging 2 presentations into one:
36
+ ```ruby
37
+ require 'asposeslides'
38
+ include Asposeslides
39
+ include Asposeslides::Powerpoint
40
+ initialize_aspose
41
+ dest_ppt = File.join('dest_template.pptx')
42
+ src_ppt1 = File.join('src_template1.pptx')
43
+ src_ppt2 = File.join('src_template2.pptx')
44
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt1, :position => 2, :replace => true}, {:ppt => src_ppt2, :position => 5, :replace => true}])
45
+ merged_ppt.save("merged.pptx",3)
46
+ ```
47
+
48
+ Lets understand the above code
49
+ 1. The first line makes sure that the aspose slides is loaded and available
50
+ 2. Include the files that are required to access the aspose slides
51
+ 3. Initialize the libraries. The aspose JAVA classes are loaded from the path provided in the aspose.yml file
52
+ 4. Next we have to start with initializing files that need to be merged. In this example, the dest_ppt, src_ppt1, src_ppt2 needs to be merged.
53
+ 5. The merge_ppts method, takes the dest_ppt and the src_ppts (1 and 2) and merge them together to generate a new ppt file. The src ppts can be provided with various options.
54
+
55
+ ##### Options for merge_ppts
56
+ * dest_ppt : this is the ppt in which you want merge other ppts
57
+ * The second option is an array of src_ppt hashes. The hash is as follows
58
+ ```ruby
59
+ {:ppt => src_ppt1, :position => 2, :replace => true}
60
+ ```
61
+ * :ppt parameter represents the ppt that needs to be merged with dest_ppt.
62
+ * :position parameter represents the index of the dest_ppt at which the slides form src_ppt needs to be inserted
63
+ * :replace parameter (default false) indicates if you want to replace the slide in dest_ppt at the given position or not.
64
+
65
+ ## TODO
66
+ * Make it work with the http urls of ppts
67
+ * Extend the gem for other slide operations like add, delete, reorder etc
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( https://github.com/sanjusoftware/asposeslides/fork )
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asposeslides/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'asposeslides'
8
+ spec.version = Asposeslides::VERSION
9
+ spec.authors = ['Sanjeev Mishra']
10
+ spec.email = ['sanjusoftware@gmail.com']
11
+ spec.summary = %q{A Ruby gem to work with aspose libraries}
12
+ spec.description = %q{asposeslides is a Ruby gem that can help working with aspose libraries}
13
+ spec.homepage = 'https://github.com/sanjusoftware/asposeslides'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+
25
+ spec.add_dependency 'rjb', '1.5.2'
26
+
27
+ end
data/config/aspose.yml ADDED
@@ -0,0 +1 @@
1
+ jar_dir: ../asposeslides/jars
Binary file
@@ -0,0 +1,40 @@
1
+ module Asposeslides
2
+ module Powerpoint
3
+
4
+ def create_ppt(file = nil)
5
+ file ? Rjb::import('com.aspose.slides.Presentation').new(file) : Rjb::import('com.aspose.slides.Presentation').new
6
+ end
7
+
8
+ def get_notes(ppt, index)
9
+ slide = ppt.getSlides().get_Item(index)
10
+ slide.getNotesSlide() ? slide.getNotesSlide().getNotesTextFrame().getText() : ''
11
+ end
12
+
13
+ def merge_ppts(dest_ppt, src_ppt_options)
14
+ destPres = create_ppt(dest_ppt)
15
+ offset_position = 0
16
+
17
+ src_ppt_options.each do |ppt_option|
18
+ src_ppt = ppt_option[:ppt]
19
+ position = ppt_option[:position]
20
+ replace = ppt_option[:replace]
21
+
22
+ srcPres = create_ppt(src_ppt)
23
+ dest_slides = destPres.getSlides()
24
+ src_slides = srcPres.getSlides()
25
+
26
+ if position
27
+ dest_slides.remove(dest_slides.get_Item(position + offset_position)) if replace
28
+ (0..src_slides.toArray().length-1).map{|i| dest_slides.insertClone(position + offset_position + i, src_slides.get_Item(i))}
29
+
30
+ offset_position = offset_position + (replace ? (src_slides.toArray().length - 1) : (src_slides.toArray().length))
31
+
32
+ else
33
+ (0..src_slides.toArray().length-1).map{|i| dest_slides.addClone(src_slides.get_Item(i))}
34
+ end
35
+ end
36
+ destPres
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Asposeslides
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'asposeslides/version'
2
+ require 'asposeslides/powerpoint'
3
+ require 'logger'
4
+ require 'rjb'
5
+
6
+ module Asposeslides
7
+
8
+ class << self
9
+ attr_accessor :aspose_slides_config
10
+ end
11
+
12
+ def initialize_aspose
13
+ dir = Asposeslides.aspose_slides_config ? Asposeslides.aspose_slides_config['jar_dir'] : nil
14
+
15
+ if dir && File.exist?(dir)
16
+ jardir = File.join(dir, '**', '*.jar')
17
+ else
18
+ logger = Logger.new(STDOUT)
19
+ logger.level = Logger::WARN
20
+ logger.warn('Using the non licensed aspose slides jar. Please specify path to your licensed aspose slides jar directory in config/aspose.yml file!')
21
+ jardir = File.join(File.dirname(File.dirname(__FILE__)),'jars', '**', '*.jar')
22
+ end
23
+ Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true'])
24
+ end
25
+
26
+
27
+ def self.configure_aspose_slides config
28
+ Asposeslides.aspose_slides_config = config
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Asposeslides Initialization' do
4
+
5
+ include Asposeslides
6
+
7
+ it 'should initialize aspose and return a valid object' do
8
+ initialize_aspose
9
+ expect(Rjb::import('com.aspose.slides.Presentation').new).not_to be_nil
10
+ end
11
+
12
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'asposeslides/powerpoint'
3
+
4
+ describe 'Asposeslides::Powerpoint' do
5
+
6
+ include Asposeslides
7
+ include Asposeslides::Powerpoint
8
+
9
+ context 'powerpoint' do
10
+
11
+ before do
12
+ initialize_aspose
13
+ end
14
+
15
+ context 'create' do
16
+ it 'should create a new presentation for a given file' do
17
+ file = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
18
+ ppt = create_ppt(file)
19
+ expect(ppt).to_not be_nil
20
+ end
21
+ end
22
+
23
+ context 'notes' do
24
+ it 'should give the notes for a given slide in a ppt' do
25
+ ppt_file = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
26
+ ppt = create_ppt(ppt_file)
27
+ expect(get_notes(ppt, 2)).to eq('NOTE1')
28
+ end
29
+ end
30
+
31
+ context 'merge' do
32
+ it 'should append given source presentation into destination presentation' do
33
+ dest_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
34
+ src_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'src_template1.pptx')
35
+
36
+ ppt1 = create_ppt(dest_ppt)
37
+ ppt2 = create_ppt(src_ppt)
38
+
39
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt}])
40
+ expect(merged_ppt.getSlides().toArray().length).to eq(ppt1.getSlides().toArray().length + ppt2.getSlides().toArray().length)
41
+ end
42
+
43
+ it 'should insert slides from source presentation into destination presentation at a given position' do
44
+ dest_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
45
+ src_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'src_template1.pptx')
46
+
47
+ ppt1 = create_ppt(dest_ppt)
48
+ ppt2 = create_ppt(src_ppt)
49
+
50
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt, :position => 4}])
51
+ expect(merged_ppt.getSlides().toArray().length).to eq(ppt1.getSlides().toArray().length + ppt2.getSlides().toArray().length)
52
+ end
53
+
54
+ it 'should replace a slide at a given position in destination presentation with slides from source presentation' do
55
+ dest_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
56
+ src_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'src_template1.pptx')
57
+
58
+ ppt1 = create_ppt(dest_ppt)
59
+ ppt2 = create_ppt(src_ppt)
60
+
61
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt, :position => 4, :replace => true}])
62
+ expect(merged_ppt.getSlides().toArray().length).to eq((ppt1.getSlides().toArray().length + ppt2.getSlides().toArray().length) - 1)
63
+ end
64
+
65
+ it 'should replace multiple slides at a given positions in destination presentation with slides from multiple source presentations' do
66
+ dest_ppt = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'dest_template.pptx')
67
+ src_ppt1 = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'src_template1.pptx')
68
+ src_ppt2 = File.join(File.dirname(File.dirname(__FILE__)), 'spec', 'data', 'src_template2.pptx')
69
+
70
+ ppt1 = create_ppt(dest_ppt)
71
+ ppt2 = create_ppt(src_ppt1)
72
+ ppt3 = create_ppt(src_ppt2)
73
+
74
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt1, :position => 2, :replace => true}, {:ppt => src_ppt2, :position => 5, :replace => true}])
75
+ expect(merged_ppt.getSlides().toArray().length).to eq((ppt1.getSlides().toArray().length + ppt2.getSlides().toArray().length + ppt3.getSlides().toArray().length) - 2)
76
+
77
+ merged_ppt = merge_ppts(dest_ppt, [{:ppt => src_ppt1, :position => 2}, {:ppt => src_ppt2, :position => 5}])
78
+ expect(merged_ppt.getSlides().toArray().length).to eq((ppt1.getSlides().toArray().length + ppt2.getSlides().toArray().length + ppt3.getSlides().toArray().length))
79
+ end
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'yaml'
4
+
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
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'Asposeslides'
16
+
17
+ Asposeslides.configure_aspose_slides YAML.load(File.read('config/aspose.yml'))
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asposeslides
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sanjeev Mishra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rjb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.2
69
+ description: asposeslides is a Ruby gem that can help working with aspose libraries
70
+ email:
71
+ - sanjusoftware@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - asposeslides.gemspec
82
+ - config/aspose.yml
83
+ - jars/aspose.slides-14.9.0.jar
84
+ - lib/asposeslides.rb
85
+ - lib/asposeslides/powerpoint.rb
86
+ - lib/asposeslides/version.rb
87
+ - spec/asposeslides_spec.rb
88
+ - spec/data/dest_template.pptx
89
+ - spec/data/src_template1.pptx
90
+ - spec/data/src_template2.pptx
91
+ - spec/powerpoint_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/sanjusoftware/asposeslides
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A Ruby gem to work with aspose libraries
117
+ test_files:
118
+ - spec/asposeslides_spec.rb
119
+ - spec/data/dest_template.pptx
120
+ - spec/data/src_template1.pptx
121
+ - spec/data/src_template2.pptx
122
+ - spec/powerpoint_spec.rb
123
+ - spec/spec_helper.rb