lib/powerpoint/slide/textual.rb in powerpoint-1.5 vs lib/powerpoint/slide/textual.rb in powerpoint-1.6

- old
+ new

@@ -1,26 +1,32 @@ -require 'zip/filesystem' require 'fileutils' +require 'erb' module Powerpoint module Slide - class Powerpoint::Slide::Textual - def initialize extract_path, title, content, slide_number - template_path = "#{TEMPLATE_PATH}/ppt/slides/slide2.xml" - xml = File.read template_path + class Textual + include Powerpoint::Util + + attr_reader :title, :content - title_xml = '<a:p><a:r><a:rPr lang="en-US" dirty="0" smtClean="0"/><a:t>'+ title.to_s + '</a:t></a:r><a:endParaRPr lang="en-US" dirty="0"/></a:p>' - xml.gsub!('SLIDE_TITLE_PACEHOLDER', title_xml) + def initialize(options={}) + require_arguments [:title, :content], options + options.each {|k, v| instance_variable_set("@#{k}", v)} + end - content_xml = '' - content.each do |i| - content_xml += '<a:p><a:r><a:rPr lang="en-US" dirty="0" smtClean="0"/><a:t>' + i.to_s + '</a:t></a:r></a:p>' - end + def save(index) + save_rel_xml(index) + save_slide_xml(index) + end - xml.gsub!('CONTENT_PACEHOLDER', content_xml) + private - slide_path = "#{extract_path}/ppt/slides/slide#{slide_number}.xml" - File.open(slide_path, 'w'){ |f| f << xml } + def save_rel_xml index + File.open("#{extract_path}/ppt/slides/_rels/slide#{index}.xml.rels", 'w'){ |f| f << render_view('textual_rel.xml.erb') } + end + + def save_slide_xml index + File.open("#{extract_path}/ppt/slides/slide#{index}.xml", 'w'){ |f| f << render_view('textual_slide.xml.erb') } end end end end \ No newline at end of file