madness 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78a49ca36d07d11662ba98136593790a316586d4f17cff8bd7a3febc02916c01
4
- data.tar.gz: 03adaa519d407baa99337a9eae0beba3edfcb91c22f73fe54049d78d3fd0f103
3
+ metadata.gz: 76896d82203c749d37aa6bb4a321deee5e544f9763ff9ab9544bd28ae90c613d
4
+ data.tar.gz: a1a8c4093bc5dbef67489096658f057860945125c6de6e5376f362287b207be2
5
5
  SHA512:
6
- metadata.gz: 88b64055acfc24a132c11bfcc91e81dcbef93343c3b1c857921fb0257befd21d85c3c9651891c54eabb9bfd558e21e4f299fc706dd4f8655e7b2dc426eb388f7
7
- data.tar.gz: a155163d534295118fc2082a0bce08533bfffe06a45b934ea68b6d7deffb301075b8aff1635bb6d95e841a479eaafa36055c7f6f650a30e153f72792425016d8
6
+ metadata.gz: 7a0e267fcdd6e0568f348e03d2b67b99e3bbc7ca6cbc7eefef3d8f00f1661b5193c281800520fa7b4ad266083eb174dc62d65314d1a6883e91d986e5e6719203
7
+ data.tar.gz: 55db2eb7681263246b3fbae1881c811e62c5d39974439ad7279ecf6ba48c43c6e69d18866c09e9d110aa3e26674ec127e251343f88ccdc8d9da3a5926359b182
data/README.md CHANGED
@@ -78,9 +78,6 @@ Madness expects to be executed in a documentation directory.
78
78
  A documentation directory contains only markdown files (`*.md`) and sub
79
79
  directories that contain more markdown files.
80
80
 
81
- The server will consider the file `index.md` or `README.md` in any directory as
82
- the main file describing this directory, where `index.md` has priority.
83
-
84
81
  The navigation sidebar will show all the sub directories and files in the same
85
82
  directory as the viewed file.
86
83
 
@@ -129,6 +126,11 @@ bind: 0.0.0.0
129
126
  # base_uri: /docs
130
127
  base_uri: ~
131
128
 
129
+ # choose navigation sort order:
130
+ # sort_order: dirs_first # alphabetic directories then alphabetic files
131
+ # sort_order: mixed # alphabetic regardless of type
132
+ sort_order: dirs_first
133
+
132
134
  # enable sidebar
133
135
  sidebar: true
134
136
 
@@ -195,6 +197,23 @@ exclude: ['^[a-z_\-0-9]+$']
195
197
 
196
198
  ## Features
197
199
 
200
+ ### Cover Pages
201
+
202
+ Cover pages are specially named markdown files that serve as the introduction
203
+ to the contents of a specific directory.
204
+
205
+ The server will consider any of the following files as cover pages (prioritized):
206
+
207
+ - A markdown file with the same name as the directory (adjacent to it).
208
+ - `index.md`
209
+ - `README.md`
210
+
211
+ For example, for a directory named "API Documentation":
212
+
213
+ - `/API Documentation.md`
214
+ - `/API Documentation/index.md`
215
+ - `/API Documentation/README.md`
216
+
198
217
  ### Search
199
218
 
200
219
  Madness comes with a full text search page.
@@ -286,6 +305,9 @@ will be omitted when they are displayed.
286
305
  └── 2. Another file or folder
287
306
  ```
288
307
 
308
+ Note that by default, directories will appear above files. If you wish to
309
+ change this, set `sort_order: mixed` in your configuration file.
310
+
289
311
  ### Displaying Additional File Types
290
312
 
291
313
  If you wish the navigation and search features to also show other documents
@@ -3,6 +3,7 @@ module Madness
3
3
  class Directory
4
4
  include ServerHelper
5
5
  using ArrayRefinements
6
+ using StringRefinements
6
7
 
7
8
  attr_reader :dir
8
9
 
@@ -17,17 +18,22 @@ module Madness
17
18
  private
18
19
 
19
20
  def files
20
- result = Dir["#{dir}/#{config.dir_glob}"]
21
- result.reject! do |f|
22
- ['README.md', 'index.md'].include? File.basename(f)
21
+ @files ||= begin
22
+ result = Dir["#{dir}/#{config.dir_glob}"]
23
+ result.reject! do |f|
24
+ ['README.md', 'index.md'].include? File.basename(f)
25
+ end
26
+ result.reject! { |f| is_cover_page? f }
27
+ result.nat_sort.map { |path| Item.new path, :file }
23
28
  end
24
- result.nat_sort.map { |path| Item.new path, :file }
25
29
  end
26
30
 
27
31
  def dirs
28
- result = Dir["#{dir}/*"].select { |f| File.directory? f }
29
- result.reject! { |f| exclude? f }
30
- result.nat_sort.map { |path| Item.new path, :dir }
32
+ @dirs ||= begin
33
+ result = Dir["#{dir}/*"].select { |f| File.directory? f }
34
+ result.reject! { |f| exclude? f }
35
+ result.nat_sort.map { |path| Item.new path, :dir }
36
+ end
31
37
  end
32
38
 
33
39
  def exclude?(path)
@@ -40,6 +46,14 @@ module Madness
40
46
  false
41
47
  end
42
48
 
49
+ def is_cover_page?(path)
50
+ dir_paths.include? path.remove(/\.md$/)
51
+ end
52
+
53
+ def dir_paths
54
+ @dir_paths ||= dirs.map(&:path)
55
+ end
56
+
43
57
  def config
44
58
  @config ||= Settings.instance
45
59
  end
@@ -55,10 +55,8 @@ module Madness
55
55
  @dir = base
56
56
  @type = :readme
57
57
 
58
- if File.exist? "#{base}/index.md"
59
- @file = "#{base}/index.md"
60
- elsif File.exist? "#{base}/README.md"
61
- @file = "#{base}/README.md"
58
+ if cover_page
59
+ @file = cover_page
62
60
  else
63
61
  @type = :empty
64
62
  end
@@ -79,5 +77,25 @@ module Madness
79
77
  def md_filename
80
78
  File.extname(base) == '.md' ? base : "#{base}.md"
81
79
  end
80
+
81
+ def cover_page
82
+ @cover_page ||= cover_page!
83
+ end
84
+
85
+ def cover_page!
86
+ cover_page_candidates.each do |candidate|
87
+ return candidate if File.exist? candidate
88
+ end
89
+
90
+ nil
91
+ end
92
+
93
+ def cover_page_candidates
94
+ @cover_page_candidates ||= [
95
+ File.expand_path("../#{File.basename(base)}.md", base),
96
+ File.expand_path('index.md', base),
97
+ File.expand_path('README.md', base),
98
+ ]
99
+ end
82
100
  end
83
101
  end
@@ -2,6 +2,7 @@ module Madness
2
2
  # Handle the navigation links for a given directory
3
3
  class Navigation
4
4
  include ServerHelper
5
+ using ArrayRefinements
5
6
  using StringRefinements
6
7
 
7
8
  attr_reader :dir
@@ -11,7 +12,11 @@ module Madness
11
12
  end
12
13
 
13
14
  def links
14
- @links ||= directory.list
15
+ @links ||= if config.sort_order == 'mixed'
16
+ directory.list.nat_sort(by: :href)
17
+ else
18
+ directory.list
19
+ end
15
20
  end
16
21
 
17
22
  def caption
@@ -27,5 +32,9 @@ module Madness
27
32
  def directory
28
33
  @directory ||= Directory.new(dir)
29
34
  end
35
+
36
+ def config
37
+ Settings.instance
38
+ end
30
39
  end
31
40
  end
@@ -3,8 +3,8 @@ require 'naturally'
3
3
  module Madness
4
4
  module ArrayRefinements
5
5
  refine Array do
6
- def nat_sort
7
- Naturally.sort self
6
+ def nat_sort(by: nil)
7
+ Naturally.sort self, by: by
8
8
  end
9
9
  end
10
10
  end
@@ -16,7 +16,7 @@ module Madness
16
16
  set :static, false
17
17
 
18
18
  # Since we cannot use any config values in the main body of the class,
19
- # since they will be updated later, we need to set anything that relys
19
+ # since they will be updated later, we need to set anything that relies
20
20
  # on the config values just before running the server.
21
21
  # The CommandLine class and the test suite should both call
22
22
  # `Server.prepare` before calling Server.run!
@@ -15,7 +15,7 @@ module Madness
15
15
  reset
16
16
  end
17
17
 
18
- def method_missing(name, *args, &_blk)
18
+ def method_missing(name, *args, &_block)
19
19
  name_string = name.to_s
20
20
 
21
21
  if name_string.end_with? '='
@@ -57,6 +57,7 @@ module Madness
57
57
  port: 3000,
58
58
  bind: '0.0.0.0',
59
59
  base_uri: nil,
60
+ sort_order: 'dirs_first',
60
61
  sidebar: true,
61
62
  auto_h1: true,
62
63
  auto_nav: true,
@@ -15,6 +15,11 @@ bind: 0.0.0.0
15
15
  # base_uri: /docs
16
16
  base_uri: ~
17
17
 
18
+ # choose navigation sort order:
19
+ # sort_order: dirs_first # alphabetic directories then alphabetic files
20
+ # sort_order: mixed # alphabetic regardless of type
21
+ sort_order: dirs_first
22
+
18
23
  # enable sidebar
19
24
  sidebar: true
20
25
 
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
data/lib/madness.rb CHANGED
@@ -1,11 +1,8 @@
1
- if ENV['BYEBUG']
2
- require 'byebug'
3
- require 'lp'
4
- end
5
-
6
1
  require 'requires'
7
2
 
8
3
  requires 'madness/refinements'
9
4
  requires 'madness/settings'
10
5
  requires 'madness/server_helper'
11
6
  requires 'madness'
7
+
8
+ require 'debug' rescue nil if ENV['DEBUGGER']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-09 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -28,22 +28,16 @@ dependencies:
28
28
  name: colsole
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.1
34
- - - "<"
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
- version: '2'
33
+ version: '1.0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.8.1
44
- - - "<"
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '2'
40
+ version: '1.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: extended_yaml
49
43
  requirement: !ruby/object:Gem::Requirement