Class: Techbook::Builder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, html, epub, mobi, docbook, output) ⇒ Builder

Returns a new instance of Builder.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/techbook/builder.rb', line 32

def initialize(pdf, html, epub, mobi, docbook, output)
  @pdf = pdf
  @html = html
  @epub = epub
  @mobi = mobi
  @docbook = docbook
  @output = output

  @basename = File.basename @output
  @book = File.join @output, "#{@basename}.asc"
  @path = File.join @output, "build"
end

Instance Attribute Details

#basenameObject

Returns the value of attribute basename.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def basename
  @basename
end

#docbookObject

Returns the value of attribute docbook.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def docbook
  @docbook
end

#epubObject

Returns the value of attribute epub.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def epub
  @epub
end

#fileObject

Returns the value of attribute file.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def file
  @file
end

#htmlObject

Returns the value of attribute html.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def html
  @html
end

#mobiObject

Returns the value of attribute mobi.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def mobi
  @mobi
end

#outputObject

Returns the value of attribute output.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def output
  @output
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def path
  @path
end

#pdfObject

Returns the value of attribute pdf.



12
13
14
# File 'lib/techbook/builder.rb', line 12

def pdf
  @pdf
end

Class Method Details

.run(pdf:, html:, epub:, mobi:, docbook:, output:, watch:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/techbook/builder.rb', line 14

def self.run(pdf:, html:, epub:, mobi:, docbook:, output:, watch:)
  b = new pdf, html, epub, mobi, docbook, output
  b.build

  if watch
    Signal.trap("SIGINT") do
      puts "Bye :)".green
      exit
    end

    puts "Watching changes for #{output}".green

    listener = Listen.to(File.join(output, "book")) { b.build }
    listener.start
    sleep
  end
end

Instance Method Details

#buildObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/techbook/builder.rb', line 45

def build
  puts "Building book...".yellow

  prepare
  generate_includes

  build_pdf
  build_html
  build_docbook
  build_epub
  build_mobi

  dist
  clean
end