Class: TxtBook::KeynoteBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book_dir) ⇒ KeynoteBuilder

Returns a new instance of KeynoteBuilder.



16
17
18
19
# File 'lib/txtbook.rb', line 16

def initialize(book_dir)
  @textbook = File.expand_path(book_dir)
  @work_dir = File.join(@textbook, "work")
end

Instance Attribute Details

#keynote_contentObject

Returns the value of attribute keynote_content.



14
15
16
# File 'lib/txtbook.rb', line 14

def keynote_content
  @keynote_content
end

#snippetsObject

Returns the value of attribute snippets.



14
15
16
# File 'lib/txtbook.rb', line 14

def snippets
  @snippets
end

#work_dirObject

Returns the value of attribute work_dir.



14
15
16
# File 'lib/txtbook.rb', line 14

def work_dir
  @work_dir
end

Instance Method Details

#gunzip(filename) ⇒ Object



47
48
49
# File 'lib/txtbook.rb', line 47

def gunzip(filename)
  Kernel.system("gunzip --force #{filename}")
end

#pressObject



33
34
35
36
37
# File 'lib/txtbook.rb', line 33

def press
  @keynote_content.scan(/\$\{(.+?)\}/).each do |template|
    @keynote_content.gsub!("${#{template}}", IO.read("snippets/#{template}"))
  end
end

#rebindObject



39
40
41
42
43
44
45
# File 'lib/txtbook.rb', line 39

def rebind
  Dir[File.join(@work_dir, "*.key")].each do |prez|
    File.open(File.join(@work_dir, prez, "index.apxl"), "w+") do |file|
      file.write @keynote_content
    end
  end
end

#unbindObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/txtbook.rb', line 21

def unbind
  FileUtils.mkdir_p @work_dir
  Dir[File.join(@textbook, "slides/*.key")].each do |prez|
    FileUtils.cp_r(prez, @work_dir)
    
    # DEBT Untested
    gunzip(File.join(@work_dir, File.basename(prez), "index.apxl.gz"))
    
    @keynote_content = IO.read(File.join(@work_dir, File.basename(prez), "index.apxl"))
  end
end