Class: Zlide::Deck

Inherits:
Object
  • Object
show all
Defined in:
lib/zlide/deck.rb

Instance Method Summary collapse

Constructor Details

#initializeDeck

Returns a new instance of Deck.



8
9
10
11
12
13
14
15
16
17
# File 'lib/zlide/deck.rb', line 8

def initialize
  files = Dir.glob('slides/*.md')
  @slides = Array.new
  files.sort.each do |f|
    slides = File.read(f).split(/(^!SLIDE.*$)/)[1..-1].each_slice(2).map(&:join)
    slides.each do |slide|
      @slides << {:file => f, :content => slide}
    end
  end
end

Instance Method Details

#slide(index) ⇒ Object



19
20
21
# File 'lib/zlide/deck.rb', line 19

def slide(index)
  @slides[index][:content]
end

#to_htmlObject



31
32
33
34
35
36
# File 'lib/zlide/deck.rb', line 31

def to_html
  slides = markdown_parser(Zlide::Redcarpet::Renderers::HTML).render(full_markdown)
  layout = File.read(File.join(File.dirname(__FILE__), "layouts", "deckjs.haml"))
  layout_renderer = Haml::Engine.new(layout)
  layout_renderer.render { slides }
end

#to_pdfObject



38
39
40
41
42
# File 'lib/zlide/deck.rb', line 38

def to_pdf
  pdf = Zlide::Redcarpet::Renderers::PDF.new
  markdown_parser(pdf).render(full_markdown)
  pdf.write_file
end

#update_slide(index, content) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/zlide/deck.rb', line 23

def update_slide(index, content)
  @slides[index][:content] = content
  file = @slides[index][:file]
  file_slides = @slides.select{|s| s[:file] == file}.map{|s| s[:content]}
  File.open("#{file}.tmp", "w") {|f| f.write(file_slides.join)}
  File.rename("#{file}.tmp", file)
end