madman 0.1.3 → 0.2.0

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: 23e170953e138b20f746310e8152cd7b43a7e1da60023d52745d94c55a1a9e4f
4
- data.tar.gz: 1a9315ef63047804e548e040e1aeb9fff47dd87d06bfa6f3050b87bdc4f1c6cb
3
+ metadata.gz: '0397dcc8aa59270b402f884eef91bb3b9359c678317f5dc11b7b04e55fc714a0'
4
+ data.tar.gz: b03912ea38913bc419d0bab33bd533bfce1b4688d7972e28963205c92f7ea2ba
5
5
  SHA512:
6
- metadata.gz: 75bc524b8513c711066ae65c649d752d49475e3e6e1f6b705ec751a5ec27034b1c7683dbf4fc3bc876a4bf17fd30821a078241a44d5d3b8d4c6286567e03cfc0
7
- data.tar.gz: c519c432a7288f9ca983aa1ec06aba4437b81f699db16741d49c70200558fbf8868bfbdd86a8e23f98d919a5069c5ff80900006170f2a110d2775f33cfabcb4c
6
+ metadata.gz: 8e8a338fac43b8979a5ad68b158512bf85c102808c7ee284f3d5157fb537258d308a4acaa59a6238bcc5b7e2bfbb526670b574d3a3d5917f1400aea4b6ac61b2
7
+ data.tar.gz: c2d9c12999e35514c866653b655cb231e3e1a53af6b0932917779820c49e9542d7fb19e1b3cbbcc282f003dd011792fc0d74372f254879f341a0d99b4ad64291
data/bin/madman CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- require 'mister_bin'
3
- require 'madman/version'
2
+ require 'madman'
3
+ require 'madman/cli'
4
4
 
5
- runner = MisterBin::Runner.new 'madman', basedir: __dir__,
6
- version: Madman::VERSION
5
+ runner = Madman::CLI.runner
7
6
 
8
7
  begin
9
8
  exit runner.run ARGV
@@ -5,6 +5,7 @@ require 'sinatra/reloader'
5
5
  require 'slim'
6
6
  require 'string-direction'
7
7
 
8
+ require 'madman/cli'
8
9
  require 'madman/injector'
9
10
 
10
11
  require 'madman/directory'
@@ -17,4 +18,5 @@ require 'madman/server_base'
17
18
  require 'madman/preview_server'
18
19
  require 'madman/server'
19
20
 
21
+
20
22
  require 'byebug' if ENV['BYEBUG']
@@ -0,0 +1,19 @@
1
+ require 'mister_bin'
2
+ require 'madman/commands'
3
+
4
+ module Madman
5
+ class CLI
6
+ def self.runner
7
+ runner = MisterBin::Runner.new version: Madman::VERSION
8
+
9
+ runner.route 'nav', to: Madman::Commands::Nav
10
+ runner.route 'preview', to: Madman::Commands::Preview
11
+ runner.route 'readme', to: Madman::Commands::Readme
12
+ runner.route 'render', to: Madman::Commands::Render
13
+ runner.route 'serve', to: Madman::Commands::Serve
14
+
15
+ runner
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'madman/commands/nav'
2
+ require 'madman/commands/preview'
3
+ require 'madman/commands/readme'
4
+ require 'madman/commands/render'
5
+ require 'madman/commands/serve'
@@ -0,0 +1,70 @@
1
+ require 'io/console'
2
+
3
+ module Madman
4
+ module Commands
5
+ class Nav < MisterBin::Command
6
+ include Colsole
7
+
8
+ summary "Add site-wide navigation links to README files"
9
+
10
+ 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."
11
+
12
+ usage "madman nav DIR [options]"
13
+ usage "madman nav (-h|--help)"
14
+
15
+ option "-f --force", "Inject TOC to all README files, even if they do not have a marker"
16
+ option "-m --marker TEXT", "Look for an HTML comment with <!-- TEXT --> [default: nav]"
17
+ option "-d --depth N", "The depth of the table of contents [default: 1]"
18
+ option "-v --verbose", "Show the updated README content"
19
+ option "-t --target NAME", "Set the target filename to look for. [default: README.md]"
20
+ option "-r --recursive", "Inject to all target files"
21
+ option "-y --dry", "Do not save the updated files, just show what will happen"
22
+
23
+ param "DIR", "The directory containing markdown files"
24
+
25
+ example "madman nav"
26
+ example "madman nav path/to/docs --force --marker toc"
27
+ example "madman nav path/to/docs --dry -v -d2"
28
+
29
+ def run(args)
30
+ @args = args
31
+
32
+ if recursive?
33
+ Dir["#{dir}/**/#{target}"].each { |file| update_file file }
34
+ else
35
+ update_file "#{dir}/#{target}"
36
+ end
37
+
38
+ say dry? ? "Done (dry mode, no changes were made)" : "Done"
39
+ end
40
+
41
+ def update_file(file)
42
+ say "Updating !txtgrn!#{file}"
43
+ file_dir = File.dirname file
44
+ toc = Madman::Navigation.new file_dir, depth: depth
45
+ doc = Madman::Document.from_file file
46
+ doc.inject toc.markdown, marker: marker, force: force?
47
+
48
+ if verbose?
49
+ say word_wrap " !txtblu!#{doc.text}"
50
+ say ""
51
+ end
52
+
53
+ doc.save unless dry?
54
+ end
55
+
56
+ # CLI Arguments
57
+
58
+ def args; @args; end
59
+ def dir; args['DIR'] || '.'; end
60
+ def depth; args['--depth'].to_i; end
61
+ def marker; args['--marker']; end
62
+ def target; args['--target']; end
63
+ def force?; args['--force']; end
64
+ def dry?; args['--dry']; end
65
+ def verbose?; args['--verbose']; end
66
+ def recursive?; args['--recursive']; end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,41 @@
1
+ module Madman
2
+ module Commands
3
+ class Preview < MisterBin::Command
4
+ include Colsole
5
+
6
+ summary "Serve a markdown file using a local server"
7
+
8
+ 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"
9
+
10
+ usage "madman preview FILE [--port N --bind ADDRESS]"
11
+ usage "madman preview (-h|--help)"
12
+
13
+ option "-p --port N", "Set server port [default: 3000]"
14
+ option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
15
+
16
+ param "FILE", "The input markdown file"
17
+
18
+ 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"
19
+
20
+ example "madman preview README.md"
21
+ example "madman preview README.md -p4000"
22
+
23
+ def run(args)
24
+ file = args['FILE']
25
+ port = args['--port']
26
+ bind = args['--bind']
27
+
28
+ say "Starting server at !undblu!localhost:#{port}!txtrst!"
29
+ if ENV['GITHUB_ACCESS_TOKEN']
30
+ say "To view the GitHub API version go to !undblu!localhost:#{port}/github!txtrst!"
31
+ end
32
+ say ''
33
+
34
+ Madman::PreviewServer.set bind: bind, port: port, file: file
35
+ Madman::PreviewServer.run!
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,45 @@
1
+ require 'lp'
2
+
3
+ module Madman
4
+ module Commands
5
+ class Readme < MisterBin::Command
6
+ include Colsole
7
+
8
+ summary "Create README in all qualified sub directories"
9
+
10
+ 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."
11
+
12
+ usage "madman readme DIR [--dry]"
13
+ usage "madman readme (-h|--help)"
14
+
15
+ option "-y --dry", "Only show what will be created, don't make any changes"
16
+
17
+ param "DIR", "The directory containing markdown files"
18
+
19
+ example "madman readme ."
20
+ example "madman readme path/to/docs --dry"
21
+
22
+ def run(args)
23
+ dir = args['DIR']
24
+ basedir = Madman::Directory.new dir, dir
25
+
26
+ dirs = basedir.deep_list.select { |i| i.dir? }.map { |i| i.path }
27
+ dirs.each do |dir|
28
+ file = "#{dir}/README.md"
29
+
30
+ if File.exist? file
31
+ say "Skipping #{file}"
32
+ else
33
+ say "Creating !txtgrn!#{file}"
34
+ h1 = "# #{File.basename dir}\n\n"
35
+ File.write file, h1 unless args['--dry']
36
+ end
37
+ end
38
+
39
+ say args['--dry'] ? "Done (dry mode, no changes were made)" : "Done"
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,42 @@
1
+ module Madman
2
+ module Commands
3
+ class Render < MisterBin::Command
4
+ include Colsole
5
+
6
+ help "Render markdown to HTML"
7
+
8
+ usage "madman render FILE [--github --save OUTFILE]"
9
+ usage "madman render (-h|--help)"
10
+
11
+ option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
12
+ option "--save OUTFILE", "Save the output to a file"
13
+
14
+ param "FILE", "The input markdown file"
15
+
16
+ environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nGenerate one here: https://github.com/settings/tokens"
17
+
18
+ example "madman render README.md"
19
+ example "madman render README.md --github"
20
+ example "madman render README.md --save out.html"
21
+
22
+ def run(args)
23
+ infile = args['FILE']
24
+ outfile = args['--save']
25
+ renderer = args['--github'] ? :github : :default
26
+
27
+ doc = Madman::Document.from_file infile
28
+
29
+ output = doc.render renderer
30
+
31
+ if outfile
32
+ File.write outfile, output
33
+ say "Saved !txtgrn!#{outfile}"
34
+ else
35
+ puts output
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,39 @@
1
+ module Madman
2
+ module Commands
3
+ class Serve < MisterBin::Command
4
+ include Colsole
5
+
6
+ summary "Serve a markdown directory using a local server"
7
+
8
+ usage "madman serve DIR [--port N --bind ADDRESS --github]"
9
+ usage "madman serve (-h|--help)"
10
+
11
+ option "--github", "Use the GitHub API renderer instead of the default one"
12
+ option "-p --port N", "Set server port [default: 3000]"
13
+ option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
14
+
15
+ param "DIR", "The directory containing markdown files"
16
+
17
+ 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"
18
+
19
+ example "madman serve"
20
+ example "madman serve path/to/docs -p4000 --github"
21
+
22
+ def run(args)
23
+ dir = args['DIR']
24
+ port = args['--port']
25
+ bind = args['--bind']
26
+ renderer = args['--github'] ? :github : :default
27
+
28
+ say "Starting server at !undblu!localhost:#{port}!txtrst! using the !txtgrn!#{renderer}!txtrst! renderer\n"
29
+
30
+ Madman::Server.set bind: bind, port: port,
31
+ dir: dir, renderer: renderer
32
+
33
+ Madman::Server.run!
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+
@@ -1,3 +1,3 @@
1
1
  module Madman
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
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.3
4
+ version: 0.2.0
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-26 00:00:00.000000000 Z
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: puma
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '10.0'
125
- - !ruby/object:Gem::Dependency
126
- name: github_changelog_generator
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '1.14'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '1.14'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: lp
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -294,22 +280,19 @@ description: A command line utility for markdown fun
294
280
  email: db@dannyben.com
295
281
  executables:
296
282
  - madman
297
- - madman-nav.rb
298
- - madman-preview.rb
299
- - madman-readme.rb
300
- - madman-render.rb
301
- - madman-serve.rb
302
283
  extensions: []
303
284
  extra_rdoc_files: []
304
285
  files:
305
286
  - README.md
306
287
  - bin/madman
307
- - bin/madman-nav.rb
308
- - bin/madman-preview.rb
309
- - bin/madman-readme.rb
310
- - bin/madman-render.rb
311
- - bin/madman-serve.rb
312
288
  - lib/madman.rb
289
+ - lib/madman/cli.rb
290
+ - lib/madman/commands.rb
291
+ - lib/madman/commands/nav.rb
292
+ - lib/madman/commands/preview.rb
293
+ - lib/madman/commands/readme.rb
294
+ - lib/madman/commands/render.rb
295
+ - lib/madman/commands/serve.rb
313
296
  - lib/madman/directory.rb
314
297
  - lib/madman/document.rb
315
298
  - lib/madman/injector.rb
@@ -1,62 +0,0 @@
1
- require 'madman'
2
- require 'io/console'
3
-
4
- summary "Add site-wide navigation links to README files"
5
-
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."
7
-
8
- usage "madman nav DIR [options]"
9
- usage "madman nav (-h|--help)"
10
-
11
- option "-f --force", "Inject TOC to all README files, even if they do not have a marker"
12
- option "-m --marker TEXT", "Look for an HTML comment with <!-- TEXT --> [default: nav]"
13
- option "-d --depth N", "The depth of the table of contents [default: 1]"
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"
18
-
19
- param "DIR", "The directory containing markdown files"
20
-
21
- example "madman nav"
22
- example "madman nav path/to/docs --force --marker toc"
23
- example "madman nav path/to/docs --dry -v -d2"
24
-
25
- action do |args|
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 ""
47
- end
48
-
49
- doc.save unless dry?
50
- end
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
@@ -1,34 +0,0 @@
1
- require 'madman'
2
-
3
- summary "Serve a markdown file using a local server"
4
-
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
-
7
- usage "madman preview FILE [--port N --bind ADDRESS]"
8
- usage "madman preview (-h|--help)"
9
-
10
- option "-p --port N", "Set server port [default: 3000]"
11
- option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
12
-
13
- param "FILE", "The input markdown file"
14
-
15
- 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"
16
-
17
- example "madman preview README.md"
18
- example "madman preview README.md -p4000"
19
-
20
- action do |args|
21
- file = args['FILE']
22
- port = args['--port']
23
- bind = args['--bind']
24
-
25
- say "Starting server at !undblu!localhost:#{port}!txtrst!"
26
- if ENV['GITHUB_ACCESS_TOKEN']
27
- say "To view the GitHub API version go to !undblu!localhost:#{port}/github!txtrst!"
28
- end
29
- say ''
30
-
31
- Madman::PreviewServer.set bind: bind, port: port, file: file
32
- Madman::PreviewServer.run!
33
- end
34
-
@@ -1,37 +0,0 @@
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
-
@@ -1,35 +0,0 @@
1
- require 'madman'
2
-
3
- help "Render markdown to HTML"
4
-
5
- usage "madman render FILE [--github --save OUTFILE]"
6
- usage "madman render (-h|--help)"
7
-
8
- option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
9
- option "--save OUTFILE", "Save the output to a file"
10
-
11
- param "FILE", "The input markdown file"
12
-
13
- environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nGenerate one here: https://github.com/settings/tokens"
14
-
15
- example "madman render README.md"
16
- example "madman render README.md --github"
17
- example "madman render README.md --save out.html"
18
-
19
- action do |args|
20
- infile = args['FILE']
21
- outfile = args['--save']
22
- renderer = args['--github'] ? :github : :default
23
-
24
- doc = Madman::Document.from_file infile
25
-
26
- output = doc.render renderer
27
-
28
- if outfile
29
- File.write outfile, output
30
- say "Saved !txtgrn!#{outfile}"
31
- else
32
- puts output
33
- end
34
- end
35
-
@@ -1,32 +0,0 @@
1
- require 'madman'
2
-
3
- summary "Serve a markdown directory using a local server"
4
-
5
- usage "madman serve DIR [--port N --bind ADDRESS --github]"
6
- usage "madman serve (-h|--help)"
7
-
8
- option "--github", "Use the GitHub API renderer instead of the default one"
9
- option "-p --port N", "Set server port [default: 3000]"
10
- option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
11
-
12
- param "DIR", "The directory containing markdown files"
13
-
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
-
16
- example "madman serve"
17
- example "madman serve path/to/docs -p4000 --github"
18
-
19
- action do |args|
20
- dir = args['DIR']
21
- port = args['--port']
22
- bind = args['--bind']
23
- renderer = args['--github'] ? :github : :default
24
-
25
- say "Starting server at !undblu!localhost:#{port}!txtrst! using the !txtgrn!#{renderer}!txtrst! renderer\n"
26
-
27
- Madman::Server.set bind: bind, port: port,
28
- dir: dir, renderer: renderer
29
-
30
- Madman::Server.run!
31
- end
32
-