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.



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

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.



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

def keynote_content
  @keynote_content
end

#snippetsObject

Returns the value of attribute snippets.



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

def snippets
  @snippets
end

#work_dirObject

Returns the value of attribute work_dir.



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

def work_dir
  @work_dir
end

Instance Method Details

#gunzip(filename) ⇒ Object



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

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

#pressObject



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

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

#rebindObject



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

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

#unbindObject



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

def unbind
  FileUtils.mkdir_p @work_dir
  Dir[File.join(@textbook, "slides/*.key")].each do |preso|
    copy_to_working_dir(preso)
    
    gunzip(File.join(@work_dir, File.basename(preso), "index.apxl.gz"))

    content_file = File.join(@work_dir, File.basename(preso), "index.apxl")
    @keynote_content = IO.read(content_file)
  end
end