Class: Monograph::Book
- Inherits:
-
Object
- Object
- Monograph::Book
- Defined in:
- lib/monograph/book.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #builtin_template ⇒ Object
- #builtin_template_path ⇒ Object
- #chapters ⇒ Object
- #config ⇒ Object
- #config_path ⇒ Object
- #export ⇒ Object
-
#initialize(path) ⇒ Book
constructor
A new instance of Book.
- #template ⇒ Object
- #template_file(name) ⇒ Object
- #title ⇒ Object
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
#path ⇒ Object (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_template ⇒ Object
26 27 28 |
# File 'lib/monograph/book.rb', line 26 def builtin_template config['template'] || 'default' end |
#builtin_template_path ⇒ Object
30 31 32 |
# File 'lib/monograph/book.rb', line 30 def builtin_template_path File.join(Monograph.root, 'templates', builtin_template) end |
#chapters ⇒ Object
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 |
#config ⇒ Object
18 19 20 |
# File 'lib/monograph/book.rb', line 18 def config @config ||= YAML.load(File.read(config_path)) end |
#config_path ⇒ Object
10 11 12 |
# File 'lib/monograph/book.rb', line 10 def config_path File.join(@path, 'config.yml') end |
#export ⇒ Object
47 48 49 |
# File 'lib/monograph/book.rb', line 47 def export @export ||= Export.new(self) end |
#template ⇒ Object
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 |
#title ⇒ Object
14 15 16 |
# File 'lib/monograph/book.rb', line 14 def title config['title'] end |