Class: Madness::Document

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

Overview

Handle a single document path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ServerHelper

#config, #disallowed_static?, #docroot, #find_static_file, #log, #theme

Constructor Details

#initialize(path) ⇒ Document

Returns a new instance of Document.



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

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.



8
9
10
# File 'lib/madness/document.rb', line 8

def base
  @base
end

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/madness/document.rb', line 8

def dir
  @dir
end

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/madness/document.rb', line 8

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/madness/document.rb', line 8

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/madness/document.rb', line 8

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/madness/document.rb', line 8

def type
  @type
end

Instance Method Details

#contentObject

Return the HTML for that document



18
19
20
# File 'lib/madness/document.rb', line 18

def content
  @content ||= i[empty missing].include?(type) ? "<h1>#{title}</h1>" : markdown.to_html
end

#hrefObject



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

def href
  relative_file.to_href
end

#relative_fileObject



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

def relative_file
  file[%r{^#{docroot}/(.*)}, 1]
end