madman 0.1.2 → 0.1.3

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: 8d2cbbb3df05900e21afcc52747a66d7e29966f89e16f479cf5fdf55dfcbf3d0
4
- data.tar.gz: 48a7d30f17a8b31909d11ea296c424cbb5611d931d4b1ab101166bb192e43f57
3
+ metadata.gz: 23e170953e138b20f746310e8152cd7b43a7e1da60023d52745d94c55a1a9e4f
4
+ data.tar.gz: 1a9315ef63047804e548e040e1aeb9fff47dd87d06bfa6f3050b87bdc4f1c6cb
5
5
  SHA512:
6
- metadata.gz: 6e2fe3266fe89d3ba1c9cfa776e533d52919dbc0af47609ea5057f07bb6b8d420bd6cbcceb9914a9e53c94975a85ea245df4d91e0025ff0a50427e88051f9fa3
7
- data.tar.gz: 59ae594fc5021740a4b980e914b8309a404f1399bfd99a322286307d99a84715f0452eb7131d5f0343715d6c5f221d3614768d10024a45f6bc6034b9e1280aa7
6
+ metadata.gz: 75bc524b8513c711066ae65c649d752d49475e3e6e1f6b705ec751a5ec27034b1c7683dbf4fc3bc876a4bf17fd30821a078241a44d5d3b8d4c6286567e03cfc0
7
+ data.tar.gz: c519c432a7288f9ca983aa1ec06aba4437b81f699db16741d49c70200558fbf8868bfbdd86a8e23f98d919a5069c5ff80900006170f2a110d2775f33cfabcb4c
data/README.md CHANGED
@@ -9,7 +9,7 @@ Madman
9
9
 
10
10
  ---
11
11
 
12
- The Markdown Swiss Armi Knife
12
+ The Markdown Swiss Army Knife
13
13
 
14
14
  ---
15
15
 
@@ -28,17 +28,21 @@ gem 'madman', require: false
28
28
 
29
29
 
30
30
 
31
- Key Features
31
+ Features
32
32
  --------------------------------------------------
33
33
 
34
- - GitHub-style markdown generation.
35
- - Convert markdown to a single HTML file (including CSS).
36
- - Ad-hoc server to serve a markdown file locally for preview.
37
- - Markdown generation with GitHub API (optional).
38
- - Table of Contents generation for a folder of markdown files.
39
- - Web server for an entire folder (like [Madness](https://github.com/DannyBen/madness))
40
- - [Planned] Table of Contents generation for a single file.
41
- - [Planned] Combine multiple markdown files to one.
34
+ - [x] GitHub-style markdown generation (markup and stylesheet).
35
+ - [x] Convert markdown to HTML file.
36
+ - [x] Ad-hoc server to serve a markdown file locally for preview.
37
+ - [x] Markdown generation with GitHub API (optional).
38
+ - [x] Table of Contents generation for a folder of markdown files.
39
+ - [x] Web server for an entire folder (like [Madness][1]) with GitHub Pages
40
+ compatibility.
41
+ - [x] Automatic detection of Right-to-Left markdown files for HTML rendering.
42
+ - [x] Generate navigation README in folders without one.
43
+ - [ ] [Planned] Generate breadcrumbs.
44
+ - [ ] [Planned] Combine multiple markdown files to one.
45
+ - [ ] [Considered] Table of Contents generation for a single file.
42
46
 
43
47
 
44
48
 
@@ -52,8 +56,9 @@ $ madman
52
56
  Commands:
53
57
  nav Add site-wide navigation links to README files
54
58
  preview Serve a markdown file using a local server
59
+ readme Create README in all qualified sub directories
55
60
  render Render markdown to HTML
56
- serve Serve a markdown folder using a local server
61
+ serve Serve a markdown directory using a local server
57
62
  ```
58
63
 
59
64
  <!-- usage -->
@@ -66,7 +71,7 @@ Commands:
66
71
  $ madman render
67
72
  Usage:
68
73
  madman render FILE [--github --save OUTFILE]
69
- madman render (-h|--help|--version)
74
+ madman render (-h|--help)
70
75
  ```
71
76
 
72
77
  <!-- render -->
@@ -80,7 +85,7 @@ Render markdown to HTML
80
85
 
81
86
  Usage:
82
87
  madman render FILE [--github --save OUTFILE]
83
- madman render (-h|--help|--version)
88
+ madman render (-h|--help)
84
89
 
85
90
  Options:
86
91
  --github
@@ -119,7 +124,7 @@ Examples:
119
124
  $ madman preview
120
125
  Usage:
121
126
  madman preview FILE [--port N --bind ADDRESS]
122
- madman preview (-h|--help|--version)
127
+ madman preview (-h|--help)
123
128
  ```
124
129
 
125
130
  <!-- preview -->
@@ -136,7 +141,7 @@ This command will start a local server with two endpoints:
136
141
 
137
142
  Usage:
138
143
  madman preview FILE [--port N --bind ADDRESS]
139
- madman preview (-h|--help|--version)
144
+ madman preview (-h|--help)
140
145
 
141
146
  Options:
142
147
  -p --port N
@@ -173,8 +178,8 @@ Examples:
173
178
  ```
174
179
  $ madman serve
175
180
  Usage:
176
- madman serve FOLDER [--port N --bind ADDRESS --github]
177
- madman serve (-h|--help|--version)
181
+ madman serve DIR [--port N --bind ADDRESS --github]
182
+ madman serve (-h|--help)
178
183
  ```
179
184
 
180
185
  <!-- serve -->
@@ -183,11 +188,11 @@ Usage:
183
188
 
184
189
  ```
185
190
  $ madman serve --help
186
- Serve a markdown folder using a local server
191
+ Serve a markdown directory using a local server
187
192
 
188
193
  Usage:
189
- madman serve FOLDER [--port N --bind ADDRESS --github]
190
- madman serve (-h|--help|--version)
194
+ madman serve DIR [--port N --bind ADDRESS --github]
195
+ madman serve (-h|--help)
191
196
 
192
197
  Options:
193
198
  --github
@@ -203,8 +208,8 @@ Options:
203
208
  Show this help
204
209
 
205
210
  Parameters:
206
- FOLDER
207
- The folder containing markdown files
211
+ DIR
212
+ The directory containing markdown files
208
213
 
209
214
  Environment Variables:
210
215
  GITHUB_ACCESS_TOKEN
@@ -227,8 +232,8 @@ Examples:
227
232
  ```
228
233
  $ madman nav
229
234
  Usage:
230
- madman nav FOLDER [--marker TEXT --force --dry --verbose --depth N]
231
- madman nav (-h|--help|--version)
235
+ madman nav DIR [options]
236
+ madman nav (-h|--help)
232
237
  ```
233
238
 
234
239
  <!-- nav -->
@@ -239,17 +244,18 @@ Usage:
239
244
  $ madman nav --help
240
245
  Add site-wide navigation links to README files
241
246
 
242
- This command will add a table of contents to all README files in the folder. The
243
- table of contents will link to all the pages and folders that are in the same
244
- folder as each README file.
247
+ This command generates a Table of Contents for a directory, and injects it to a
248
+ file. In addition, it supports recursive execution, which will add a Table of
249
+ Contents to all README files (or a filename of your choice) in all the
250
+ subfolders, creating nagigation pages for an entire Markdown site.
245
251
 
246
252
  Usage:
247
- madman nav FOLDER [--marker TEXT --force --dry --verbose --depth N]
248
- madman nav (-h|--help|--version)
253
+ madman nav DIR [options]
254
+ madman nav (-h|--help)
249
255
 
250
256
  Options:
251
257
  -f --force
252
- Add to all README files, even if they do not have a marker
258
+ Inject TOC to all README files, even if they do not have a marker
253
259
 
254
260
  -m --marker TEXT
255
261
  Look for an HTML comment with <!-- TEXT --> [default: nav]
@@ -257,18 +263,24 @@ Options:
257
263
  -d --depth N
258
264
  The depth of the table of contents [default: 1]
259
265
 
260
- --dry
261
- Do not save the updated files, just show what will happen
262
-
263
266
  -v --verbose
264
267
  Show the updated README content
265
268
 
269
+ -t --target NAME
270
+ Set the target filename to look for. [default: README.md]
271
+
272
+ -r --recursive
273
+ Inject to all target files
274
+
275
+ -y --dry
276
+ Do not save the updated files, just show what will happen
277
+
266
278
  -h --help
267
279
  Show this help
268
280
 
269
281
  Parameters:
270
- FOLDER
271
- The folder containing markdown files
282
+ DIR
283
+ The directory containing markdown files
272
284
 
273
285
  Examples:
274
286
  madman nav
@@ -277,3 +289,52 @@ Examples:
277
289
  ```
278
290
 
279
291
  <!-- nav-help --></details>
292
+
293
+
294
+ ### Generate README files with H1
295
+
296
+ <!-- readme -->
297
+
298
+ ```
299
+ $ madman readme
300
+ Usage:
301
+ madman readme DIR [--dry]
302
+ madman readme (-h|--help)
303
+ ```
304
+
305
+ <!-- readme -->
306
+
307
+ <details><summary>Show full usage</summary><!-- readme-help -->
308
+
309
+ ```
310
+ $ madman readme --help
311
+ Create README in all qualified sub directories
312
+
313
+ This command generates README.md files in all subdirectories. Each file will
314
+ receive an H1 caption with the name of the folder it resides in. This command is
315
+ designed to assist in preparing a folder for table of contents injection.
316
+
317
+ Usage:
318
+ madman readme DIR [--dry]
319
+ madman readme (-h|--help)
320
+
321
+ Options:
322
+ -y --dry
323
+ Only show what will be created, don't make any changes
324
+
325
+ -h --help
326
+ Show this help
327
+
328
+ Parameters:
329
+ DIR
330
+ The directory containing markdown files
331
+
332
+ Examples:
333
+ madman readme .
334
+ madman readme path/to/docs --dry
335
+ ```
336
+
337
+ <!-- readme-help --></details>
338
+
339
+
340
+ [1]: https://github.com/DannyBen/madness
data/bin/madman-nav.rb CHANGED
@@ -1,48 +1,62 @@
1
1
  require 'madman'
2
+ require 'io/console'
2
3
 
3
4
  summary "Add site-wide navigation links to README files"
4
5
 
5
- help "This command will add a table of contents to all README files in the folder. The table of contents will link to all the pages and folders that are in the same folder as each README file."
6
+ help "This command generates a Table of Contents for a directory, and injects it to a file. In addition, it supports recursive execution, which will add a Table of Contents to all README files (or a filename of your choice) in all the subfolders, creating nagigation pages for an entire Markdown site."
6
7
 
7
- usage "madman nav FOLDER [--marker TEXT --force --dry --verbose --depth N]"
8
- usage "madman nav (-h|--help|--version)"
8
+ usage "madman nav DIR [options]"
9
+ usage "madman nav (-h|--help)"
9
10
 
10
- option "-f --force", "Add to all README files, even if they do not have a marker"
11
+ option "-f --force", "Inject TOC to all README files, even if they do not have a marker"
11
12
  option "-m --marker TEXT", "Look for an HTML comment with <!-- TEXT --> [default: nav]"
12
13
  option "-d --depth N", "The depth of the table of contents [default: 1]"
13
- option "--dry", "Do not save the updated files, just show what will happen"
14
14
  option "-v --verbose", "Show the updated README content"
15
+ option "-t --target NAME", "Set the target filename to look for. [default: README.md]"
16
+ option "-r --recursive", "Inject to all target files"
17
+ option "-y --dry", "Do not save the updated files, just show what will happen"
15
18
 
16
- param "FOLDER", "The folder containing markdown files"
19
+ param "DIR", "The directory containing markdown files"
17
20
 
18
21
  example "madman nav"
19
22
  example "madman nav path/to/docs --force --marker toc"
20
23
  example "madman nav path/to/docs --dry -v -d2"
21
24
 
22
25
  action do |args|
23
- dir = args['FOLDER'] || '.'
24
- force = args['--force']
25
- marker = args['--marker']
26
- dry = args['--dry']
27
- verbose = args['--verbose']
28
- depth = args['--depth'].to_i
29
-
30
- candidates = Dir["#{dir}/**/README.md"]
31
- candidates.each do |candidate|
32
- say "Updating !txtgrn!#{candidate}"
33
- candidate_dir = File.dirname candidate
34
- toc = Madman::Navigation.new candidate_dir, depth: depth
35
- doc = Madman::Document.from_file candidate
36
- doc.inject toc.markdown, marker: marker, force: force
37
-
38
- if verbose
39
- say word_wrap " !txtblu!#{doc.text}"
40
- say ""
41
- end
42
-
43
- doc.save unless dry
26
+ @args = args
27
+
28
+ if recursive?
29
+ Dir["#{dir}/**/#{target}"].each { |file| update_file file }
30
+ else
31
+ update_file "#{dir}/#{target}"
32
+ end
33
+
34
+ say dry? ? "Done (dry mode, no changes were made)" : "Done"
35
+ end
36
+
37
+ def update_file(file)
38
+ say "Updating !txtgrn!#{file}"
39
+ file_dir = File.dirname file
40
+ toc = Madman::Navigation.new file_dir, depth: depth
41
+ doc = Madman::Document.from_file file
42
+ doc.inject toc.markdown, marker: marker, force: force?
43
+
44
+ if verbose?
45
+ say word_wrap " !txtblu!#{doc.text}"
46
+ say ""
44
47
  end
45
48
 
46
- say dry ? "Done (dry mode, nothing changed)" : "Done"
49
+ doc.save unless dry?
47
50
  end
48
51
 
52
+ # CLI Arguments
53
+
54
+ def args; @args; end
55
+ def dir; args['DIR'] || '.'; end
56
+ def depth; args['--depth'].to_i; end
57
+ def marker; args['--marker']; end
58
+ def target; args['--target']; end
59
+ def force?; args['--force']; end
60
+ def dry?; args['--dry']; end
61
+ def verbose?; args['--verbose']; end
62
+ def recursive?; args['--recursive']; end
@@ -5,7 +5,7 @@ summary "Serve a markdown file using a local server"
5
5
  help "This command will start a local server with two endpoints:\n / will render the markdown with the default renderer\n /github will render with the GitHub API"
6
6
 
7
7
  usage "madman preview FILE [--port N --bind ADDRESS]"
8
- usage "madman preview (-h|--help|--version)"
8
+ usage "madman preview (-h|--help)"
9
9
 
10
10
  option "-p --port N", "Set server port [default: 3000]"
11
11
  option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
@@ -0,0 +1,37 @@
1
+ require 'madman'
2
+ require 'lp'
3
+
4
+ summary "Create README in all qualified sub directories"
5
+
6
+ help "This command generates README.md files in all subdirectories. Each file will receive an H1 caption with the name of the folder it resides in. This command is designed to assist in preparing a folder for table of contents injection."
7
+
8
+ usage "madman readme DIR [--dry]"
9
+ usage "madman readme (-h|--help)"
10
+
11
+ option "-y --dry", "Only show what will be created, don't make any changes"
12
+
13
+ param "DIR", "The directory containing markdown files"
14
+
15
+ example "madman readme ."
16
+ example "madman readme path/to/docs --dry"
17
+
18
+ action do |args|
19
+ dir = args['DIR']
20
+ basedir = Madman::Directory.new dir, dir
21
+
22
+ dirs = basedir.deep_list.select { |i| i.dir? }.map { |i| i.path }
23
+ dirs.each do |dir|
24
+ file = "#{dir}/README.md"
25
+
26
+ if File.exist? file
27
+ say "Skipping #{file}"
28
+ else
29
+ say "Creating !txtgrn!#{file}"
30
+ h1 = "# #{File.basename dir}\n\n"
31
+ File.write file, h1 unless args['--dry']
32
+ end
33
+ end
34
+
35
+ say args['--dry'] ? "Done (dry mode, no changes were made)" : "Done"
36
+ end
37
+
data/bin/madman-render.rb CHANGED
@@ -3,7 +3,7 @@ require 'madman'
3
3
  help "Render markdown to HTML"
4
4
 
5
5
  usage "madman render FILE [--github --save OUTFILE]"
6
- usage "madman render (-h|--help|--version)"
6
+ usage "madman render (-h|--help)"
7
7
 
8
8
  option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
9
9
  option "--save OUTFILE", "Save the output to a file"
data/bin/madman-serve.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'madman'
2
2
 
3
- summary "Serve a markdown folder using a local server"
3
+ summary "Serve a markdown directory using a local server"
4
4
 
5
- usage "madman serve FOLDER [--port N --bind ADDRESS --github]"
6
- usage "madman serve (-h|--help|--version)"
5
+ usage "madman serve DIR [--port N --bind ADDRESS --github]"
6
+ usage "madman serve (-h|--help)"
7
7
 
8
8
  option "--github", "Use the GitHub API renderer instead of the default one"
9
9
  option "-p --port N", "Set server port [default: 3000]"
10
10
  option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
11
11
 
12
- param "FOLDER", "The folder containing markdown files"
12
+ param "DIR", "The directory containing markdown files"
13
13
 
14
14
  environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nRequired only if you wish to use the '/github' endpoint\nGenerate one here: https://github.com/settings/tokens"
15
15
 
@@ -17,7 +17,7 @@ example "madman serve"
17
17
  example "madman serve path/to/docs -p4000 --github"
18
18
 
19
19
  action do |args|
20
- dir = args['FOLDER'] || '.'
20
+ dir = args['DIR']
21
21
  port = args['--port']
22
22
  bind = args['--bind']
23
23
  renderer = args['--github'] ? :github : :default
@@ -12,6 +12,14 @@ module Madman
12
12
  @list ||= (dirs + files)
13
13
  end
14
14
 
15
+ def deep_list
16
+ result = list
17
+ dirs.each do |dir|
18
+ result += Directory.new(dir.path, basedir).deep_list
19
+ end
20
+ result
21
+ end
22
+
15
23
  private
16
24
 
17
25
  def files
@@ -1,3 +1,3 @@
1
1
  module Madman
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-21 00:00:00.000000000 Z
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -296,6 +296,7 @@ executables:
296
296
  - madman
297
297
  - madman-nav.rb
298
298
  - madman-preview.rb
299
+ - madman-readme.rb
299
300
  - madman-render.rb
300
301
  - madman-serve.rb
301
302
  extensions: []
@@ -305,6 +306,7 @@ files:
305
306
  - bin/madman
306
307
  - bin/madman-nav.rb
307
308
  - bin/madman-preview.rb
309
+ - bin/madman-readme.rb
308
310
  - bin/madman-render.rb
309
311
  - bin/madman-serve.rb
310
312
  - lib/madman.rb
@@ -344,5 +346,5 @@ rubyforge_project:
344
346
  rubygems_version: 2.7.6
345
347
  signing_key:
346
348
  specification_version: 4
347
- summary: The Markdown Swiss Armi Knife
349
+ summary: The Markdown Swiss Army Knife
348
350
  test_files: []