madness 1.1.2 → 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: 374e643da9e1c6fe4f6f0166bddd4f590b974e83bd0e8771ce6825171ed5c90b
4
- data.tar.gz: 5c37a04d04cc735c5b67ced49505193e75d735312fd91e7a31e6064e92f72f48
3
+ metadata.gz: 76896d82203c749d37aa6bb4a321deee5e544f9763ff9ab9544bd28ae90c613d
4
+ data.tar.gz: a1a8c4093bc5dbef67489096658f057860945125c6de6e5376f362287b207be2
5
5
  SHA512:
6
- metadata.gz: 553ec42ee241e5272e789e3dcd18be0e896c52c97419d28b7c419a769cb7c4934cbc426ded181f550473acb4b84f459ab80235046424ab9f834b7da4d6b37290
7
- data.tar.gz: 197c7d750d44ef8e9bdefca0842cc63d30a43fae815a8f56ac53fbcb89fbb8f9f178a1b4cf4173fabee0883e625ee5002d5bd27d1138c1b24ff7451a2d621062
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
@@ -384,14 +406,26 @@ $ alias madness='docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/madness
384
406
  $ madness --help
385
407
  ```
386
408
 
409
+ or use docker compose:
410
+
411
+ ```yaml
412
+ # docker-compose.yml
413
+ services:
414
+ web:
415
+ image: dannyben/madness
416
+ volumes: [".:/docs"]
417
+ ports: ["3000:3000"]
418
+ command: server
419
+ ```
420
+
387
421
  For more information about the docker image, see:
388
422
 
389
423
  - [Madness image on Docker Hub][dockerhub]
390
- - [Madness Dockerfile and Docker Compose][dockerfile]
424
+ - [Madness Dockerfile][dockerfile]
391
425
 
392
426
 
393
427
  [dockerhub]: https://hub.docker.com/r/dannyben/madness/
394
- [dockerfile]: https://github.com/DannyBen/docker-madness
428
+ [dockerfile]: https://github.com/DannyBen/madness/blob/master/Dockerfile
395
429
  [css]: https://github.com/DannyBen/madness/blob/master/app/public/css/main.css
396
430
  [sasstool]: https://github.com/DannyBen/sasstool
397
431
 
@@ -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.2'
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.2
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-19 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
@@ -120,6 +114,20 @@ dependencies:
120
114
  - - "<"
121
115
  - !ruby/object:Gem::Version
122
116
  version: '7'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rackup
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.1'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '2.1'
123
131
  - !ruby/object:Gem::Dependency
124
132
  name: redcarpet
125
133
  requirement: !ruby/object:Gem::Requirement
@@ -166,16 +174,22 @@ dependencies:
166
174
  name: sinatra
167
175
  requirement: !ruby/object:Gem::Requirement
168
176
  requirements:
169
- - - "~>"
177
+ - - ">="
170
178
  - !ruby/object:Gem::Version
171
179
  version: '3.0'
180
+ - - "<"
181
+ - !ruby/object:Gem::Version
182
+ version: '5'
172
183
  type: :runtime
173
184
  prerelease: false
174
185
  version_requirements: !ruby/object:Gem::Requirement
175
186
  requirements:
176
- - - "~>"
187
+ - - ">="
177
188
  - !ruby/object:Gem::Version
178
189
  version: '3.0'
190
+ - - "<"
191
+ - !ruby/object:Gem::Version
192
+ version: '5'
179
193
  - !ruby/object:Gem::Dependency
180
194
  name: slim
181
195
  requirement: !ruby/object:Gem::Requirement
@@ -280,7 +294,7 @@ metadata:
280
294
  homepage_uri: https://madness.dannyb.co/
281
295
  source_code_uri: https://github.com/DannyBen/madness
282
296
  rubygems_mfa_required: 'true'
283
- post_install_message:
297
+ post_install_message:
284
298
  rdoc_options: []
285
299
  require_paths:
286
300
  - lib
@@ -295,8 +309,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
309
  - !ruby/object:Gem::Version
296
310
  version: '0'
297
311
  requirements: []
298
- rubygems_version: 3.4.12
299
- signing_key:
312
+ rubygems_version: 3.5.6
313
+ signing_key:
300
314
  specification_version: 4
301
315
  summary: Instant Markdown Server
302
316
  test_files: []