madness 0.5.1 → 0.5.2

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: 4548ff821bb0396f536bc5d7228a03bc44307c9eb60b1282c74aee8519f1dd86
4
- data.tar.gz: d438320e3e8a819aa6e90dac8d9a77140444270fceccedf6f5a199c53d685d45
3
+ metadata.gz: 05747c9d79187c38d51b832818d55b3d5ac3f752a9fe607b122deb3696cbd602
4
+ data.tar.gz: 77a756be50f65a205d65d497415dfca806ff86388f11bfe51adcf31c5e5f0f7d
5
5
  SHA512:
6
- metadata.gz: 05caa89aa6745f72cc6552ae8b4376db76bace2561196c220fa94958c327a1b9ade31686f0ad38a8c847a13a80a08ab173de2edfddbd689db4848e49060578f5
7
- data.tar.gz: 4f8937f11e93d872d1d1a3c1cc5015e5bb326a84d6a34a086fa9fe077db7aa09dbfdba170dcac1f6e0120aef26acbaf71230e32199d05d074ceaa8d4e1db9990
6
+ metadata.gz: b680d72a2ddc93f673f5d87057303872a1f6d6317af03888e684e7b925818b304bdf6695d1862aad2cc10665845ae60d6e901739ac5203a0370fe3e76872849f
7
+ data.tar.gz: e5f2c52f519da17724114a6521ffdff3922688e470029fbab57c87f25b8541aa718e6410c86ce28780bf661b4fce3a3264de95ece283e223547cb5bcfb112b22
data/README.md CHANGED
@@ -16,6 +16,25 @@ Screenshot
16
16
 
17
17
 
18
18
 
19
+ Table of Contents
20
+ --------------------------------------------------
21
+
22
+ * [Install](#install)
23
+ * [Design Intentions](#design-intentions)
24
+ * [Feature Highlights](#feature-highlights)
25
+ * [Usage](#usage)
26
+ * [Directory Conventions](#directory-conventions)
27
+ * [Configuration File](#configuration-file)
28
+ * [Search](#search)
29
+ * [Images and Static Files](#images-and-static-files)
30
+ * [Automatic H1](#automatic-h1)
31
+ * [Table of Contents Generation](#table-of-contents-generation)
32
+ * [Hidden Directories](#hidden-directories)
33
+ * [Changing Theme](#changing-theme)
34
+ * [Docker Image](#docker-image)
35
+
36
+
37
+
19
38
  Install
20
39
  --------------------------------------------------
21
40
 
@@ -38,6 +57,7 @@ Feature Highlights
38
57
  - Built in full text search
39
58
  - Compatible with how markdown files are displayed on GitHub andGitHub pages.
40
59
  - Configure with a configuration file or command arguments
60
+ - Automatic generation of Table of Contents
41
61
 
42
62
 
43
63
 
@@ -103,6 +123,7 @@ autoh1: true
103
123
  highlighter: true
104
124
  line_numbers: true
105
125
  index: false
126
+ toc: Table of Contents
106
127
  ```
107
128
 
108
129
 
@@ -156,14 +177,19 @@ will be automatically added based on the file name.
156
177
 
157
178
 
158
179
 
159
- Hidden Directories
180
+ Table of Contents Generation
160
181
  --------------------------------------------------
161
182
 
162
- These directories will not be displayed in the navigation:
183
+ You can use the `madness --toc` command to generate a "Table of Contents"
184
+ markdown file.
185
+
186
+
187
+
188
+ Hidden Directories
189
+ --------------------------------------------------
163
190
 
164
- - Directories that begin with an underscore.
165
- - Directories that are made only of lowercase letters, underscoew, dash and/or
166
- numbers (`/^[a-z_\-0-9]+$/`).
191
+ Diretories that are made only of lowercase letters, underscoes, dash and/or
192
+ numbers (`/^[a-z_\-0-9]+$/`) will not be displayed in the navigation.
167
193
 
168
194
 
169
195
 
data/lib/madness.rb CHANGED
@@ -15,15 +15,19 @@ require 'ferret'
15
15
 
16
16
  require'byebug' if ENV['BYEBUG']
17
17
 
18
- require 'madness/version'
19
- require 'madness/try_static'
20
- require 'madness/settings'
21
18
  require 'madness/server_helper'
22
- require 'madness/server_base'
23
- require 'madness/server'
24
- require 'madness/document'
25
- require 'madness/navigation'
19
+
26
20
  require 'madness/breadcrumbs'
27
21
  require 'madness/command_line'
22
+ require 'madness/directory'
23
+ require 'madness/document'
24
+ require 'madness/item'
25
+ require 'madness/navigation'
28
26
  require 'madness/search'
27
+ require 'madness/server'
28
+ require 'madness/server_base'
29
+ require 'madness/settings'
30
+ require 'madness/table_of_contents'
31
+ require 'madness/try_static'
32
+ require 'madness/version'
29
33
 
@@ -19,8 +19,7 @@ module Madness
19
19
  begin
20
20
  args = Docopt.docopt(doc, argv: argv, version: VERSION)
21
21
  set_config args
22
-
23
- build_index if config.index
22
+ generate_stuff
24
23
  launch_server unless args['--and-quit']
25
24
 
26
25
  rescue Docopt::Exit => e
@@ -48,12 +47,19 @@ module Madness
48
47
  config.path = args['PATH'] if args['PATH']
49
48
  config.port = args['--port'] if args['--port']
50
49
  config.bind = args['--bind'] if args['--bind']
50
+ config.toc = args['--toc'] if args['--toc']
51
51
  config.autoh1 = false if args['--no-auto-h1']
52
52
  config.highlighter = false if args['--no-syntax']
53
53
  config.line_numbers = false if args['--no-line-numbers']
54
54
  config.index = true if args['--index']
55
55
  end
56
56
 
57
+ # Generate index and toc, if requested by the user.
58
+ def generate_stuff
59
+ build_index if config.index
60
+ build_toc if config.toc
61
+ end
62
+
57
63
  # Say hello to everybody when the server starts, showing the known
58
64
  # config.
59
65
  def show_status
@@ -65,10 +71,15 @@ module Madness
65
71
  say "-" * 40
66
72
  end
67
73
 
74
+ # Build the search index
68
75
  def build_index
69
- say_status :start, 'indexing'
76
+ say_status :index, "generating"
70
77
  Search.new.build_index
71
- say_status :done, 'indexing'
78
+ end
79
+
80
+ def build_toc
81
+ say_status :toc, "generating #{config.toc}"
82
+ TableOfContents.new.build(config.toc)
72
83
  end
73
84
 
74
85
  def config
@@ -0,0 +1,33 @@
1
+ module Madness
2
+ # Represents a directory with markdown file sand subflders.
3
+ class Directory
4
+ include ServerHelper
5
+
6
+ attr_reader :dir
7
+
8
+ def initialize(dir)
9
+ @dir = dir
10
+ end
11
+
12
+ def list
13
+ @list ||= (dirs + files)
14
+ end
15
+
16
+ private
17
+
18
+ def files
19
+ result = Dir["#{dir}/*.md"]
20
+ result.reject! { |f| File.basename(f) == 'README.md' }
21
+ result.sort.map { |path| Item.new path, :file }
22
+ end
23
+
24
+ def dirs
25
+ result = Dir["#{dir}/*"].select { |f| File.directory? f }
26
+ result.reject! do |f|
27
+ basename = File.basename(f)
28
+ basename =~ /^[a-z_\-0-9]+$/
29
+ end
30
+ result.sort.map { |path| Item.new path, :dir }
31
+ end
32
+ end
33
+ end
@@ -9,10 +9,10 @@ Parameters:
9
9
  Optional path to the markdown directory.
10
10
 
11
11
  Options:
12
- -p, --port <number>
12
+ -p, --port NUMBER
13
13
  Set server port number.
14
14
 
15
- -b, --bind <address>
15
+ -b, --bind ADDRESS
16
16
  Set server listen address.
17
17
 
18
18
  --no-auto-h1
@@ -29,12 +29,16 @@ Options:
29
29
  --index
30
30
  Build or rebuild the index for the search page.
31
31
 
32
+ --toc FILE
33
+ Generate a table of contents file.
34
+
32
35
  --and-quit
33
- Quit after building the index (applicable only with --index).
36
+ Quit instead of running the server. Useful with --index or --toc.
34
37
 
35
38
  Examples:
36
39
  madness
37
40
  madness docs
38
41
  madness docs --no-auto-h1 -p 4567
39
42
  madness --index --and-quit
43
+ madness --toc "Table of Contents.md" --index --and-quit
40
44
 
@@ -63,8 +63,7 @@ module Madness
63
63
  # 1. Syntax highilghting
64
64
  # 2. Prepend H1 if needed
65
65
  def markdown_to_html
66
- doc = CommonMarker.render_doc(File.read file)
67
- html = doc.to_html
66
+ html = CommonMarker.render_html File.read(file), :DEFAULT, [:table]
68
67
  html = syntax_highlight(html) if config.highlighter
69
68
  html = prepend_h1(html) if config.autoh1
70
69
  html
@@ -0,0 +1,34 @@
1
+ module Madness
2
+ class Item
3
+ include ServerHelper
4
+
5
+ attr_reader :path, :type
6
+
7
+ def initialize(path, type)
8
+ @path, @type = path, type
9
+ end
10
+
11
+ def label
12
+ @label ||= File.basename(path_without_extension)
13
+ end
14
+
15
+ def href
16
+ URI.escape(path_without_extension.sub(/^#{docroot}/, ''))
17
+ end
18
+
19
+ def dir?
20
+ type == :dir
21
+ end
22
+
23
+ def file?
24
+ type == :file
25
+ end
26
+
27
+ private
28
+
29
+ def path_without_extension
30
+ @path_without_extension ||= path.sub(/\.md$/, '')
31
+ end
32
+ end
33
+ end
34
+
@@ -3,59 +3,28 @@ module Madness
3
3
  class Navigation
4
4
  include ServerHelper
5
5
 
6
- attr_reader :links, :caption
6
+ attr_reader :dir
7
7
 
8
8
  def initialize(dir)
9
- @links = make_links dir
10
- # @caption = File.basename(dir) unless dir == docroot
11
- @caption = dir == docroot ? "Index" : File.basename(dir)
9
+ @dir = dir
12
10
  end
13
11
 
14
- def with_search?
15
- @with_search ||= Search.new.has_index?
12
+ def links
13
+ @links ||= directory.list
16
14
  end
17
15
 
18
- private
19
-
20
- # Prepare a list of links from all the accepted items in the directory
21
- def make_links(dir)
22
- files = get_files dir
23
- dirs = get_dirs dir
24
-
25
- links = []
26
-
27
- dirs.sort.each do |item|
28
- links.push link(item, :dir)
29
- end
30
-
31
- files.each do |item|
32
- links.push link(item, :file)
33
- end
34
-
35
- links
16
+ def caption
17
+ @caption ||= (dir == docroot ? "Index" : File.basename(dir))
36
18
  end
37
19
 
38
- def get_files(dir)
39
- files = Dir["#{dir}/*.md"].map { |f| f.sub(/\.md$/, '') }
40
- files.reject! { |f| File.basename(f) == 'README' }
41
- files.sort
20
+ def with_search?
21
+ @with_search ||= Search.new.has_index?
42
22
  end
43
23
 
44
- def get_dirs(dir)
45
- dirs = Dir["#{dir}/*"].select { |f| File.directory? f }
46
- dirs.reject! do |f|
47
- basename = File.basename(f)
48
- basename[0] == '_' or basename =~ /^[a-z_\-0-9]+$/
49
- end
50
- dirs
51
- end
24
+ private
52
25
 
53
- def link(item, type)
54
- OpenStruct.new({
55
- label: File.basename(item).tr('-', ' '),
56
- href: URI.escape(item.sub(/^#{docroot}/, '')),
57
- type: type
58
- })
26
+ def directory
27
+ @directory ||= Directory.new(dir)
59
28
  end
60
29
  end
61
30
  end
@@ -25,7 +25,7 @@ module Madness
25
25
  redirect "#{path}/"
26
26
  end
27
27
 
28
- nav = Navigation.new(dir)
28
+ nav = Navigation.new dir
29
29
  breadcrumbs = Breadcrumbs.new(path).links
30
30
 
31
31
  if nav.links.count == 1 and doc.type == :empty
@@ -10,7 +10,7 @@ module Madness
10
10
  include Singleton
11
11
 
12
12
  attr_accessor :port, :bind, :path, :autoh1,
13
- :highlighter, :line_numbers, :index
13
+ :highlighter, :line_numbers, :index, :toc
14
14
 
15
15
  def initialize
16
16
  reset
@@ -42,6 +42,7 @@ module Madness
42
42
  self.highlighter = true
43
43
  self.line_numbers = true
44
44
  self.index = false
45
+ self.index = false
45
46
  end
46
47
 
47
48
  def load_from_file
@@ -0,0 +1,42 @@
1
+ module Madness
2
+ # Generate a markdown Table of Contents
3
+ class TableOfContents
4
+ include ServerHelper
5
+
6
+ attr_reader :dir
7
+
8
+ def initialize(dir=nil)
9
+ @dir = dir || docroot
10
+ end
11
+
12
+ def build(file)
13
+ file += ".md" unless file.end_with? '.md'
14
+ File.write "#{dir}/#{file}", toc
15
+ end
16
+
17
+ def toc
18
+ @toc ||= toc!.join("\n")
19
+ end
20
+
21
+ private
22
+
23
+ def toc!(path=dir, indent=0)
24
+ list = Directory.new(path).list
25
+
26
+ result = []
27
+ list.each do |item|
28
+ if item.type == :dir
29
+ result.push "#{' ' * indent}1. #{make_link item}"
30
+ result += toc! item.path, indent+4
31
+ elsif item.type == :file
32
+ result.push "#{' ' * indent}1. #{make_link item}"
33
+ end
34
+ end
35
+ result
36
+ end
37
+
38
+ def make_link(item)
39
+ "[#{item.label}](#{item.href})"
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
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: 0.5.1
4
+ version: 0.5.2
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: 2018-05-12 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0.4'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec_fixtures
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.4'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.4'
209
223
  - !ruby/object:Gem::Dependency
210
224
  name: byebug
211
225
  requirement: !ruby/object:Gem::Requirement
@@ -327,14 +341,17 @@ files:
327
341
  - lib/madness.rb
328
342
  - lib/madness/breadcrumbs.rb
329
343
  - lib/madness/command_line.rb
344
+ - lib/madness/directory.rb
330
345
  - lib/madness/docopt.txt
331
346
  - lib/madness/document.rb
347
+ - lib/madness/item.rb
332
348
  - lib/madness/navigation.rb
333
349
  - lib/madness/search.rb
334
350
  - lib/madness/server.rb
335
351
  - lib/madness/server_base.rb
336
352
  - lib/madness/server_helper.rb
337
353
  - lib/madness/settings.rb
354
+ - lib/madness/table_of_contents.rb
338
355
  - lib/madness/try_static.rb
339
356
  - lib/madness/version.rb
340
357
  homepage: https://github.com/DannyBen/madness