Module: Powerpoint::Util
- Included in:
- Presentation, Slide::Collage, Slide::Comment, Slide::Concept, Slide::Custom, Slide::Dashboard, Slide::DashboardUser, Slide::DescriptionPic, Slide::ExtendedIntro, Slide::Gallery, Slide::Intro, Slide::MultipleImage, Slide::Pictorial, Slide::TextPicSplit, Slide::Textual
- Defined in:
- lib/powerpoint/util.rb
Instance Method Summary collapse
- #copy_media(extract_path, image_path) ⇒ Object
- #merge_variables(b, variables) ⇒ Object
- #pixle_to_pt(px) ⇒ Object
- #read_template(filename) ⇒ Object
- #render_view(template_name, path, variables = {}) ⇒ Object
- #require_arguments(required_arguements, arguements) ⇒ Object
Instance Method Details
#copy_media(extract_path, image_path) ⇒ Object
25 26 27 28 29 |
# File 'lib/powerpoint/util.rb', line 25 def copy_media(extract_path, image_path) image_name = File.basename(image_path) dest_path = "#{extract_path}/ppt/media/#{image_name}" FileUtils.copy_file(image_path, dest_path) unless File.exist?(dest_path) end |
#merge_variables(b, variables) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/powerpoint/util.rb', line 31 def merge_variables(b, variables) return b if variables.empty? variables.each do |k,v| b.local_variable_set(k, v) end b end |
#pixle_to_pt(px) ⇒ Object
4 5 6 |
# File 'lib/powerpoint/util.rb', line 4 def pixle_to_pt(px) px * 12700 end |
#read_template(filename) ⇒ Object
17 18 19 |
# File 'lib/powerpoint/util.rb', line 17 def read_template(filename) File.read("#{Powerpoint::VIEW_PATH}/#{filename}") end |
#render_view(template_name, path, variables = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/powerpoint/util.rb', line 8 def render_view(template_name, path, variables = {}) view_contents = read_template(template_name) renderer = ERB.new(view_contents) b = merge_variables(binding, variables) data = renderer.result(b) File.open(path, 'w') { |f| f << data.squish!.gsub('> <', '><') } end |
#require_arguments(required_arguements, arguements) ⇒ Object
21 22 23 |
# File 'lib/powerpoint/util.rb', line 21 def require_arguments(required_arguements, arguements) raise ArgumentError unless required_arguements.all? {|required_key| arguements.keys.include? required_key} end |