module Eggplant class Slides def initialize path, options={} @slides = [] @title = nil Dir[path+'/**/*.md'].each do |file| if !(file =~ /README.md$/) process file, File.read(file) end end end def size @slides.size end def to_html @slides.map do |slide| render_slide slide[:body], slide[:options] end.join "\n" end private def process filename, content # if there are no !SLIDE markers, then make the file define one slide unless content =~ /^!SLIDE/m content = "!SLIDE\n" + content end title = filename.split('/').pop.gsub(/\.md$/, '') slides = content.split(/^!SLIDE/) slides.delete('') seq = 1 if slides.size > 1 slides.each do |slide| slide, options = parse_options(title, slide.split("\n")) @slides << {:body => slide, :options => options} end end def render_slide body, options body = Eggplant::Markdown.new(body).to_html <<-HTML
#{body}
HTML end def parse_options title, lines options = lines.shift.strip.scan(/[a-z]*="[^"]*"/i) rescue [] options_hash = {} options.each do |option| key, value = option.split('=') options_hash[key.to_sym] = value.gsub('"', '') end options_hash[:title] ||= title options_hash[:class] ||= '' return lines.join("\n"), options_hash end end end