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
18
# File 'lib/madness/document.rb', line 13

def initialize(path)
  @path = path
  @base = path.empty? ? docroot : "#{docroot}/#{path}"
  @base.chomp! '/'
  set_base_attributes
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

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#contentObject

Return the HTML for that document



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

def content
  @content ||= content!
end

#content!Object

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



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

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