Class: Powerdown
- Inherits:
-
Object
- Object
- Powerdown
- Defined in:
- lib/powerdown.rb,
lib/powerdown/usage.rb,
lib/powerdown/parser.rb,
lib/powerdown/version.rb,
lib/powerdown/generator.rb
Constant Summary collapse
- USAGE =
%{ == Usage powerdown file.pd }
- SLIDE_TYPE_INTRO =
1
- SLIDE_TYPE_ITEMS =
2
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw) ⇒ Powerdown
constructor
A new instance of Powerdown.
- #make(pptx_path) ⇒ Object
- #parse_slides ⇒ Object
Constructor Details
#initialize(raw) ⇒ Powerdown
Returns a new instance of Powerdown.
6 7 8 9 |
# File 'lib/powerdown/parser.rb', line 6 def initialize raw @raw = raw =~ /\A!DOWN/ ? raw : "!DOWN\n#{raw}" end |
Class Method Details
.make(source_path) ⇒ Object
22 23 24 25 |
# 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 |
.run!(argv = ARGV) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#make(pptx_path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/powerdown/generator.rb', line 5 def make pptx_path @deck = Powerpoint::Presentation.new @slides.each do || case [:type] when SLIDE_TYPE_INTRO @deck.add_intro [:title], [:subtitle] when SLIDE_TYPE_ITEMS @deck. [:title], [:items] end end @deck.save pptx_path end |
#parse_slides ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/powerdown/parser.rb', line 11 def @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 |