madness 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/madness/directory.rb +4 -1
- data/lib/madness/document.rb +52 -27
- data/lib/madness/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7c16859452e4652252758d4ead7dbb37eace8c0997cc4723891a937c200408f
|
|
4
|
+
data.tar.gz: 203352bfdaf474d2c4fcf2cd7b220deffe326ecb0185e8e46a5f0912d888351a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3de2ec54e53a84022d9f8131b27c15b7a09985793e21ea30d861354814a0071721aa3a0f3101bb752df9889931f8ecc3b595c1c889a05bd828de3add6b9ca453
|
|
7
|
+
data.tar.gz: a3768d1826817338345e537f4e76c34cc3098d71a96ef86833d06c5a481a9a7ab53088cd438ae425332782053f801ebecacc639595db278b2cd2c0e2097bdad4
|
data/README.md
CHANGED
|
@@ -84,8 +84,8 @@ Madness expects to be executed in a documentation directory.
|
|
|
84
84
|
A documentation directory contains only markdown files (`*.md`) and
|
|
85
85
|
sub directories that contain more markdown files.
|
|
86
86
|
|
|
87
|
-
The server will consider the file `README.md` in any directory
|
|
88
|
-
main file describing this directory.
|
|
87
|
+
The server will consider the file `index.md` or `README.md` in any directory
|
|
88
|
+
as the main file describing this directory, where `index.md` has priority.
|
|
89
89
|
|
|
90
90
|
The navigation sidebar will show all the sub directories and files in
|
|
91
91
|
the same directory as the viewed file.
|
data/lib/madness/directory.rb
CHANGED
|
@@ -17,7 +17,10 @@ module Madness
|
|
|
17
17
|
|
|
18
18
|
def files
|
|
19
19
|
result = Dir["#{dir}/*.md"]
|
|
20
|
-
result.reject!
|
|
20
|
+
result.reject! do |f|
|
|
21
|
+
basename = File.basename(f)
|
|
22
|
+
basename == 'README.md' or basename == 'index.md'
|
|
23
|
+
end
|
|
21
24
|
result.sort.map { |path| Item.new path, :file }
|
|
22
25
|
end
|
|
23
26
|
|
data/lib/madness/document.rb
CHANGED
|
@@ -5,32 +5,30 @@ module Madness
|
|
|
5
5
|
include ServerHelper
|
|
6
6
|
using StringRefinements
|
|
7
7
|
|
|
8
|
-
attr_reader :
|
|
8
|
+
attr_reader :base, :path
|
|
9
9
|
|
|
10
|
-
# At initialization, we handle three file "types":
|
|
11
|
-
# :readme - in case the path is a directory, then the only file we
|
|
12
|
-
# MAY show, is the README.md in it
|
|
13
|
-
# :file - in case the path is a *.md file
|
|
14
|
-
# :empty - in any other case, we don't know.
|
|
15
10
|
def initialize(path)
|
|
16
11
|
@path = path
|
|
12
|
+
@base = path.empty? ? docroot : "#{docroot}/#{path}"
|
|
13
|
+
@base.chomp! '/'
|
|
14
|
+
end
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
# Return :readme, :file or :empty
|
|
17
|
+
def type
|
|
18
|
+
set_base_attributes unless @type
|
|
19
|
+
@type
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@dir = docroot
|
|
32
|
-
@type = :empty
|
|
33
|
-
end
|
|
22
|
+
# Return the path to the actual markdown file
|
|
23
|
+
def file
|
|
24
|
+
set_base_attributes unless @file
|
|
25
|
+
@file
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Return the path to the document directory
|
|
29
|
+
def dir
|
|
30
|
+
set_base_attributes unless @dir
|
|
31
|
+
@dir
|
|
34
32
|
end
|
|
35
33
|
|
|
36
34
|
# Return the HTML for that document
|
|
@@ -40,12 +38,7 @@ module Madness
|
|
|
40
38
|
|
|
41
39
|
# Return the HTML for that document, force re-read.
|
|
42
40
|
def content!
|
|
43
|
-
|
|
44
|
-
markdown_to_html
|
|
45
|
-
else
|
|
46
|
-
@type = :empty
|
|
47
|
-
""
|
|
48
|
-
end
|
|
41
|
+
type == :empty ? '' : markdown_to_html
|
|
49
42
|
end
|
|
50
43
|
|
|
51
44
|
# Return a reasonable HTML title for the file or directory
|
|
@@ -60,6 +53,38 @@ module Madness
|
|
|
60
53
|
|
|
61
54
|
private
|
|
62
55
|
|
|
56
|
+
# Identify file, dir and type.
|
|
57
|
+
# :readme - in case the path is a directory, and it contains index.md
|
|
58
|
+
# or README.md
|
|
59
|
+
# :file - in case the path is a *.md file
|
|
60
|
+
# :empty - in any other case, we don't know.
|
|
61
|
+
def set_base_attributes
|
|
62
|
+
@dir = docroot
|
|
63
|
+
@type = :empty
|
|
64
|
+
@file = ''
|
|
65
|
+
|
|
66
|
+
if File.directory? base
|
|
67
|
+
set_base_attributes_for_directory
|
|
68
|
+
elsif File.exist? "#{base}.md"
|
|
69
|
+
@file = "#{base}.md"
|
|
70
|
+
@dir = File.dirname file
|
|
71
|
+
@type = :file
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def set_base_attributes_for_directory
|
|
76
|
+
@dir = base
|
|
77
|
+
@type = :readme
|
|
78
|
+
|
|
79
|
+
if File.exist? "#{base}/index.md"
|
|
80
|
+
@file = "#{base}/index.md"
|
|
81
|
+
elsif File.exist? "#{base}/README.md"
|
|
82
|
+
@file = "#{base}/README.md"
|
|
83
|
+
else
|
|
84
|
+
@type = :empty
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
63
88
|
def markdown
|
|
64
89
|
@markdown ||= File.read file
|
|
65
90
|
end
|
data/lib/madness/version.rb
CHANGED