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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61800bba372a7802c94d6e1b03ae7ae976a272bd46e70bcd6ee4c6840c0f99b9
4
- data.tar.gz: 80b9b50292629189fb9592eff557a63aa23cf856541a174782dffc253f0c1adf
3
+ metadata.gz: f7c16859452e4652252758d4ead7dbb37eace8c0997cc4723891a937c200408f
4
+ data.tar.gz: 203352bfdaf474d2c4fcf2cd7b220deffe326ecb0185e8e46a5f0912d888351a
5
5
  SHA512:
6
- metadata.gz: 7e25d76930f8ebad4bb54edeb033b0cd8fc1cd90c8455ebfbc534cd09df211c4f49b4ce616930ba2ca30dc9f7f8685f1bf12a1d541e43779071390f8fa1b0e50
7
- data.tar.gz: fa5f24750e105497e026c1afe6d5ac0a5815e0db7aaf3c5aec97afbc6ac07044f6249e329b169292828543dfabe128ecb13a1862a63f6bb1a0b1a66461ff45b3
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 as the
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.
@@ -17,7 +17,10 @@ module Madness
17
17
 
18
18
  def files
19
19
  result = Dir["#{dir}/*.md"]
20
- result.reject! { |f| File.basename(f) == 'README.md' }
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
 
@@ -5,32 +5,30 @@ module Madness
5
5
  include ServerHelper
6
6
  using StringRefinements
7
7
 
8
- attr_reader :file, :dir, :path, :type
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
- base = path.empty? ? docroot : "#{docroot}/#{path}"
19
- base.chomp! '/'
16
+ # Return :readme, :file or :empty
17
+ def type
18
+ set_base_attributes unless @type
19
+ @type
20
+ end
20
21
 
21
- if File.directory? base
22
- @file = "#{base}/README.md"
23
- @dir = base
24
- @type = :readme
25
- elsif File.exist? "#{base}.md"
26
- @file = "#{base}.md"
27
- @dir = File.dirname file
28
- @type = :file
29
- else
30
- @file = ''
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
- if File.exist?(file)
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
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit