madman 0.0.1 → 0.1.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: f748ad843c81bcf4868ed28e89bdf8ed7d8250a489a7d25ad1fd972241a95bfc
4
- data.tar.gz: 6e9fd6730d73a92ff64f7df7bc021c6776e5a6c1cf38d2908d0c737d59629385
3
+ metadata.gz: 1f05f3de9220613be599d500d333c17ee68b415a0f635fec5ce553a13f55a771
4
+ data.tar.gz: 753a684bdc3de29b0e74e9a0868f260d7d7e736aa7f1d554e61f30414dd48620
5
5
  SHA512:
6
- metadata.gz: 2101b953c8eb179a4e943e548868fafb544d3a6aed1205590ae665b8df8dcc0e251008d4f849c442a8830d98a361c1d7eb17f1b9c0cb88cec0cc0d2da68d54d3
7
- data.tar.gz: fab4a22e03dc6af9c5886983260541d1335204f3cc60f146e87ae92253a3f6fa8b399383f6307c83f99d43a52f5b7c11f650ed337737e4b9da0ebe1d2dba9f3d
6
+ metadata.gz: a7d40a171015a9cf52c727e16069f37d96ecea0956d4c347d89e6d66bed3719e21827b78b66ed3bf8e4c15569cd15a8b545524bb6d10ba894daaf4acafac51ab
7
+ data.tar.gz: 1e7c1342fa3c38c9996079d4eacb68814d5c660f82d541fd6354a31f994838026594b526306ca2f8179478d59fa192ddaa0c197be0e717890acae60d862c9131
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Madman
2
2
  ==================================================
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/madman.svg)](https://badge.fury.io/rb/madman)
5
+ [![Build Status](https://travis-ci.com/DannyBen/madman.svg?branch=master)](https://travis-ci.com/DannyBen/madman)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/506449ea988f5518425d/maintainability)](https://codeclimate.com/github/DannyBen/madman/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/506449ea988f5518425d/test_coverage)](https://codeclimate.com/github/DannyBen/madman/test_coverage)
8
+
9
+
4
10
  ---
5
11
 
6
12
  The Markdown Swiss Armi Knife
@@ -10,11 +16,124 @@ The Markdown Swiss Armi Knife
10
16
  Installation
11
17
  --------------------------------------------------
12
18
 
13
- $ gem install madman
19
+ ```
20
+ $ gem install madman
21
+ ```
22
+
23
+ Or with Bundler:
24
+
25
+ ```ruby
26
+ gem 'madman', require: false
27
+ ```
28
+
29
+
30
+
31
+ Key Features
32
+ --------------------------------------------------
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
+ - [Planned] Table of Contents generation for a single file.
39
+ - [Planned] Table of Contents generation for a folder of markdown files.
40
+ - [Planned] Combine multiple markdown files to one.
14
41
 
15
42
 
16
43
 
17
44
  Usage
18
45
  --------------------------------------------------
19
46
 
20
- TODO
47
+ <!-- usage -->
48
+ ```
49
+ $ madman
50
+ Commands:
51
+ render Render markdown to HTML
52
+ serve Run a webserver and serve the markdown file as HTML
53
+ ```
54
+
55
+ ---
56
+
57
+ ```
58
+ $ madman render --help
59
+ Render markdown to HTML
60
+
61
+ Usage:
62
+ madman render INFILE [OUTFILE] [--rtl --github]
63
+ madman render (-h|--help|--version)
64
+
65
+ Options:
66
+ --github
67
+ Render using the GitHub API
68
+ Requires setting the GITHUB_ACCESS_TOKEN environment variable
69
+
70
+ --rtl
71
+ Render text Right to Left
72
+
73
+ -h --help
74
+ Show this help
75
+
76
+ Parameters:
77
+ INFILE
78
+ The input markdown file
79
+
80
+ OUTFILE
81
+ The output HTML file
82
+ If not provided, the input filename will be used with .html extension
83
+
84
+ Environment Variables:
85
+ GITHUB_ACCESS_TOKEN
86
+ Your GitHub API access token
87
+ Generate one here: https://github.com/settings/tokens
88
+
89
+ Examples:
90
+ madman render README.md
91
+ madman render README.md --github
92
+ madman render README.md out.html --rtl
93
+ ```
94
+
95
+ ---
96
+
97
+ ```
98
+ $ madman serve --help
99
+ Run a webserver and serve the markdown file as HTML
100
+
101
+ Usage:
102
+ madman serve INFILE [--port N --bind ADDRESS --rtl --github]
103
+ madman serve (-h|--help|--version)
104
+
105
+ Options:
106
+ --github
107
+ Render using the GitHub API
108
+ Requires setting the GITHUB_ACCESS_TOKEN environment variable
109
+
110
+ --rtl
111
+ Render text Right to Left.
112
+
113
+ -p --port N
114
+ Set server port [default: 3000]
115
+
116
+ -b --bind ADDRESS
117
+ Set server listen address [default: 0.0.0.0]
118
+
119
+ -h --help
120
+ Show this help
121
+
122
+ Parameters:
123
+ INFILE
124
+ The input markdown file
125
+
126
+ Environment Variables:
127
+ GITHUB_ACCESS_TOKEN
128
+ Your GitHub API access token
129
+ Generate one here: https://github.com/settings/tokens
130
+
131
+ Examples:
132
+ madman serve README.md
133
+ madman serve README.md --github
134
+ madman serve README.md -p4000 --rtl
135
+ ```
136
+
137
+ ---
138
+
139
+ <!-- usage -->
data/bin/madman CHANGED
@@ -3,8 +3,7 @@ require 'mister_bin'
3
3
  require 'madman/version'
4
4
 
5
5
  runner = MisterBin::Runner.new 'madman', basedir: __dir__,
6
- header: "Madman #{Madman::VERSION}"
7
-
6
+ version: Madman::VERSION
8
7
 
9
8
  begin
10
9
  exit runner.run ARGV
data/bin/madman-render.rb CHANGED
@@ -1,25 +1,36 @@
1
1
  require 'madman'
2
- require 'madman/version'
3
-
4
- version Madman::VERSION
5
2
 
6
3
  help "Render markdown to HTML"
7
4
 
8
- usage "madman render INFILE [OUTFILE] [--rtl]"
5
+ usage "madman render INFILE [OUTFILE] [--rtl --github]"
9
6
  usage "madman render (-h|--help|--version)"
10
7
 
11
- option "--rtl", "Render text Right-to-Left"
8
+ option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
9
+ option "--rtl", "Render text Right to Left"
12
10
 
13
11
  param "INFILE", "The input markdown file"
14
- param "OUTFILE", "The output HTML file. If not provided, the input filename will be used with .html extension"
12
+ param "OUTFILE", "The output HTML file\nIf not provided, the input filename will be used with .html extension"
13
+
14
+ environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nGenerate one here: https://github.com/settings/tokens"
15
15
 
16
16
  example "madman render README.md"
17
+ example "madman render README.md --github"
17
18
  example "madman render README.md out.html --rtl"
18
19
 
19
20
  action do |args|
20
21
  infile = args['INFILE']
21
22
  outfile = args['OUTFILE'] || "#{infile}.html"
22
- doc = Madman::Document.from_file infile, rtl: args['--rtl']
23
+ renderer = args['--github'] ? :github : :default
24
+
25
+
26
+ opts = {
27
+ rtl: args['--rtl'],
28
+ renderer: renderer
29
+ }
30
+
31
+ doc = Madman::Document.from_file infile, opts
32
+
33
+ say "Rendering using the #{renderer} renderer"
23
34
  doc.render outfile
24
35
  say "Saved !txtgrn!#{outfile}"
25
36
  end
data/bin/madman-serve.rb CHANGED
@@ -1,20 +1,21 @@
1
1
  require 'madman'
2
- require 'madman/version'
3
-
4
- version Madman::VERSION
5
2
 
6
3
  help "Run a webserver and serve the markdown file as HTML"
7
4
 
8
- usage "madman serve INFILE [--port N --bind ADDRESS --rtl]"
5
+ usage "madman serve INFILE [--port N --bind ADDRESS --rtl --github]"
9
6
  usage "madman serve (-h|--help|--version)"
10
7
 
11
- option " --rtl", "Render text Right-to-Left"
8
+ option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
9
+ option "--rtl", "Render text Right to Left."
12
10
  option "-p --port N", "Set server port [default: 3000]"
13
11
  option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
14
12
 
15
13
  param "INFILE", "The input markdown file"
16
14
 
15
+ environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nGenerate one here: https://github.com/settings/tokens"
16
+
17
17
  example "madman serve README.md"
18
+ example "madman serve README.md --github"
18
19
  example "madman serve README.md -p4000 --rtl"
19
20
 
20
21
  action do |args|
@@ -25,6 +26,8 @@ action do |args|
25
26
  rtl: args['--rtl']
26
27
  }
27
28
 
29
+ opts[:renderer] = :github if args['--github']
30
+
28
31
  Madman::Server.options opts
29
32
  Madman::Server.run!
30
33
  end
@@ -1,13 +1,20 @@
1
1
  module Madman
2
2
  class Document
3
- attr_reader :text, :opts
3
+ attr_reader :text, :options
4
4
 
5
- def self.from_file(file, opts={})
5
+ def self.from_file(file, opts=nil)
6
+ opts ||= {}
6
7
  new File.read(file), opts.merge({ filename: file })
7
8
  end
8
9
 
9
- def initialize(text, opts)
10
- @text, @opts = text, opts
10
+ def initialize(text, options=nil)
11
+ @text = text
12
+ options ||= {}
13
+ @options = default_options.merge options
14
+ end
15
+
16
+ def set(new_opts)
17
+ @options = options.merge new_opts
11
18
  end
12
19
 
13
20
  def render(outfile)
@@ -16,20 +23,28 @@ module Madman
16
23
 
17
24
  def to_html
18
25
  html = template
19
- content = CommonMarker.render_html text, :DEFAULT, [:table]
26
+ content = renderer.render text
20
27
 
21
28
  replacements = {
22
29
  content: content,
23
30
  inline_css: css,
24
31
  body_attributes: ''
25
32
  }
26
- replacements[:body_attributes] = "dir='rtl'" if opts[:rtl]
33
+ replacements[:body_attributes] = "dir='rtl'" if options[:rtl]
27
34
 
28
35
  html %= replacements
29
36
  end
30
37
 
31
38
  private
32
39
 
40
+ def renderer
41
+ Renderers.available_renderers[options[:renderer]]
42
+ end
43
+
44
+ def default_options
45
+ { renderer: :default }
46
+ end
47
+
33
48
  def template
34
49
  @template ||= File.read template_file
35
50
  end
@@ -0,0 +1,9 @@
1
+ module Madman
2
+ module Renderers
3
+ class Default
4
+ def self.render(text, opts={})
5
+ CommonMarker.render_html text, :DEFAULT, [:table]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Madman
2
+ module Renderers
3
+ class GitHub
4
+ def self.render(text, opts={})
5
+ self.client.markdown text
6
+ end
7
+
8
+ private
9
+
10
+ def self.client
11
+ Octokit::Client.new access_token: access_token
12
+ end
13
+
14
+ def self.access_token
15
+ ENV['GITHUB_ACCESS_TOKEN'] or raise ArgumentError, "Please set GITHUB_ACCESS_TOKEN"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'madman/renderers/default'
2
+ require 'madman/renderers/github'
3
+
4
+ module Madman
5
+ module Renderers
6
+ def self.available_renderers
7
+ {
8
+ default: Renderers::Default,
9
+ github: Renderers::GitHub,
10
+ }
11
+ end
12
+ end
13
+ end
data/lib/madman/server.rb CHANGED
@@ -6,10 +6,15 @@ module Madman
6
6
  @@options = opts
7
7
  set :bind, @@options[:bind]
8
8
  set :port, @@options[:port]
9
+ set :public_folder, File.expand_path(File.dirname(@@options[:file]))
9
10
  end
10
11
 
11
12
  def doc
12
- Madman::Document.from_file @@options[:file], rtl: @@options[:rtl]
13
+ doc_options = {
14
+ rtl: @@options[:rtl],
15
+ renderer: (@@options[:renderer] || :default)
16
+ }
17
+ Madman::Document.from_file @@options[:file], doc_options
13
18
  end
14
19
 
15
20
  get '/' do
@@ -1,3 +1,3 @@
1
1
  module Madman
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/madman.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'commonmarker'
2
+ require 'octokit'
2
3
  require 'sinatra/base'
3
4
 
4
5
  require 'madman/document'
5
6
  require 'madman/server'
7
+ require 'madman/renderers'
8
+
9
+ require 'byebug' if ENV['BYEBUG']
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.0.1
4
+ version: 0.1.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-18 00:00:00.000000000 Z
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mister_bin
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: octokit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.9'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rack-test
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -235,6 +249,9 @@ files:
235
249
  - bin/madman-serve.rb
236
250
  - lib/madman.rb
237
251
  - lib/madman/document.rb
252
+ - lib/madman/renderers.rb
253
+ - lib/madman/renderers/default.rb
254
+ - lib/madman/renderers/github.rb
238
255
  - lib/madman/server.rb
239
256
  - lib/madman/version.rb
240
257
  - lib/templates/css.css