-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from DannyBen/mister-bin-update
Migrate to new mister_bin
- Loading branch information
Showing
22 changed files
with
275 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'mister_bin' | ||
require 'madman/commands' | ||
|
||
module Madman | ||
class CLI | ||
def self.runner | ||
runner = MisterBin::Runner.new version: Madman::VERSION | ||
|
||
runner.route 'nav', to: Madman::Commands::Nav | ||
runner.route 'preview', to: Madman::Commands::Preview | ||
runner.route 'readme', to: Madman::Commands::Readme | ||
runner.route 'render', to: Madman::Commands::Render | ||
runner.route 'serve', to: Madman::Commands::Serve | ||
|
||
runner | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'madman/commands/nav' | ||
require 'madman/commands/preview' | ||
require 'madman/commands/readme' | ||
require 'madman/commands/render' | ||
require 'madman/commands/serve' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'io/console' | ||
|
||
module Madman | ||
module Commands | ||
class Nav < MisterBin::Command | ||
include Colsole | ||
|
||
summary "Add site-wide navigation links to README files" | ||
|
||
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." | ||
|
||
usage "madman nav DIR [options]" | ||
usage "madman nav (-h|--help)" | ||
|
||
option "-f --force", "Inject TOC to all README files, even if they do not have a marker" | ||
option "-m --marker TEXT", "Look for an HTML comment with <!-- TEXT --> [default: nav]" | ||
option "-d --depth N", "The depth of the table of contents [default: 1]" | ||
option "-v --verbose", "Show the updated README content" | ||
option "-t --target NAME", "Set the target filename to look for. [default: README.md]" | ||
option "-r --recursive", "Inject to all target files" | ||
option "-y --dry", "Do not save the updated files, just show what will happen" | ||
|
||
param "DIR", "The directory containing markdown files" | ||
|
||
example "madman nav" | ||
example "madman nav path/to/docs --force --marker toc" | ||
example "madman nav path/to/docs --dry -v -d2" | ||
|
||
def run(args) | ||
@args = args | ||
|
||
if recursive? | ||
Dir["#{dir}/**/#{target}"].each { |file| update_file file } | ||
else | ||
update_file "#{dir}/#{target}" | ||
end | ||
|
||
say dry? ? "Done (dry mode, no changes were made)" : "Done" | ||
end | ||
|
||
def update_file(file) | ||
say "Updating !txtgrn!#{file}" | ||
file_dir = File.dirname file | ||
toc = Madman::Navigation.new file_dir, depth: depth | ||
doc = Madman::Document.from_file file | ||
doc.inject toc.markdown, marker: marker, force: force? | ||
|
||
if verbose? | ||
say word_wrap " !txtblu!#{doc.text}" | ||
say "" | ||
end | ||
|
||
doc.save unless dry? | ||
end | ||
|
||
# CLI Arguments | ||
|
||
def args; @args; end | ||
def dir; args['DIR'] || '.'; end | ||
def depth; args['--depth'].to_i; end | ||
def marker; args['--marker']; end | ||
def target; args['--target']; end | ||
def force?; args['--force']; end | ||
def dry?; args['--dry']; end | ||
def verbose?; args['--verbose']; end | ||
def recursive?; args['--recursive']; end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Madman | ||
module Commands | ||
class Preview < MisterBin::Command | ||
include Colsole | ||
|
||
summary "Serve a markdown file using a local server" | ||
|
||
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" | ||
|
||
usage "madman preview FILE [--port N --bind ADDRESS]" | ||
usage "madman preview (-h|--help)" | ||
|
||
option "-p --port N", "Set server port [default: 3000]" | ||
option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]" | ||
|
||
param "FILE", "The input markdown file" | ||
|
||
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" | ||
|
||
example "madman preview README.md" | ||
example "madman preview README.md -p4000" | ||
|
||
def run(args) | ||
file = args['FILE'] | ||
port = args['--port'] | ||
bind = args['--bind'] | ||
|
||
say "Starting server at !undblu!localhost:#{port}!txtrst!" | ||
if ENV['GITHUB_ACCESS_TOKEN'] | ||
say "To view the GitHub API version go to !undblu!localhost:#{port}/github!txtrst!" | ||
end | ||
say '' | ||
|
||
Madman::PreviewServer.set bind: bind, port: port, file: file | ||
Madman::PreviewServer.run! | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
Oops, something went wrong.