Class: Powerpoint::Presentation

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/powerpoint/presentation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#copy_media, #merge_variables, #pixle_to_pt, #read_template, #render_view, #require_arguments

Constructor Details

#initializePresentation

Returns a new instance of Presentation.



11
12
13
# File 'lib/powerpoint/presentation.rb', line 11

def initialize
  @slides = []
end

Instance Attribute Details

#slidesObject (readonly)

Returns the value of attribute slides.



9
10
11
# File 'lib/powerpoint/presentation.rb', line 9

def slides
  @slides
end

Instance Method Details

#add_collage_slide(title, subtitle = nil, page_number, logo, task_icon, image_information, images) ⇒ Object



67
68
69
# File 'lib/powerpoint/presentation.rb', line 67

def add_collage_slide(title, subtitle = nil, page_number, , task_icon, image_information ,images)
  @slides << Powerpoint::Slide::Collage.new(presentation: self, title: title, subtitle: subtitle, page_number: page_number, logo: , task_icon: task_icon, image_information: image_information, images: images)
end

#add_comment_slide(title, subtitle = nil, user, page_number, logo, task_icon, comments) ⇒ Object



55
56
57
# File 'lib/powerpoint/presentation.rb', line 55

def add_comment_slide(title, subtitle = nil, user, page_number, , task_icon ,comments)
  @slides << Powerpoint::Slide::Comment.new(presentation: self, title: title, subtitle: subtitle, user: user, page_number: page_number, task_icon: task_icon, logo: , comments: comments)
end

#add_concept_slide(title, subtitle = nil, page_number, logo, task_icon, image_information, images, legend) ⇒ Object



63
64
65
# File 'lib/powerpoint/presentation.rb', line 63

def add_concept_slide(title, subtitle = nil, page_number, , task_icon, image_information ,images, legend)
  @slides << Powerpoint::Slide::Concept.new(presentation: self, title: title, subtitle: subtitle, page_number: page_number, logo: , task_icon: task_icon, image_information: image_information, images: images, legend: legend)
end

#add_custom_slide(title, subtitle = nil, properties) ⇒ Object



71
72
73
# File 'lib/powerpoint/presentation.rb', line 71

def add_custom_slide(title, subtitle = nil, properties)
  @slides << Powerpoint::Slide::Custom.new(presentation: self, title: title, subtitle: subtitle, properties: properties)
end

#add_dashboard_slide(title, subtitle = nil, page_number, graph_1_title, graph_1_subtitle, graph_2_title, image_1, image_2, image_3, image_4, logo, data) ⇒ Object



75
76
77
# File 'lib/powerpoint/presentation.rb', line 75

def add_dashboard_slide(title, subtitle = nil, page_number, graph_1_title, graph_1_subtitle, graph_2_title, image_1, image_2, image_3, image_4, , data)
  @slides << Powerpoint::Slide::Dashboard.new(presentation: self, title: title, subtitle: subtitle, page_number: page_number, graph_1_title: graph_1_title, graph_1_subtitle: graph_1_subtitle, graph_2_title: graph_2_title, image_path: image_1, image_path_2: image_2, image_path_3: image_3, image_path_4: image_4, logo: , data: data)
end

#add_dashboard_user_slide(title, subtitle = nil, page_number, logo, images) ⇒ Object



79
80
81
# File 'lib/powerpoint/presentation.rb', line 79

def add_dashboard_user_slide(title, subtitle = nil, page_number, , images)
  @slides << Powerpoint::Slide::DashboardUser.new(presentation: self, title: title, subtitle: subtitle,page_number: page_number, logo: , images: images)
end

#add_extended_intro(title, image_path, image_path_2, subtitle = nil, subtitle_2 = nil, coords = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/powerpoint/presentation.rb', line 25

def add_extended_intro(title, image_path, image_path_2,subtitle = nil,subtitle_2 = nil, coords = {})
  existing_intro_slide = @slides.select {|s| s.class == Powerpoint::Slide::ExtendedIntro}[0]
  slide = Powerpoint::Slide::ExtendedIntro.new(presentation: self, title: title, subtitle: subtitle, image_path: image_path, image_path_2: image_path_2, subtitle_2: subtitle_2, coords: coords)
  if existing_intro_slide
    @slides[@slides.index(existing_intro_slide)] = slide 
  else
    @slides.insert 0, slide
  end
end


59
60
61
# File 'lib/powerpoint/presentation.rb', line 59

def add_gallery_slide(title, subtitle = nil, question, page_number, , task_icon ,images)
  @slides << Powerpoint::Slide::Gallery.new(presentation: self, title: title, subtitle: subtitle, question: question, page_number: page_number, task_icon: task_icon, logo: , images: images)
end

#add_intro(title, subtitile = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/powerpoint/presentation.rb', line 15

def add_intro(title, subtitile = nil)
  existing_intro_slide = @slides.select {|s| s.class == Powerpoint::Slide::Intro}[0]
  slide = Powerpoint::Slide::Intro.new(presentation: self, title: title, subtitile: subtitile)
  if existing_intro_slide
    @slides[@slides.index(existing_intro_slide)] = slide 
  else
    @slides.insert 0, slide
  end
end

#add_multiple_image_slide(title, subtitle = nil, page_number, logo, task_icon, images) ⇒ Object



51
52
53
# File 'lib/powerpoint/presentation.rb', line 51

def add_multiple_image_slide(title, subtitle = nil, page_number, , task_icon ,images)
  @slides << Powerpoint::Slide::MultipleImage.new(presentation: self, title: title, subtitle: subtitle, page_number: page_number, task_icon: task_icon, logo: , images: images)
end

#add_pictorial_slide(title, image_path, coords = {}) ⇒ Object



39
40
41
# File 'lib/powerpoint/presentation.rb', line 39

def add_pictorial_slide(title, image_path, coords = {})
  @slides << Powerpoint::Slide::Pictorial.new(presentation: self, title: title, image_path: image_path, coords: coords)
end

#add_picture_description_slide(title, image_path, content = []) ⇒ Object



47
48
49
# File 'lib/powerpoint/presentation.rb', line 47

def add_picture_description_slide(title, image_path, content = [])
  @slides << Powerpoint::Slide::DescriptionPic.new(presentation: self, title: title, image_path: image_path, content: content)
end

#add_text_picture_slide(title, image_path, content = []) ⇒ Object



43
44
45
# File 'lib/powerpoint/presentation.rb', line 43

def add_text_picture_slide(title, image_path, content = [])
  @slides << Powerpoint::Slide::TextPicSplit.new(presentation: self, title: title, image_path: image_path, content: content)
end

#add_textual_slide(title, content = []) ⇒ Object



35
36
37
# File 'lib/powerpoint/presentation.rb', line 35

def add_textual_slide(title, content = [])
  @slides << Powerpoint::Slide::Textual.new(presentation: self, title: title, content: content)
end

#file_typesObject



114
115
116
# File 'lib/powerpoint/presentation.rb', line 114

def file_types
  
end

#save(path) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/powerpoint/presentation.rb', line 83

def save(path)
  Dir.mktmpdir do |dir|
    extract_path = "#{dir}/extract_#{Time.now.strftime("%Y-%m-%d-%H%M%S")}"

    # Copy template to temp path
    FileUtils.copy_entry(TEMPLATE_PATH, extract_path)

    # Remove keep files
    Dir.glob("#{extract_path}/**/.keep").each do |keep_file|
      FileUtils.rm_rf(keep_file)
    end

    # Render/save generic stuff
    render_view('content_type.xml.erb', "#{extract_path}/[Content_Types].xml")
    render_view('presentation.xml.rel.erb', "#{extract_path}/ppt/_rels/presentation.xml.rels")
    render_view('presentation.xml.erb', "#{extract_path}/ppt/presentation.xml")
    render_view('app.xml.erb', "#{extract_path}/docProps/app.xml")

    # Save slides
    slides.each_with_index do |slide, index|
      slide.save(extract_path, index + 1)
    end

    # Create .pptx file
    File.delete(path) if File.exist?(path)
    Powerpoint.compress_pptx(extract_path, path)
  end

  path
end