class Powerdown

Constants

SLIDE_TYPE_INTRO
SLIDE_TYPE_ITEMS
USAGE
VERSION

Public Class Methods

make(source_path) click to toggle source
# File lib/powerdown.rb, line 22
def self.make source_path
  powerdown = new File.read(source_path)
  powerdown.make source_path.sub(/.pd$/, '') + '.pptx'
end
new(raw) click to toggle source
# File lib/powerdown/parser.rb, line 6
def initialize raw
  @raw = raw =~ /\A!DOWN/ ? raw : "!DOWN\n#{raw}"
  parse_slides
end
run!(argv = ARGV) click to toggle source
# File lib/powerdown.rb, line 11
def self.run! argv = ARGV
  args = argv.dup

  if args.empty?
    puts USAGE
  else
    source = args[0]
    make source
  end
end

Public Instance Methods

make(pptx_path) click to toggle source
# File lib/powerdown/generator.rb, line 5
def make pptx_path
  @deck = Powerpoint::Presentation.new
  @slides.each do |slide|
    case slide[:type]
    when SLIDE_TYPE_INTRO
      @deck.add_intro slide[:title], slide[:subtitle]
    when SLIDE_TYPE_ITEMS
      @deck.add_textual_slide slide[:title], slide[:items]
    end
  end
  @deck.save pptx_path
end
parse_slides() click to toggle source
# File lib/powerdown/parser.rb, line 11
def parse_slides
  @slides = @raw.split(/^!DOWN\s*([a-z\s]*)$/).reject(&:empty?).each_with_index.map do |lines, i|
    lines = lines.split("\n").reject(&:empty?)
    if ( i == 0 ) && ( lines.count <= 2 )
      {
        type: SLIDE_TYPE_INTRO,
        title: lines[0],
        subtitle: lines[1] || ''
      }
    else
      {
        type: SLIDE_TYPE_ITEMS,
        title: lines[0],
        items: lines.slice(1, lines.count - 1).map do |item|
          item.sub(/^\s*-\s*/, '').strip
        end
      }
    end
  end
end