madness 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84b40224e178737a2b80bbdac62d8c1937f5abff7a5cbc0a228858280f299459
4
- data.tar.gz: 7e9f72bebf1c17373540df77b5aa222bfd461d7cd324f9a25a213974641e1f4a
3
+ metadata.gz: 89018d212a6eb10fa20bcbf6874d00201639f636b3f015d1d091cef82fb0cc84
4
+ data.tar.gz: 2b0e17b9b9802d0ad2d0dd92dd3e35ddd28bfbf9b4a79f9347b733d7d8feb520
5
5
  SHA512:
6
- metadata.gz: ad23d7559298ec2b05087aae493fcfbfb485b01d90c6849da53f74414c67804aca70e963b3b6241718170e0618f9125e9705e564b0da75f6789586f2e9f33d53
7
- data.tar.gz: 0b4ea8fa485d52a2b1cc05d7d5989c10b2855da4708c94393543a50efcfa4e0c1d58c16a12798b7db1700098f4aa19160d43836ca70852c31e5317df2b3cba3e
6
+ metadata.gz: f6d63da556f0a76366ca5dbbff71c2e488d04bfec985a3d4c388ea51b7dbb51ddf3f643701d96e4cfbdea1965e2bb71681e3cec84b6b2644ed73262f1bc72669
7
+ data.tar.gz: 050aa5976b73a39cffcf0d1ef4d56887952253641853c5b1ec2d6960aad7cc5276939692a1f5adce042b42519a0a57c9b33390c8ea3dcefea69ef46af249ef4a
data/README.md CHANGED
@@ -1,13 +1,10 @@
1
1
  Madness - Instant Markdown Server
2
2
  ==================================================
3
3
 
4
- [![Gem](https://img.shields.io/gem/v/madness.svg?style=flat-square)](https://rubygems.org/gems/madness)
5
- [![Downloads](https://img.shields.io/gem/dt/madness.svg?style=flat-square)](https://rubygems.org/gems/madness)
6
- [![Build](https://img.shields.io/travis/DannyBen/madness.svg?style=flat-square)](https://travis-ci.org/DannyBen/madness)
7
- [![Dependencies](https://img.shields.io/gemnasium/DannyBen/madness.svg?style=flat-square)](https://gemnasium.com/DannyBen/madness)
8
- [![Code Quality](https://img.shields.io/codacy/grade/794c32ee5f8743c3a835091efbc09068.svg?style=flat-square)](https://www.codacy.com/app/db/madness)
9
- [![Maintainability](https://img.shields.io/codeclimate/maintainability/DannyBen/madness.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/madness)
10
- [![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/madness.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/madness)
4
+ [![Gem Version](https://badge.fury.io/rb/madness.svg)](https://badge.fury.io/rb/madness)
5
+ [![Build Status](https://travis-ci.com/DannyBen/madness.svg?branch=master)](https://travis-ci.com/DannyBen/madness)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/fa440dc4dbf895734d74/maintainability)](https://codeclimate.com/github/DannyBen/madness/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/fa440dc4dbf895734d74/test_coverage)](https://codeclimate.com/github/DannyBen/madness/test_coverage)
11
8
 
12
9
  ---
13
10
 
@@ -76,16 +73,15 @@ Example structure:
76
73
  ```
77
74
  ./
78
75
  ├── README.md
79
- ├── Code.md
80
- ├── Double Escape.md
76
+ ├── File.md
77
+ ├── Another File.md
81
78
  ├── File-with-Dashes.md
82
79
  ├── Folder
83
-    └── File.md
80
+ ├── File.md
81
+ │ └── image.png
84
82
  └── Another Folder
85
83
  ├── README.md
86
- ├── Headings.md
87
- ├── Images.md
88
- └── Lists.md
84
+ └── File.md
89
85
  ```
90
86
 
91
87
 
@@ -107,7 +103,6 @@ autoh1: true
107
103
  highlighter: true
108
104
  line_numbers: true
109
105
  index: false
110
- development: false
111
106
  ```
112
107
 
113
108
 
@@ -130,15 +125,32 @@ documents change or new documents are added.
130
125
  Images and Static Files
131
126
  --------------------------------------------------
132
127
 
133
- Your markdown directory can have a `public` folder. Anything in it
134
- will be served as is. For example, if you have `public/images/ok.png`
135
- you can access it from your markdown file by typing:
128
+ You can put images and any other asset file anywhere in your documentation
129
+ folder.
130
+
131
+ When linking to other pages or images in your documentation folder, simply
132
+ use the URL relative to the markdown file. Madness will convert these to be
133
+ relative to the docroot of the generated site.
134
+
135
+ This behavior mimics how GitHub is rendering markdown files.
136
+
137
+ For example, if you have a folder named `subfolder` that contains a
138
+ `README.md` and a `nice-picture.png`, showing it in your `README` is done by
139
+ this markdown:
136
140
 
137
141
  ```markdown
138
- ![alt text](/images/ok.png)
142
+ ![alt text](nice-picture.png)
143
+ ```
144
+
145
+ If you wish to link to images or pages in a different folder, simply specify
146
+ the path relative to the homepage:
147
+
148
+ ```
149
+ ![alt text](/images/nice-picture.png)
139
150
  ```
140
151
 
141
152
 
153
+
142
154
  Automatic H1
143
155
  --------------------------------------------------
144
156
 
@@ -154,44 +166,6 @@ navigation.
154
166
 
155
167
 
156
168
 
157
- Automatic GraphViz Dot Diagram Generation
158
- --------------------------------------------------
159
-
160
- This feature requires that you have GraphViz installed
161
- (`$ sudo apt install graphviz`).
162
-
163
- What you place `*.dot` files in the `_dot` folder (or subfolders), they
164
- can be accessed directly as an image in your Markdown files.
165
-
166
- In development mode, when such files are accessed, Madness will run the
167
- graphviz `dot` command and generate a respective image in the `public`
168
- folder.
169
-
170
- For example, if you have the following graphviz file:
171
-
172
- ```
173
- # _dot/diagrams/my_diagram.dot
174
- digraph {
175
- Hello -> World
176
- }
177
- ```
178
-
179
- You can access it from your markdown files like this:
180
-
181
- ```markdown
182
- !['alt text'](/diagrams/my_diagram.dot)
183
- ```
184
-
185
- This will work in one of two ways:
186
-
187
- 1. If the server is in development mode (`--development`), then it will
188
- create a `png` image in the public folder, and redirect to it.
189
- 2. If the server is in production mode, it will redirect to the
190
- (previously-generated-) `png` image in the public folder, meaning
191
- `public/diagrams/my_diagram.png`
192
-
193
-
194
-
195
169
  Docker Image
196
170
  --------------------------------------------------
197
171
 
@@ -216,3 +190,5 @@ For more information see:
216
190
  [screenshot]: https://raw.githubusercontent.com/DannyBen/madness/master/screenshot.png
217
191
  [dockerhub]: https://hub.docker.com/r/dannyben/madness/
218
192
  [dockerfile]: https://github.com/DannyBen/docker-madness
193
+
194
+
data/lib/madness.rb CHANGED
@@ -3,7 +3,7 @@ require 'singleton'
3
3
  require 'yaml'
4
4
 
5
5
  require 'slim'
6
- require 'rdiscount'
6
+ require 'commonmarker'
7
7
  require 'coderay'
8
8
  require 'sass'
9
9
  require 'sinatra/base'
@@ -13,6 +13,8 @@ require 'docopt'
13
13
  require 'colsole'
14
14
  require 'ferret'
15
15
 
16
+ require'byebug' if ENV['BYEBUG']
17
+
16
18
  require 'madness/version'
17
19
  require 'madness/try_static'
18
20
  require 'madness/settings'
@@ -52,14 +52,13 @@ module Madness
52
52
  config.highlighter = false if args['--no-syntax']
53
53
  config.line_numbers = false if args['--no-line-numbers']
54
54
  config.index = true if args['--index']
55
- config.development = true if args['--development']
56
55
  end
57
56
 
58
57
  # Say hello to everybody when the server starts, showing the known
59
58
  # config.
60
59
  def show_status
61
60
  say_status :start, 'the madness'
62
- say_status :env, config.development ? 'development' : 'production', :txtblu
61
+ say_status :env, Server.environment, :txtblu
63
62
  say_status :listen, "#{config.bind}:#{config.port}", :txtblu
64
63
  say_status :path, File.realpath(config.path), :txtblu
65
64
  say_status :use, config.filename if config.file_exist?
@@ -15,11 +15,6 @@ Options:
15
15
  -b, --bind <address>
16
16
  Set server listen address.
17
17
 
18
- --development
19
- Start the server in development mode. In this mode, dot diagrams are
20
- regenerated on each request, whereas in production mode (default), the
21
- diagrams are expected to already be generated in the public folder.
22
-
23
18
  --no-auto-h1
24
19
  By default, if a markdown document does not start with an H1 caption,
25
20
  it will be added automatically based on the file name. To disable this
@@ -41,6 +36,5 @@ Examples:
41
36
  madness
42
37
  madness docs
43
38
  madness docs --no-auto-h1 -p 4567
44
- madness docs --development
45
39
  madness --index --and-quit
46
40
 
@@ -56,13 +56,19 @@ module Madness
56
56
  result.tr '-', ' '
57
57
  end
58
58
 
59
+ def relative_dir
60
+ @relative_dir ||= dir[/#{docroot}\/(.*)/,1]
61
+ end
62
+
59
63
  private
60
64
 
61
65
  # Convert markdown to HTML, wit hsome additional processing:
62
66
  # 1. Syntax highilghting
63
67
  # 2. Prepend H1 if needed
64
68
  def markdown_to_html
65
- html = RDiscount.new(File.read file).to_html
69
+ doc = CommonMarker.render_doc(File.read file)
70
+ fix_relative_links doc if relative_dir
71
+ html = doc.to_html
66
72
  html = syntax_highlight(html) if config.highlighter
67
73
  html = prepend_h1(html) if config.autoh1
68
74
  html
@@ -87,12 +93,24 @@ module Madness
87
93
  def syntax_highlight(html)
88
94
  line_numbers = config.line_numbers ? :table : nil
89
95
  opts = { css: :style, wrap: nil, line_numbers: line_numbers }
90
- html.gsub(/\<code class="(.+?)"\>(.+?)\<\/code\>/m) do
96
+ html.gsub(/\<code class="language-(.+?)"\>(.+?)\<\/code\>/m) do
91
97
  lang, code = $1, $2
92
98
  code = CGI.unescapeHTML code
93
99
  CodeRay.scan(code, lang).html opts
94
100
  end
95
101
  end
102
+
103
+ def fix_relative_links(doc)
104
+ doc.walk do |node|
105
+ if [:link, :image].include? node.type
106
+ node.url = "/#{relative_dir}/#{node.url}" if relative? node.url
107
+ end
108
+ end
109
+ end
110
+
111
+ def relative?(link)
112
+ !(link.include? ':' or link[0] == '/')
113
+ end
96
114
  end
97
115
  end
98
116
 
@@ -45,7 +45,7 @@ module Madness
45
45
  dirs = Dir["#{dir}/*"].select { |f| File.directory? f }
46
46
  dirs.reject! do |f|
47
47
  basename = File.basename(f)
48
- basename[0] == '_' || basename == 'public'
48
+ basename[0] == '_'
49
49
  end
50
50
  dirs
51
51
  end
@@ -14,23 +14,6 @@ module Madness
14
14
  }
15
15
  end
16
16
 
17
- get '/*.dot' do
18
- splat = params[:splat].first
19
- dot = "_dot/#{splat}.dot"
20
- png = "public/#{splat}.png"
21
- out_dir = File.dirname png
22
-
23
- Dir.chdir docroot do
24
- if config.development and File.exist? dot
25
- FileUtils.mkdir_p out_dir unless Dir.exist? out_dir
26
- system %Q[dot "#{dot}" -Tpng -o "#{png}"]
27
- redirect to "#{splat}.png"
28
- else
29
- redirect to "#{splat}.png"
30
- end
31
- end
32
- end
33
-
34
17
  get '/*' do
35
18
  path = params[:splat].first
36
19
 
@@ -18,13 +18,18 @@ module Madness
18
18
  set :public_folder, File.expand_path('../../app/public', __dir__)
19
19
  set :server, :puma
20
20
 
21
+ configure :development do
22
+ register Sinatra::Reloader
23
+ also_reload "#{__dir__}/*.rb"
24
+ end
25
+
21
26
  # Since we cannot use any config values in the main body of the class,
22
27
  # since they will be updated later, we need to set anything that relys
23
28
  # on the config values just before running the server.
24
29
  # The CommandLine class and the test suite should both call
25
30
  # `Server.prepare` before calling Server.run!
26
31
  def self.prepare
27
- use TryStatic, root: "#{config.path}/public/", :urls => %w[/]
32
+ use TryStatic, root: "#{config.path}/", :urls => %w[/]
28
33
  set :bind, config.bind
29
34
  set :port, config.port
30
35
  end
@@ -10,7 +10,7 @@ module Madness
10
10
  include Singleton
11
11
 
12
12
  attr_accessor :port, :bind, :path, :autoh1,
13
- :highlighter, :line_numbers, :index, :development
13
+ :highlighter, :line_numbers, :index
14
14
 
15
15
  def initialize
16
16
  reset
@@ -42,7 +42,6 @@ module Madness
42
42
  self.highlighter = true
43
43
  self.line_numbers = true
44
44
  self.index = false
45
- self.development = false
46
45
  end
47
46
 
48
47
  def load_from_file
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.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-02-26 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rdiscount
70
+ name: commonmarker
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.2'
75
+ version: '0.17'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.2'
82
+ version: '0.17'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coderay
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '0.8'
187
+ version: '1.0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '0.8'
194
+ version: '1.0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: runfile-tasks
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: '9.1'
215
+ version: '10.0'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: '9.1'
222
+ version: '10.0'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: rspec
225
225
  requirement: !ruby/object:Gem::Requirement