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.



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

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.



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

def base
  @base
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#contentObject

Return the HTML for that document



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

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

#hrefObject



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

def href
  relative_file.to_href
end

#relative_fileObject



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

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