powerpoint 1.6 → 1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/powerpoint.rb +3 -27
- data/lib/powerpoint/compression.rb +25 -0
- data/lib/powerpoint/presentation.rb +27 -25
- data/lib/powerpoint/slide/intro.rb +10 -10
- data/lib/powerpoint/slide/pictorial.rb +17 -14
- data/lib/powerpoint/slide/textual.rb +10 -10
- data/lib/powerpoint/util.rb +7 -9
- data/lib/powerpoint/version.rb +1 -1
- data/samples/pptx/sample.pptx +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTIyN2VhNDU0N2I4MTFkZTQxNTBmNzhiZTQ5OTYxMzA1NWFmOTgxNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGNjNGJmODJlNzI2YTFiYzEyMzVlZGYxZTJhMDVmMTAyY2M5NWY0MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWYxMmE0ODg5Y2E1ZWU3MjZiYzhjYzkyYmUxOTlhNGRiZmU1NWM5M2JhZmI1
|
10
|
+
YzUxZjBmZDE0YTVhYTMxNjE1OGZlNjg0OGQ1ODhjZTlmM2EzMDk3N2U3MTYz
|
11
|
+
NGY2OGE0ZjRiMjYwNzI1N2EyNzI4NDNkNzA5NTliYjg1MThhYTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWJkZDI5OTdiYzc5YTBmYmQ4ZTM3NjhiZmJjODk2ODUxNzMwY2E5YTg5YmZi
|
14
|
+
MzlkMjY4ZWZlMmIzNDk0MTAzYTZiYWU1NTUyZmI4YzA4NjViNGMwMWU0MzYw
|
15
|
+
OGNkOThjNmY5OGJhNGUzODRjOTQ0OWVkZjY5ODI4ZDJmMmVmYjE=
|
data/lib/powerpoint.rb
CHANGED
@@ -3,35 +3,11 @@ require 'powerpoint/util'
|
|
3
3
|
require 'powerpoint/slide/intro'
|
4
4
|
require 'powerpoint/slide/textual'
|
5
5
|
require 'powerpoint/slide/pictorial'
|
6
|
+
require 'powerpoint/compression'
|
6
7
|
require 'powerpoint/presentation'
|
7
8
|
|
8
9
|
module Powerpoint
|
9
|
-
|
10
|
-
spec = Gem::Specification.find_by_name("powerpoint")
|
11
|
-
ROOT_PATH = spec.gem_dir
|
10
|
+
ROOT_PATH = File.expand_path("../..", __FILE__)
|
12
11
|
TEMPLATE_PATH = "#{ROOT_PATH}/template/"
|
13
|
-
|
14
|
-
def self.decompress_pptx in_path, out_path
|
15
|
-
Zip::File.open(in_path) do |zip_file|
|
16
|
-
zip_file.each do |f|
|
17
|
-
f_path = File.join(out_path, f.name)
|
18
|
-
FileUtils.mkdir_p(File.dirname(f_path))
|
19
|
-
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.compress_pptx in_path, out_path
|
25
|
-
Zip::File.open(out_path, Zip::File::CREATE) do |zip_file|
|
26
|
-
Dir.glob("#{in_path}/**/*", ::File::FNM_DOTMATCH).each do |path|
|
27
|
-
zip_path = path.gsub("#{in_path}/","")
|
28
|
-
next if zip_path == "." || zip_path == ".." || zip_path.match(/DS_Store/)
|
29
|
-
begin
|
30
|
-
zip_file.add(zip_path, path)
|
31
|
-
rescue Zip::ZipEntryExistsError
|
32
|
-
raise "#{out_path} allready exists!"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
12
|
+
VIEW_PATH = "#{ROOT_PATH}/lib/powerpoint/views/"
|
37
13
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Powerpoint
|
2
|
+
def self.decompress_pptx(in_path, out_path)
|
3
|
+
Zip::File.open(in_path) do |zip_file|
|
4
|
+
zip_file.each do |f|
|
5
|
+
f_path = File.join(out_path, f.name)
|
6
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
7
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.compress_pptx(in_path, out_path)
|
13
|
+
Zip::File.open(out_path, Zip::File::CREATE) do |zip_file|
|
14
|
+
Dir.glob("#{in_path}/**/*", ::File::FNM_DOTMATCH).each do |path|
|
15
|
+
zip_path = path.gsub("#{in_path}/","")
|
16
|
+
next if zip_path == "." || zip_path == ".." || zip_path.match(/DS_Store/)
|
17
|
+
begin
|
18
|
+
zip_file.add(zip_path, path)
|
19
|
+
rescue Zip::ZipEntryExistsError
|
20
|
+
raise "#{out_path} already exists!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -6,13 +6,13 @@ module Powerpoint
|
|
6
6
|
class Presentation
|
7
7
|
include Powerpoint::Util
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :slides
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@slides = []
|
13
13
|
end
|
14
14
|
|
15
|
-
def add_intro
|
15
|
+
def add_intro(title, subtitile = nil)
|
16
16
|
existing_intro_slide = @slides.select {|s| s.class == Powerpoint::Slide::Intro}[0]
|
17
17
|
slide = Powerpoint::Slide::Intro.new(presentation: self, title: title, subtitile: subtitile)
|
18
18
|
if existing_intro_slide
|
@@ -22,39 +22,41 @@ module Powerpoint
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def add_textual_slide
|
25
|
+
def add_textual_slide(title, content = [])
|
26
26
|
@slides << Powerpoint::Slide::Textual.new(presentation: self, title: title, content: content)
|
27
27
|
end
|
28
28
|
|
29
|
-
def add_pictorial_slide
|
29
|
+
def add_pictorial_slide(title, image_path, coords = {})
|
30
30
|
@slides << Powerpoint::Slide::Pictorial.new(presentation: self, title: title, image_path: image_path, coords: coords)
|
31
31
|
end
|
32
32
|
|
33
|
-
def save
|
34
|
-
|
35
|
-
|
36
|
-
FileUtils.copy_entry TEMPLATE_PATH, @extract_path
|
33
|
+
def save(path)
|
34
|
+
Dir.mktmpdir do |dir|
|
35
|
+
extract_path = "#{dir}/extract_#{Time.now.strftime("%Y-%m-%d-%H%M%S")}"
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
FileUtils.rm_rf("#{@extract_path}/ppt/media/.keep")
|
41
|
-
FileUtils.rm_rf("#{@extract_path}/ppt/slides/_rels/.keep")
|
37
|
+
# Copy template to temp path
|
38
|
+
FileUtils.copy_entry(TEMPLATE_PATH, extract_path)
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# Remove keep files
|
41
|
+
Dir.glob("#{extract_path}/**/.keep").each do |keep_file|
|
42
|
+
FileUtils.rm_rf(keep_file)
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
# Render/save generic stuff
|
46
|
+
render_view('content_type.xml.erb', "#{extract_path}/[Content_Types].xml")
|
47
|
+
render_view('presentation.xml.rel.erb', "#{extract_path}/ppt/_rels/presentation.xml.rels")
|
48
|
+
render_view('presentation.xml.erb', "#{extract_path}/ppt/presentation.xml")
|
49
|
+
|
50
|
+
# Save slides
|
51
|
+
slides.each_with_index do |slide, index|
|
52
|
+
slide.save(extract_path, index + 1)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create .pptx file
|
56
|
+
File.delete(path) if File.exist?(path)
|
57
|
+
Powerpoint.compress_pptx(extract_path, path)
|
51
58
|
end
|
52
59
|
|
53
|
-
# Create .pptx file
|
54
|
-
@pptx_path = path
|
55
|
-
File.delete(path) if File.exist?(path)
|
56
|
-
Powerpoint.compress_pptx @extract_path, @pptx_path
|
57
|
-
FileUtils.rm_rf(@extract_path)
|
58
60
|
path
|
59
61
|
end
|
60
62
|
|
@@ -62,4 +64,4 @@ module Powerpoint
|
|
62
64
|
slides.select {|slide| slide.class == Powerpoint::Slide::Pictorial}.map(&:file_type).uniq
|
63
65
|
end
|
64
66
|
end
|
65
|
-
end
|
67
|
+
end
|
@@ -13,20 +13,20 @@ module Powerpoint
|
|
13
13
|
options.each {|k, v| instance_variable_set("@#{k}", v)}
|
14
14
|
end
|
15
15
|
|
16
|
-
def save(index)
|
17
|
-
save_rel_xml(index)
|
18
|
-
save_slide_xml(index)
|
16
|
+
def save(extract_path, index)
|
17
|
+
save_rel_xml(extract_path, index)
|
18
|
+
save_slide_xml(extract_path, index)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
def save_rel_xml index
|
24
|
-
File.open("#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels", 'w'){ |f| f << render_view('textual_rel.xml.erb') }
|
21
|
+
def save_rel_xml(extract_path, index)
|
22
|
+
render_view('textual_rel.xml.erb', "#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels")
|
25
23
|
end
|
24
|
+
private :save_rel_xml
|
26
25
|
|
27
|
-
def save_slide_xml index
|
28
|
-
|
26
|
+
def save_slide_xml(extract_path, index)
|
27
|
+
render_view('intro_slide.xml.erb', "#{extract_path}/ppt/slides/slide#{index}.xml")
|
29
28
|
end
|
29
|
+
private :save_slide_xml
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
@@ -17,20 +17,20 @@ module Powerpoint
|
|
17
17
|
@image_name = File.basename(@image_path)
|
18
18
|
end
|
19
19
|
|
20
|
-
def save(index)
|
21
|
-
|
22
|
-
save_rel_xml(index)
|
23
|
-
save_slide_xml(index)
|
20
|
+
def save(extract_path, index)
|
21
|
+
copy_media(extract_path)
|
22
|
+
save_rel_xml(extract_path, index)
|
23
|
+
save_slide_xml(extract_path, index)
|
24
24
|
end
|
25
25
|
|
26
26
|
def file_type
|
27
27
|
File.extname(image_name).gsub('.', '')
|
28
28
|
end
|
29
29
|
|
30
|
-
private
|
31
|
-
|
32
30
|
def default_coords
|
33
|
-
slide_width = pixle_to_pt(720)
|
31
|
+
slide_width = pixle_to_pt(720)
|
32
|
+
default_width = pixle_to_pt(550)
|
33
|
+
|
34
34
|
return {} unless dimensions = FastImage.size(image_path)
|
35
35
|
image_width, image_height = dimensions.map {|d| pixle_to_pt(d)}
|
36
36
|
new_width = default_width < image_width ? default_width : image_width
|
@@ -38,19 +38,22 @@ module Powerpoint
|
|
38
38
|
new_height = (image_height.to_f * ratio).round
|
39
39
|
{x: (slide_width / 2) - (new_width/2), y: pixle_to_pt(120), cx: new_width, cy: new_height}
|
40
40
|
end
|
41
|
+
private :default_coords
|
41
42
|
|
42
|
-
def
|
43
|
+
def copy_media(extract_path)
|
43
44
|
FileUtils.copy_file(@image_path, "#{extract_path}/ppt/media/#{@image_name}")
|
44
45
|
end
|
46
|
+
private :copy_media
|
45
47
|
|
46
|
-
def save_rel_xml index
|
47
|
-
|
48
|
+
def save_rel_xml(extract_path, index)
|
49
|
+
render_view('pictorial_rel.xml.erb', "#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels")
|
48
50
|
end
|
51
|
+
private :save_rel_xml
|
49
52
|
|
50
|
-
def save_slide_xml index
|
51
|
-
|
53
|
+
def save_slide_xml(extract_path, index)
|
54
|
+
render_view('pictorial_slide.xml.erb', "#{extract_path}/ppt/slides/slide#{index}.xml")
|
52
55
|
end
|
53
|
-
|
56
|
+
private :save_slide_xml
|
54
57
|
end
|
55
58
|
end
|
56
|
-
end
|
59
|
+
end
|
@@ -13,20 +13,20 @@ module Powerpoint
|
|
13
13
|
options.each {|k, v| instance_variable_set("@#{k}", v)}
|
14
14
|
end
|
15
15
|
|
16
|
-
def save(index)
|
17
|
-
save_rel_xml(index)
|
18
|
-
save_slide_xml(index)
|
16
|
+
def save(extract_path, index)
|
17
|
+
save_rel_xml(extract_path, index)
|
18
|
+
save_slide_xml(extract_path, index)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
def save_rel_xml index
|
24
|
-
File.open("#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels", 'w'){ |f| f << render_view('textual_rel.xml.erb') }
|
21
|
+
def save_rel_xml(extract_path, index)
|
22
|
+
render_view('textual_rel.xml.erb', "#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels")
|
25
23
|
end
|
24
|
+
private :save_rel_xml
|
26
25
|
|
27
|
-
def save_slide_xml index
|
28
|
-
|
26
|
+
def save_slide_xml(extract_path, index)
|
27
|
+
render_view('textual_slide.xml.erb', "#{extract_path}/ppt/slides/slide#{index}.xml")
|
29
28
|
end
|
29
|
+
private :save_slide_xml
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/lib/powerpoint/util.rb
CHANGED
@@ -5,22 +5,20 @@ module Powerpoint
|
|
5
5
|
px * 12700
|
6
6
|
end
|
7
7
|
|
8
|
-
def render_view(
|
9
|
-
view_contents = read_template(
|
8
|
+
def render_view(template_name, path)
|
9
|
+
view_contents = read_template(template_name)
|
10
10
|
renderer = ERB.new(view_contents)
|
11
|
-
renderer.result(
|
11
|
+
data = renderer.result(binding)
|
12
|
+
|
13
|
+
File.open(path, 'w') { |f| f << data }
|
12
14
|
end
|
13
15
|
|
14
16
|
def read_template(filename)
|
15
|
-
File.read(Powerpoint::
|
17
|
+
File.read("#{Powerpoint::VIEW_PATH}/#{filename}")
|
16
18
|
end
|
17
19
|
|
18
20
|
def require_arguments(required_argements, argements)
|
19
21
|
raise ArgumentError unless required_argements.all? {|required_key| argements.keys.include? required_key}
|
20
22
|
end
|
21
|
-
|
22
|
-
def extract_path
|
23
|
-
@presentation.extract_path
|
24
|
-
end
|
25
23
|
end
|
26
|
-
end
|
24
|
+
end
|
data/lib/powerpoint/version.rb
CHANGED
data/samples/pptx/sample.pptx
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: powerpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pythonicrubyist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- README.rdoc
|
109
109
|
- Rakefile
|
110
110
|
- lib/powerpoint.rb
|
111
|
+
- lib/powerpoint/compression.rb
|
111
112
|
- lib/powerpoint/presentation.rb
|
112
113
|
- lib/powerpoint/slide/intro.rb
|
113
114
|
- lib/powerpoint/slide/pictorial.rb
|