Class: Madness::Document
- Inherits:
-
Object
- Object
- Madness::Document
- Includes:
- ServerHelper
- Defined in:
- lib/madness/document.rb
Overview
Handle a single document path.
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#content ⇒ Object
Return the HTML for that document.
- #href ⇒ Object
-
#initialize(path) ⇒ Document
constructor
A new instance of Document.
- #relative_file ⇒ Object
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def base @base end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def dir @dir end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def file @file end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/madness/document.rb', line 7 def type @type end |
Instance Method Details
#content ⇒ Object
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 |
#href ⇒ Object
25 26 27 |
# File 'lib/madness/document.rb', line 25 def href relative_file.to_href end |
#relative_file ⇒ Object
21 22 23 |
# File 'lib/madness/document.rb', line 21 def relative_file file[%r{^#{docroot}/(.*)}, 1] end |