rubypoint 0.0.1
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.
- data/GPL-LICENSE +674 -0
- data/README.textile +21 -0
- data/Rakefile +96 -0
- data/lib/rubypoint.rb +107 -0
- data/lib/rubypoint/content_types_xml.rb +48 -0
- data/lib/rubypoint/core.rb +13 -0
- data/lib/rubypoint/docProps/app.rb +47 -0
- data/lib/rubypoint/element.rb +33 -0
- data/lib/rubypoint/file.rb +20 -0
- data/lib/rubypoint/ppt/presentation.rb +42 -0
- data/lib/rubypoint/ppt/rels/presentation_rel.rb +73 -0
- data/lib/rubypoint/presentation.rb +89 -0
- data/lib/rubypoint/relationship.rb +25 -0
- data/lib/rubypoint/slide/rel.rb +16 -0
- data/lib/rubypoint/slide/slide.rb +34 -0
- data/lib/rubypoint/textfield.rb +19 -0
- metadata +89 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'zipruby'
|
2
|
+
|
3
|
+
class RubyPoint
|
4
|
+
class Presentation
|
5
|
+
|
6
|
+
attr_accessor :files, :slides
|
7
|
+
|
8
|
+
def initialize(file_path)
|
9
|
+
@working_directory = RubyPoint.working_directory
|
10
|
+
@uuid = Time.now.to_i
|
11
|
+
@files = []
|
12
|
+
self.open(file_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def open(path)
|
16
|
+
system("mkdir #{file_directory}")
|
17
|
+
system("cp #{path} #{@working_directory}#{@uuid}/#{path}")
|
18
|
+
system("unzip -q #{@working_directory}#{@uuid}/#{path} -d #{@working_directory}#{@uuid}/")
|
19
|
+
system("rm #{@working_directory}#{@uuid}/#{path}")
|
20
|
+
@files = Dir.glob("#{@working_directory}#{@uuid}/**/*", ::File::FNM_DOTMATCH)
|
21
|
+
end
|
22
|
+
|
23
|
+
def save(file_path, force=false)
|
24
|
+
slides.each do |s|
|
25
|
+
s.write
|
26
|
+
end
|
27
|
+
presentation_rel.write
|
28
|
+
presentation_xml.write
|
29
|
+
app_xml.write
|
30
|
+
content_types_xml.write
|
31
|
+
if ::File.exist?(file_path)
|
32
|
+
force ? system("rm -f #{file_path}") : raise("#{file_path} already exists")
|
33
|
+
end
|
34
|
+
RubyPoint.compress_folder(file_directory, file_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def clean_file_directory
|
38
|
+
system("rm -r #{file_directory}")
|
39
|
+
end
|
40
|
+
|
41
|
+
### PRESENTATION PARTS
|
42
|
+
|
43
|
+
def slides
|
44
|
+
return @slides if @slides
|
45
|
+
@slides = []
|
46
|
+
slide_files = Dir.glob("#{file_directory}/ppt/slides/*.xml")
|
47
|
+
slide_files.each do |f|
|
48
|
+
@slides << RubyPoint::Slide.new(self, f)
|
49
|
+
end
|
50
|
+
@slides
|
51
|
+
end
|
52
|
+
|
53
|
+
def presentation_rel
|
54
|
+
@presentation_rel ||= RubyPoint::PresentationRel.new(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def presentation_xml
|
58
|
+
@presentation_xml ||= RubyPoint::Presentation::Presentation.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def app_xml
|
62
|
+
@app_xml ||= RubyPoint::App.new(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def content_types_xml
|
66
|
+
@content_types_xml ||= RubyPoint::ContentTypes::XML.new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def new_slide
|
70
|
+
RubyPoint::Slide.new(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def next_slide_id
|
74
|
+
self.slides.size + 1
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_to_relationships(object)
|
78
|
+
self.presentation_rel.add_relationship_for(object)
|
79
|
+
end
|
80
|
+
|
81
|
+
def slide_directory
|
82
|
+
file_directory + '/ppt/slides'
|
83
|
+
end
|
84
|
+
|
85
|
+
def file_directory
|
86
|
+
"#{@working_directory}#{@uuid}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class RubyPoint::Relationship < RubyPoint::Element
|
2
|
+
|
3
|
+
attr_accessor :rel_id, :object
|
4
|
+
class_attributes :target, :type
|
5
|
+
|
6
|
+
def initialize(parent, object=false)
|
7
|
+
@parent = parent
|
8
|
+
@rel_id = parent.next_rel_id
|
9
|
+
if object
|
10
|
+
@object = object
|
11
|
+
@object.rel_id = @rel_id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def write
|
16
|
+
@parent.doc.search('//Relationships').append(self.raw)
|
17
|
+
end
|
18
|
+
|
19
|
+
def raw
|
20
|
+
raw = <<EOF
|
21
|
+
<Relationship Id="rId#{self.rel_id}" Type="#{self.type}" Target="#{self.target}"/>
|
22
|
+
EOF
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RubyPoint::Slide::Rel < RubyPoint::File
|
2
|
+
|
3
|
+
def initialize(slide)
|
4
|
+
@parent = slide
|
5
|
+
@presenation = slide.presentation
|
6
|
+
@file_path = @presenation.slide_directory + "/_rels/slide#{@parent.slide_id}.xml.rels"
|
7
|
+
@doc = Hpricot::XML(self.raw_xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def raw_xml
|
11
|
+
raw = <<EOF
|
12
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
13
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout2.xml"/></Relationships>
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class RubyPoint::Slide < RubyPoint::File
|
2
|
+
|
3
|
+
attr_accessor :slide_id, :rel_id
|
4
|
+
|
5
|
+
def initialize(presentation, file=nil)
|
6
|
+
@presentation = presentation
|
7
|
+
file ? init_from_file(file) : init_from_new
|
8
|
+
end
|
9
|
+
|
10
|
+
def raw_xml
|
11
|
+
raw = <<EOF
|
12
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
13
|
+
<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" mc:Ignorable="mv" mc:PreserveAttributes="mv:*" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="#{self.slide_id}" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def init_from_file(file)
|
20
|
+
@file_path = file
|
21
|
+
@slide_id = presentation.next_slide_id
|
22
|
+
@rel_id = presentation.add_to_relationships(self)
|
23
|
+
@doc = Hpricot::XML(File.open(@file_path).read)
|
24
|
+
end
|
25
|
+
|
26
|
+
def init_from_new
|
27
|
+
@slide_id = presentation.next_slide_id
|
28
|
+
@file_path = presentation.slide_directory + "/slide#{@slide_id}.xml"
|
29
|
+
@rel_id = presentation.add_to_relationships(self)
|
30
|
+
self.objects << RubyPoint::Slide::Rel.new(self)
|
31
|
+
presentation.slides << self
|
32
|
+
@doc = Hpricot::XML(self.raw_xml)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RubyPoint::TextField < RubyPoint::Element
|
2
|
+
attr_accessor :text, :x, :y, :width, :height
|
3
|
+
|
4
|
+
def initialize(text="",x=3200400, y=4572000, w=3200400, h=572000)
|
5
|
+
@dirty = true
|
6
|
+
@text = text
|
7
|
+
@x, @y, @width, @height = x, y, w, h
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
@parent.doc.search('//p:spTree').append(self.raw)
|
12
|
+
end
|
13
|
+
|
14
|
+
def raw
|
15
|
+
raw = <<EOF
|
16
|
+
<p:sp><p:nvSpPr><p:cNvPr id="#{self.object_id}" name="TextBox #{self.object_id}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm><a:off x="#{self.x}" y="#{self.y}"/><a:ext cx="#{self.width}" cy="#{self.height}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/></p:spPr><p:txBody><a:bodyPr wrap="square" rtlCol="0"><a:spAutoFit/></a:bodyPr><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" dirty="0" smtClean="0"/><a:t>#{self.text}</a:t></a:r></a:p></p:txBody></p:sp>
|
17
|
+
EOF
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubypoint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Pozdena
|
8
|
+
autorequire: rubypoint
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-17 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: zipruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.3.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hpricot
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
version:
|
35
|
+
description: Make pptx files with Ruby.
|
36
|
+
email: jpoz@jpoz.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- GPL-LICENSE
|
43
|
+
files:
|
44
|
+
- GPL-LICENSE
|
45
|
+
- README.textile
|
46
|
+
- Rakefile
|
47
|
+
- lib/rubypoint/content_types_xml.rb
|
48
|
+
- lib/rubypoint/core.rb
|
49
|
+
- lib/rubypoint/docProps/app.rb
|
50
|
+
- lib/rubypoint/element.rb
|
51
|
+
- lib/rubypoint/file.rb
|
52
|
+
- lib/rubypoint/ppt/presentation.rb
|
53
|
+
- lib/rubypoint/ppt/rels/presentation_rel.rb
|
54
|
+
- lib/rubypoint/presentation.rb
|
55
|
+
- lib/rubypoint/relationship.rb
|
56
|
+
- lib/rubypoint/slide/rel.rb
|
57
|
+
- lib/rubypoint/slide/slide.rb
|
58
|
+
- lib/rubypoint/textfield.rb
|
59
|
+
- lib/rubypoint.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/jpoz/rubypoint
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Make pptx files with Ruby.
|
88
|
+
test_files: []
|
89
|
+
|