Class: Monograph::Book

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Book

Returns a new instance of Book.



6
7
8
# File 'lib/monograph/book.rb', line 6

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/monograph/book.rb', line 4

def path
  @path
end

Instance Method Details

#builtin_templateObject



26
27
28
# File 'lib/monograph/book.rb', line 26

def builtin_template
  config['template'] || 'default'
end

#builtin_template_pathObject



30
31
32
# File 'lib/monograph/book.rb', line 30

def builtin_template_path
  File.join(Monograph.root, 'templates', builtin_template)
end

#chaptersObject



22
23
24
# File 'lib/monograph/book.rb', line 22

def chapters
  @chapters ||= Dir[File.join(@path, '*.md')].map { |path| Monograph::Chapter.new(self, path) }
end

#configObject



18
19
20
# File 'lib/monograph/book.rb', line 18

def config
  @config ||= YAML.load(File.read(config_path))
end

#config_pathObject



10
11
12
# File 'lib/monograph/book.rb', line 10

def config_path
  File.join(@path, 'config.yml')
end

#exportObject



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

def export
  @export ||= Export.new(self)
end

#templateObject



43
44
45
# File 'lib/monograph/book.rb', line 43

def template
  @template ||= template_file('template.html')
end

#template_file(name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/monograph/book.rb', line 34

def template_file(name)
  template_path = File.join(@path, name)
  if File.exist?(template_path)
    File.read(template_path)
  else
    File.read(File.join(builtin_template_path, name))
  end
end

#titleObject



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

def title
  config['title']
end