madman 0.1.0 → 0.1.1

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: 1f05f3de9220613be599d500d333c17ee68b415a0f635fec5ce553a13f55a771
4
- data.tar.gz: 753a684bdc3de29b0e74e9a0868f260d7d7e736aa7f1d554e61f30414dd48620
3
+ metadata.gz: 47049987d632e62ea57b613c96170b95031acaa20b0390fdbf55d430d02c45ec
4
+ data.tar.gz: 53856412c8eb24b3ee946f24b554f80fa66aad09ee93bfe0b7ff0bc30ae90bb1
5
5
  SHA512:
6
- metadata.gz: a7d40a171015a9cf52c727e16069f37d96ecea0956d4c347d89e6d66bed3719e21827b78b66ed3bf8e4c15569cd15a8b545524bb6d10ba894daaf4acafac51ab
7
- data.tar.gz: 1e7c1342fa3c38c9996079d4eacb68814d5c660f82d541fd6354a31f994838026594b526306ca2f8179478d59fa192ddaa0c197be0e717890acae60d862c9131
6
+ metadata.gz: a2df596bb8c46b703e2e708199a945d95534bf5a294ce40580b3693bb7390087a46b1fce1e6dc31cc33adca2106fc36c64210e78a9d433597006463026af88a5
7
+ data.tar.gz: daca0122ce6af5f38f9aeeed54c87fc818784c93a29e89da89eb6babe71ab0f6359c9686a5a9889cb5a77e295ca373fdd99903df4bb55b0a74416257d6e496a4
data/README.md CHANGED
@@ -38,6 +38,7 @@ Key Features
38
38
  - [Planned] Table of Contents generation for a single file.
39
39
  - [Planned] Table of Contents generation for a folder of markdown files.
40
40
  - [Planned] Combine multiple markdown files to one.
41
+ - [Considered] Web server for an entire folder (like [Madness][1])
41
42
 
42
43
 
43
44
 
@@ -98,15 +99,15 @@ Examples:
98
99
  $ madman serve --help
99
100
  Run a webserver and serve the markdown file as HTML
100
101
 
102
+ This command will start a local server with two endpoints:
103
+ / will render the markdown with the default renderer
104
+ /github will render with the GitHub API
105
+
101
106
  Usage:
102
- madman serve INFILE [--port N --bind ADDRESS --rtl --github]
107
+ madman serve INFILE [--port N --bind ADDRESS --rtl]
103
108
  madman serve (-h|--help|--version)
104
109
 
105
110
  Options:
106
- --github
107
- Render using the GitHub API
108
- Requires setting the GITHUB_ACCESS_TOKEN environment variable
109
-
110
111
  --rtl
111
112
  Render text Right to Left.
112
113
 
@@ -126,14 +127,17 @@ Parameters:
126
127
  Environment Variables:
127
128
  GITHUB_ACCESS_TOKEN
128
129
  Your GitHub API access token
130
+ Required only if you wish to use the '/github' endpoint
129
131
  Generate one here: https://github.com/settings/tokens
130
132
 
131
133
  Examples:
132
134
  madman serve README.md
133
- madman serve README.md --github
134
135
  madman serve README.md -p4000 --rtl
135
136
  ```
136
137
 
137
138
  ---
138
139
 
139
- <!-- usage -->
140
+ <!-- usage -->
141
+
142
+
143
+ [1]: https://github.com/DannyBen/madness
data/bin/madman-render.rb CHANGED
@@ -22,16 +22,13 @@ action do |args|
22
22
  outfile = args['OUTFILE'] || "#{infile}.html"
23
23
  renderer = args['--github'] ? :github : :default
24
24
 
25
-
26
- opts = {
27
- rtl: args['--rtl'],
28
- renderer: renderer
29
- }
30
-
31
- doc = Madman::Document.from_file infile, opts
32
-
25
+ doc = Madman::Document.from_file infile
26
+ template = Madman::Template.new :default
27
+
33
28
  say "Rendering using the #{renderer} renderer"
34
- doc.render outfile
29
+ output = template.render doc.render(renderer)
30
+
31
+ File.write outfile, output
35
32
  say "Saved !txtgrn!#{outfile}"
36
33
  end
37
34
 
data/bin/madman-serve.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  require 'madman'
2
2
 
3
- help "Run a webserver and serve the markdown file as HTML"
3
+ summary "Run a webserver and serve the markdown file as HTML"
4
4
 
5
- usage "madman serve INFILE [--port N --bind ADDRESS --rtl --github]"
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 serve INFILE [--port N --bind ADDRESS --rtl]"
6
8
  usage "madman serve (-h|--help|--version)"
7
9
 
8
- option "--github", "Render using the GitHub API\nRequires setting the GITHUB_ACCESS_TOKEN environment variable"
9
10
  option "--rtl", "Render text Right to Left."
10
11
  option "-p --port N", "Set server port [default: 3000]"
11
12
  option "-b --bind ADDRESS", "Set server listen address [default: 0.0.0.0]"
12
13
 
13
14
  param "INFILE", "The input markdown file"
14
15
 
15
- environment "GITHUB_ACCESS_TOKEN", "Your GitHub API access token\nGenerate one here: https://github.com/settings/tokens"
16
+ 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
 
17
18
  example "madman serve README.md"
18
- example "madman serve README.md --github"
19
19
  example "madman serve README.md -p4000 --rtl"
20
20
 
21
21
  action do |args|
@@ -26,7 +26,11 @@ action do |args|
26
26
  rtl: args['--rtl']
27
27
  }
28
28
 
29
- opts[:renderer] = :github if args['--github']
29
+ say "Starting server at !undblu!localhost:#{opts[:port]}!txtrst!"
30
+ if ENV['GITHUB_ACCESS_TOKEN']
31
+ say "To view the GitHub API version go to !undblu!localhost:#{opts[:port]}/github!txtrst!"
32
+ end
33
+ say ''
30
34
 
31
35
  Madman::Server.options opts
32
36
  Madman::Server.run!
@@ -1,64 +1,24 @@
1
1
  module Madman
2
2
  class Document
3
- attr_reader :text, :options
3
+ attr_reader :text, :filename
4
4
 
5
- def self.from_file(file, opts=nil)
6
- opts ||= {}
7
- new File.read(file), opts.merge({ filename: file })
5
+ def self.from_file(file)
6
+ new File.read(file), file
8
7
  end
9
8
 
10
- def initialize(text, options=nil)
9
+ def initialize(text, filename=nil)
11
10
  @text = text
12
- options ||= {}
13
- @options = default_options.merge options
11
+ @filename = filename
14
12
  end
15
13
 
16
- def set(new_opts)
17
- @options = options.merge new_opts
18
- end
19
-
20
- def render(outfile)
21
- File.write outfile, to_html
22
- end
23
-
24
- def to_html
25
- html = template
26
- content = renderer.render text
27
-
28
- replacements = {
29
- content: content,
30
- inline_css: css,
31
- body_attributes: ''
32
- }
33
- replacements[:body_attributes] = "dir='rtl'" if options[:rtl]
34
-
35
- html %= replacements
14
+ def render(renderer=:default)
15
+ renderers[renderer].render text
36
16
  end
37
17
 
38
18
  private
39
19
 
40
- def renderer
41
- Renderers.available_renderers[options[:renderer]]
42
- end
43
-
44
- def default_options
45
- { renderer: :default }
46
- end
47
-
48
- def template
49
- @template ||= File.read template_file
50
- end
51
-
52
- def css
53
- @css ||= File.read css_file
54
- end
55
-
56
- def template_file
57
- @template_file ||= File.expand_path('../templates/template.html', __dir__)
58
- end
59
-
60
- def css_file
61
- @css_file ||= File.expand_path('../templates/css.css', __dir__)
20
+ def renderers
21
+ Renderers.available_renderers
62
22
  end
63
23
  end
64
24
  end
data/lib/madman/server.rb CHANGED
@@ -9,16 +9,22 @@ module Madman
9
9
  set :public_folder, File.expand_path(File.dirname(@@options[:file]))
10
10
  end
11
11
 
12
+ get '/' do
13
+ template.render doc.render
14
+ end
15
+
16
+ get '/github' do
17
+ template.render doc.render(:github)
18
+ end
19
+
20
+ private
21
+
12
22
  def doc
13
- doc_options = {
14
- rtl: @@options[:rtl],
15
- renderer: (@@options[:renderer] || :default)
16
- }
17
- Madman::Document.from_file @@options[:file], doc_options
23
+ Madman::Document.from_file @@options[:file]
18
24
  end
19
25
 
20
- get '/' do
21
- doc.to_html
26
+ def template
27
+ Madman::Template.new :default, rtl: @@options[:rtl]
22
28
  end
23
29
  end
24
30
  end
@@ -0,0 +1,45 @@
1
+ module Madman
2
+ class Template
3
+ attr_reader :file, :options, :content
4
+
5
+ def initialize(file, options=nil)
6
+ @file = file.is_a?(Symbol) ? presets[file] : file
7
+ @options = options || {}
8
+ end
9
+
10
+ def render(content)
11
+ @content = content
12
+ template % replacements
13
+ end
14
+
15
+ private
16
+
17
+ def replacements
18
+ result = {
19
+ content: content,
20
+ inline_css: css,
21
+ body_attributes: ''
22
+ }
23
+ result[:body_attributes] = "dir='rtl'" if options[:rtl]
24
+ result
25
+ end
26
+
27
+ def template
28
+ @template ||= File.read file
29
+ end
30
+
31
+ def css
32
+ @css ||= File.read css_file
33
+ end
34
+
35
+ def presets
36
+ {
37
+ default: File.expand_path('../templates/template.html', __dir__)
38
+ }
39
+ end
40
+
41
+ def css_file
42
+ @css_file ||= File.expand_path('../templates/css.css', __dir__)
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Madman
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/madman.rb CHANGED
@@ -3,7 +3,8 @@ require 'octokit'
3
3
  require 'sinatra/base'
4
4
 
5
5
  require 'madman/document'
6
- require 'madman/server'
7
6
  require 'madman/renderers'
7
+ require 'madman/server'
8
+ require 'madman/template'
8
9
 
9
10
  require 'byebug' if ENV['BYEBUG']
@@ -23,9 +23,9 @@
23
23
  }
24
24
  </style>
25
25
 
26
- <article class="markdown-body" %{body_attributes}>
27
- %{content}
28
- </article>
26
+ <article class="markdown-body" %{body_attributes}>
27
+ %{content}
28
+ </article>
29
29
 
30
30
  </body>
31
31
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -253,6 +253,7 @@ files:
253
253
  - lib/madman/renderers/default.rb
254
254
  - lib/madman/renderers/github.rb
255
255
  - lib/madman/server.rb
256
+ - lib/madman/template.rb
256
257
  - lib/madman/version.rb
257
258
  - lib/templates/css.css
258
259
  - lib/templates/template.html