Class: Kitabu::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/kitabu/generator.rb

Overview

The Kitabu::Generator class will create a new book structure.

ebook = Kitabu::Generator.new
ebook.destination_root = "/some/path/book-name"
ebook.invoke_all

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



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

def self.source_root
  "#{File.dirname(__FILE__)}/../../templates"
end

Instance Method Details

#bundle_installObject



63
64
65
66
67
# File 'lib/kitabu/generator.rb', line 63

def bundle_install
  inside destination_root do
    run "bundle install"
  end
end

#copy_config_fileObject



31
32
33
34
35
36
# File 'lib/kitabu/generator.rb', line 31

def copy_config_file
  @name = full_name
  @uid = Digest::MD5.hexdigest("#{Time.now}--#{rand}")
  @year = Date.today.year
  template "config.erb", "config/kitabu.yml"
end

#copy_gemfileObject



42
43
44
# File 'lib/kitabu/generator.rb', line 42

def copy_gemfile
  copy_file "Gemfile"
end

#copy_guardfileObject



59
60
61
# File 'lib/kitabu/generator.rb', line 59

def copy_guardfile
  copy_file "Guardfile"
end

#copy_helper_fileObject



38
39
40
# File 'lib/kitabu/generator.rb', line 38

def copy_helper_file
  copy_file "helper.rb", "config/helper.rb"
end

#copy_imagesObject



27
28
29
# File 'lib/kitabu/generator.rb', line 27

def copy_images
  directory "images", "images"
end

#copy_sample_textsObject



23
24
25
# File 'lib/kitabu/generator.rb', line 23

def copy_sample_texts
  directory "text", "text"
end

#copy_templatesObject



19
20
21
# File 'lib/kitabu/generator.rb', line 19

def copy_templates
  directory "templates", "templates"
end

#create_directoriesObject



46
47
48
49
# File 'lib/kitabu/generator.rb', line 46

def create_directories
  empty_directory "output"
  empty_directory "fonts"
end

#create_git_filesObject



51
52
53
54
55
56
57
# File 'lib/kitabu/generator.rb', line 51

def create_git_files
  create_file ".gitignore" do
    "/output"
  end

  create_file "fonts/.keep"
end