Class: Madness::Document

Inherits:
Object
  • Object
show all
Includes:
ServerHelper
Defined in:
lib/madness/document.rb

Overview

Handle a single markdown document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ServerHelper

#config, #docroot, #log

Constructor Details

#initialize(path) ⇒ Document

Returns a new instance of Document.



13
14
15
16
17
# File 'lib/madness/document.rb', line 13

def initialize(path)
  @path = path
  @base = path.empty? ? docroot : "#{docroot}/#{path}"
  @base.chomp! '/'
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



11
12
13
# File 'lib/madness/document.rb', line 11

def base
  @base
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/madness/document.rb', line 11

def path
  @path
end

Instance Method Details

#contentObject

Return the HTML for that document



44
45
46
# File 'lib/madness/document.rb', line 44

def content
  @content ||= content!
end

#content!Object

Return the HTML for that document, force re-read.



49
50
51
# File 'lib/madness/document.rb', line 49

def content!
  [:empty, :missing].include?(type) ? "<h1>#{title}</h1>" : markdown_to_html
end

#dirObject

Return the path to the document directory



32
33
34
35
# File 'lib/madness/document.rb', line 32

def dir
  set_base_attributes unless @dir
  @dir
end

#fileObject

Return the path to the actual markdown file



26
27
28
29
# File 'lib/madness/document.rb', line 26

def file
  set_base_attributes unless @file
  @file
end

#titleObject

Return the path to the document directory



38
39
40
41
# File 'lib/madness/document.rb', line 38

def title
  set_base_attributes unless @title
  @title
end

#typeObject

Return :readme, :file or :empty



20
21
22
23
# File 'lib/madness/document.rb', line 20

def type
  set_base_attributes unless @type
  @type
end