Class: Madness::Document
- Inherits:
-
Object
- Object
- Madness::Document
- Includes:
- ServerHelper
- Defined in:
- lib/madness/document.rb
Overview
Handle a single markdown document.
Instance Attribute Summary collapse
-
#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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#content ⇒ Object
Return the HTML for that document.
-
#content! ⇒ Object
Return the HTML for that document, force re-read.
-
#initialize(path) ⇒ Document
constructor
At initialization, we handle three file “types”: :readme - in case the path is a directory, then the only file we MAY show, is the README.md in it :file - in case the path is a *.md file :empty - in any other case, we don’t know.
-
#title ⇒ Object
Return a reasonable HTML title for the file or directory.
Methods included from ServerHelper
Constructor Details
#initialize(path) ⇒ Document
At initialization, we handle three file “types”: :readme - in case the path is a directory, then the only file we
MAY show, is the README.md in it
:file - in case the path is a *.md file :empty - in any other case, we don’t know.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/madness/document.rb', line 14 def initialize(path) @path = path base = path.empty? ? docroot : "#{docroot}/#{path}" if File.directory? base @file = "#{base}/README.md" @dir = base @type = :readme elsif File.exist? "#{base}.md" @file = "#{base}.md" @dir = File.dirname file @type = :file else @file = '' @dir = docroot @type = :empty end end |
Instance Attribute Details
#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 |
#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
35 36 37 |
# File 'lib/madness/document.rb', line 35 def content @content ||= content! end |
#content! ⇒ Object
Return the HTML for that document, force re-read.
40 41 42 43 44 45 46 47 |
# File 'lib/madness/document.rb', line 40 def content! if File.exist?(file) markdown_to_html else @type = :empty "" end end |
#title ⇒ Object
Return a reasonable HTML title for the file or directory
50 51 52 53 54 55 56 57 |
# File 'lib/madness/document.rb', line 50 def title if file =~ /README.md/ result = File.basename File.dirname(file) else result = File.basename(file,'.md') end result.tr '-', ' ' end |