madness 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/app/public/css/main.css +21 -21
- data/app/public/css/main.css.map +2 -2
- data/app/styles/_manifest.scss +3 -1
- data/lib/madness.rb +2 -0
- data/lib/madness/breadcrumbs.rb +3 -0
- data/lib/madness/command_line.rb +15 -4
- data/lib/madness/document.rb +22 -0
- data/lib/madness/navigation.rb +29 -9
- data/lib/madness/server.rb +3 -0
- data/lib/madness/server_base.rb +19 -5
- data/lib/madness/server_helper.rb +3 -0
- data/lib/madness/settings.rb +10 -0
- data/lib/madness/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 522b6812a30a5263c3860e0dd78d9d516d75142e
|
4
|
+
data.tar.gz: dec8f6ee48993a3f02318bd43f3469897544c72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23ac24a8659d80b208020c332c32166d1066874392dd1a1ecf5ff8619a1610caf3832f122b5d40c1c7cd9a58db195529e3585ae16b6b9fd2a30126882720685
|
7
|
+
data.tar.gz: e757685713c3379b1cf91f2cb55721b536fb2bb76434a451cf8be4fd3659674cf4066b15173e5cf25562849c40511db0110f111d18f6080294625776185686ce
|
data/README.md
CHANGED
@@ -82,6 +82,28 @@ line_numbers: true
|
|
82
82
|
```
|
83
83
|
|
84
84
|
|
85
|
+
Tips
|
86
|
+
--------------------------------------------------
|
87
|
+
|
88
|
+
**Automatic H1**
|
89
|
+
If your markdown document does not start with a level 1 heading, it
|
90
|
+
will be automatically added based on the file name.
|
91
|
+
|
92
|
+
**Hidden Directories**
|
93
|
+
Directories that begin with an underscore will not be displayed in the
|
94
|
+
navigation.
|
95
|
+
|
96
|
+
**Images and Static Files**
|
97
|
+
Your markdown directory can have a `public` folder. Anything in it
|
98
|
+
will be served as is. For example, if you have `public/images/ok.png`
|
99
|
+
you can access it from your markdown file by typing:
|
100
|
+
|
101
|
+
```markdown
|
102
|
+
![alt text](/images/ok.png)
|
103
|
+
```
|
104
|
+
|
105
|
+
|
85
106
|
---
|
86
107
|
|
87
108
|
[Screenshot]: https://raw.githubusercontent.com/DannyBen/madness/master/screenshot.png
|
109
|
+
|
data/app/public/css/main.css
CHANGED
@@ -1,24 +1,3 @@
|
|
1
|
-
* {
|
2
|
-
box-sizing: border-box; }
|
3
|
-
|
4
|
-
p {
|
5
|
-
margin-top: 0;
|
6
|
-
margin-bottom: 10px; }
|
7
|
-
|
8
|
-
blockquote {
|
9
|
-
margin: 0;
|
10
|
-
padding: 0 15px;
|
11
|
-
color: #777;
|
12
|
-
border-left: 4px solid #ddd; }
|
13
|
-
blockquote > :first-child {
|
14
|
-
margin-top: 0; }
|
15
|
-
blockquote > :last-child {
|
16
|
-
margin-bottom: 0; }
|
17
|
-
|
18
|
-
p, blockquote, ul, ol, dl, table, pre {
|
19
|
-
margin-top: 0;
|
20
|
-
margin-bottom: 16px; }
|
21
|
-
|
22
1
|
body {
|
23
2
|
-ms-text-size-adjust: 100%;
|
24
3
|
-webkit-text-size-adjust: 100%;
|
@@ -218,6 +197,27 @@ kbd {
|
|
218
197
|
border-radius: 3px;
|
219
198
|
box-shadow: inset 0 -1px 0 #bbb; }
|
220
199
|
|
200
|
+
* {
|
201
|
+
box-sizing: border-box; }
|
202
|
+
|
203
|
+
p {
|
204
|
+
margin-top: 0;
|
205
|
+
margin-bottom: 10px; }
|
206
|
+
|
207
|
+
blockquote {
|
208
|
+
margin: 0;
|
209
|
+
padding: 0 15px;
|
210
|
+
color: #777;
|
211
|
+
border-left: 4px solid #ddd; }
|
212
|
+
blockquote > :first-child {
|
213
|
+
margin-top: 0; }
|
214
|
+
blockquote > :last-child {
|
215
|
+
margin-bottom: 0; }
|
216
|
+
|
217
|
+
p, blockquote, ul, ol, dl, table, pre {
|
218
|
+
margin-top: 0;
|
219
|
+
margin-bottom: 16px; }
|
220
|
+
|
221
221
|
body {
|
222
222
|
max-width: 1300px;
|
223
223
|
margin: 0 auto; }
|
data/app/public/css/main.css.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"mappings": "AAAA,
|
4
|
-
"sources": ["../../styles/
|
3
|
+
"mappings": "AAAA,IAAK;EACH,oBAAoB,EAAE,IAAI;EAC1B,wBAAwB,EAAE,IAAI;EAC9B,KAAK,EAAE,IAAI;EACX,WAAW,EAAE,8HAA8H;EAC3I,SAAS,EAAE,IAAI;EACf,WAAW,EAAE,GAAG;EAChB,SAAS,EAAE,UAAU;;AAGvB,eAAgB;EACd,WAAW,EAAE,MAAM;;AAGrB,sBAAuB;EACrB,UAAU,EAAE,GAAG;EACf,aAAa,EAAE,IAAI;EACnB,WAAW,EAAE,IAAI;EACjB,WAAW,EAAE,GAAG;;AAGlB,EAAG;EACD,MAAM,EAAE,QAAQ;EAChB,cAAc,EAAE,KAAK;EACrB,SAAS,EAAE,MAAM;EACjB,WAAW,EAAE,GAAG;EAChB,aAAa,EAAE,cAAc;;AAG/B,EAAG;EACD,cAAc,EAAE,KAAK;EACrB,SAAS,EAAE,MAAM;EACjB,WAAW,EAAE,KAAK;EAClB,aAAa,EAAE,cAAc;;AAG/B,EAAG;EACD,SAAS,EAAE,KAAK;EAChB,WAAW,EAAE,IAAI;;AAGnB,EAAG;EACD,SAAS,EAAE,MAAM;;AAGnB,EAAG;EACD,SAAS,EAAE,GAAG;;AAGhB,EAAG;EACD,SAAS,EAAE,GAAG;EACd,KAAK,EAAE,IAAI;;AAGb,cAAe;EACb,WAAW,EAAE,oBAAoB;EACjC,SAAS,EAAE,GAAG;;AAGhB,cAAe;EACb,WAAW,EAAE,sDAAsD;;AC5DrE,KAAM;EACJ,cAAc,EAAE,CAAC;EACjB,eAAe,EAAE,QAAQ;EAEzB,OAAO,EAAE,KAA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AAa,EAAE,GAAG;IALlB,2BAAQ;MACN,UAAU,EAAE,OAAO;;AASzB,mBAAoB;EAClB,KAAK,EAAE,GAAG;;AAEZ,yBAA0B;EACxB,UAAU,EAAE,IAAI;EAChB,qBAAqB,EAAE,GAAG",
|
4
|
+
"sources": ["../../styles/_typography.scss","../../styles/_table.scss","../../styles/_anchor.scss","../../styles/_list.scss","../../styles/_code.scss","../../styles/_coderay.scss","../../styles/_image.scss","../../styles/_line.scss","../../styles/_keyboard.scss","../../styles/_general.scss","../../styles/main.scss"],
|
5
5
|
"names": [],
|
6
6
|
"file": "main.css"
|
7
7
|
}
|
data/app/styles/_manifest.scss
CHANGED
data/lib/madness.rb
CHANGED
@@ -10,6 +10,7 @@ require "sinatra/reloader"
|
|
10
10
|
require 'sass/plugin/rack'
|
11
11
|
require 'docopt'
|
12
12
|
require 'colsole'
|
13
|
+
require 'rack/contrib/try_static'
|
13
14
|
|
14
15
|
require 'madness/version'
|
15
16
|
require 'madness/settings'
|
@@ -20,3 +21,4 @@ require 'madness/document'
|
|
20
21
|
require 'madness/navigation'
|
21
22
|
require 'madness/breadcrumbs'
|
22
23
|
require 'madness/command_line'
|
24
|
+
|
data/lib/madness/breadcrumbs.rb
CHANGED
data/lib/madness/command_line.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Madness
|
2
|
+
|
3
|
+
# Handle command line execution. Used by bin/madness.
|
2
4
|
class CommandLine
|
3
5
|
include Singleton
|
4
6
|
include Colsole
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
# Without any argument, we run the server in the current directory.
|
9
|
+
# Otherwise, we will set some options before executing.
|
9
10
|
def execute(argv=[])
|
10
11
|
if argv.empty?
|
11
12
|
launch_server
|
@@ -16,6 +17,8 @@ module Madness
|
|
16
17
|
|
17
18
|
private
|
18
19
|
|
20
|
+
# Execute the docopt engine to parse the options and then launch the
|
21
|
+
# server.
|
19
22
|
def launch_server_with_options(argv)
|
20
23
|
doc = File.read File.expand_path('docopt.txt', __dir__)
|
21
24
|
begin
|
@@ -27,16 +30,22 @@ module Madness
|
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
33
|
+
# Launch the server, but not before doing some checks and making sure
|
34
|
+
# we ask it to "prepare". This will set the server options such as port
|
35
|
+
# and static files folder.
|
30
36
|
def launch_server
|
31
37
|
unless File.directory? config.path
|
32
|
-
puts "Invalid path (#{config.path})"
|
38
|
+
STDERR.puts "Invalid path (#{config.path})"
|
33
39
|
return
|
34
40
|
end
|
35
41
|
|
36
42
|
show_status
|
43
|
+
Server.prepare
|
37
44
|
Server.run!
|
38
45
|
end
|
39
46
|
|
47
|
+
# Get the arguments as provided by docopt, and set them to our own
|
48
|
+
# config object.
|
40
49
|
def set_config(args)
|
41
50
|
config.path = args['PATH'] if args['PATH']
|
42
51
|
config.port = args['--port'] if args['--port']
|
@@ -46,6 +55,8 @@ module Madness
|
|
46
55
|
config.line_numbers = false if args['--no-line-numbers']
|
47
56
|
end
|
48
57
|
|
58
|
+
# Say hello to everybody when the server starts, showing the known
|
59
|
+
# config.
|
49
60
|
def show_status
|
50
61
|
say_status :start, 'the madness'
|
51
62
|
say_status :listen, "#{config.bind}:#{config.port}", :txtblu
|
data/lib/madness/document.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
module Madness
|
2
|
+
|
3
|
+
# Handle a single markdown document.
|
2
4
|
class Document
|
3
5
|
include ServerHelper
|
4
6
|
|
5
7
|
attr_reader :file, :dir, :path, :type
|
6
8
|
|
9
|
+
# At initialization, we handle three file "types":
|
10
|
+
# :readme - in case the path is a directory, then the only file we
|
11
|
+
# MAY show, is the README.md in it
|
12
|
+
# :file - in case the path is a *.md file
|
13
|
+
# :empty - in any other case, we don't know.
|
7
14
|
def initialize(path)
|
8
15
|
@path = path
|
9
16
|
|
@@ -24,10 +31,12 @@ module Madness
|
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
34
|
+
# Return the HTML for that document
|
27
35
|
def content
|
28
36
|
@content ||= content!
|
29
37
|
end
|
30
38
|
|
39
|
+
# Return the HTML for that document, force re-read.
|
31
40
|
def content!
|
32
41
|
if File.exist?(file)
|
33
42
|
html = markdown_to_html html
|
@@ -37,6 +46,7 @@ module Madness
|
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
49
|
+
# Return a reasonable HTML title for the file or directory
|
40
50
|
def title
|
41
51
|
if file =~ /README.md/
|
42
52
|
result = File.basename File.dirname(file)
|
@@ -48,6 +58,9 @@ module Madness
|
|
48
58
|
|
49
59
|
private
|
50
60
|
|
61
|
+
# Convert markdown to HTML, wit hsome additional processing:
|
62
|
+
# 1. Syntax highilghting
|
63
|
+
# 2. Prepend H1 if needed
|
51
64
|
def markdown_to_html(html)
|
52
65
|
html = RDiscount.new(File.read file).to_html
|
53
66
|
html = syntax_highlight(html) if config.highlighter
|
@@ -55,6 +68,7 @@ module Madness
|
|
55
68
|
html
|
56
69
|
end
|
57
70
|
|
71
|
+
# If the document does not start with an H1 tag, add it.
|
58
72
|
def prepend_h1(html)
|
59
73
|
unless html[0..3] == "<h1>"
|
60
74
|
html = "<h1>#{title}</h1>\n#{html}"
|
@@ -62,6 +76,14 @@ module Madness
|
|
62
76
|
html
|
63
77
|
end
|
64
78
|
|
79
|
+
# Apply syntax highlighting with CodeRay. This will parse for any
|
80
|
+
# <code class='LANG'> sections in the HTML, pass it to CodeRay for
|
81
|
+
# highlighting.
|
82
|
+
# Since CodeRay adds another HTML escaping, on top of what RDiscount
|
83
|
+
# does, we unescape it before passing it to CodeRay.
|
84
|
+
#
|
85
|
+
# Open StackOverflow question:
|
86
|
+
# http://stackoverflow.com/questions/37771279/prevent-double-escaping-with-coderay-and-rdiscount
|
65
87
|
def syntax_highlight(html)
|
66
88
|
line_numbers = config.line_numbers ? :table : nil
|
67
89
|
opts = { css: :style, wrap: nil, line_numbers: line_numbers }
|
data/lib/madness/navigation.rb
CHANGED
@@ -1,29 +1,49 @@
|
|
1
1
|
module Madness
|
2
|
+
# Handle the navigation links for a given directory
|
2
3
|
class Navigation
|
3
4
|
include ServerHelper
|
4
5
|
|
5
6
|
attr_reader :links, :caption
|
6
7
|
|
7
8
|
def initialize(dir)
|
8
|
-
|
9
|
-
|
9
|
+
@links = make_links dir
|
10
|
+
@caption = File.basename(dir) unless dir == docroot
|
11
|
+
end
|
10
12
|
|
11
|
-
|
13
|
+
private
|
12
14
|
|
13
|
-
|
15
|
+
# Prepare a list of links from all the accepted items in the directory
|
16
|
+
def make_links(dir)
|
17
|
+
files = get_files dir
|
18
|
+
dirs = get_dirs dir
|
14
19
|
|
15
|
-
|
20
|
+
links = []
|
16
21
|
|
17
22
|
dirs.sort.each do |item|
|
18
|
-
|
23
|
+
links.push link(item, :dir)
|
19
24
|
end
|
20
25
|
|
21
|
-
files.
|
22
|
-
|
26
|
+
files.each do |item|
|
27
|
+
links.push link(item, :file)
|
23
28
|
end
|
29
|
+
|
30
|
+
links
|
24
31
|
end
|
25
32
|
|
26
|
-
|
33
|
+
def get_files(dir)
|
34
|
+
files = Dir["#{dir}/*.md"].map { |f| f.sub(/\.md$/, '') }
|
35
|
+
files.reject! { |f| File.basename(f) == 'README' }
|
36
|
+
files.sort
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_dirs(dir)
|
40
|
+
dirs = Dir["#{dir}/*"].select { |f| File.directory? f }
|
41
|
+
dirs.reject! do |f|
|
42
|
+
basename = File.basename(f)
|
43
|
+
basename[0] == '_' || basename == 'public'
|
44
|
+
end
|
45
|
+
dirs
|
46
|
+
end
|
27
47
|
|
28
48
|
def link(item, type)
|
29
49
|
OpenStruct.new({
|
data/lib/madness/server.rb
CHANGED
data/lib/madness/server_base.rb
CHANGED
@@ -1,22 +1,36 @@
|
|
1
1
|
|
2
2
|
module Madness
|
3
3
|
|
4
|
+
# The base class for the sinatra server.
|
5
|
+
# Initialize what we can here, but since there are values that will
|
6
|
+
# become known only later, the #prepare method is provided.
|
4
7
|
class ServerBase < Sinatra::Application
|
5
8
|
helpers ServerHelper
|
6
9
|
|
7
|
-
config = Settings.instance
|
8
|
-
|
9
10
|
Sass::Plugin.options[:template_location] = 'app/styles'
|
10
11
|
Sass::Plugin.options[:css_location] = 'app/public/css'
|
11
12
|
Slim::Engine.set_options pretty: true
|
12
13
|
|
13
14
|
use Sass::Plugin::Rack
|
14
|
-
|
15
|
-
set :bind, config.bind
|
16
|
-
set :port, config.port
|
15
|
+
|
17
16
|
set :root, File.expand_path('../../', __dir__)
|
18
17
|
set :views, File.expand_path('../../app/views', __dir__)
|
19
18
|
set :public_folder, File.expand_path('../../app/public', __dir__)
|
19
|
+
|
20
|
+
# Since we cannot use any config values in the main body of the class,
|
21
|
+
# since they will be updated later, we need to set anything that relys
|
22
|
+
# on the config values just before running the server.
|
23
|
+
# The CommandLine class and the test suite should both call
|
24
|
+
# `Server.prepare` before calling Server.run!
|
25
|
+
def self.prepare
|
26
|
+
use Rack::TryStatic, :root => "#{config.path}/public/", :urls => %w[/]
|
27
|
+
set :bind, config.bind
|
28
|
+
set :port, config.port
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.config
|
32
|
+
Settings.instance
|
33
|
+
end
|
20
34
|
end
|
21
35
|
|
22
36
|
end
|
data/lib/madness/settings.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module Madness
|
2
|
+
|
3
|
+
# Handle teh configuration options
|
4
|
+
# Each configuration option has three sources
|
5
|
+
# 1. The default value
|
6
|
+
# 2. The setting as provided in the ./.madness.yml
|
7
|
+
# 3. Any override provided later (for example, by the CommandLine
|
8
|
+
# class)
|
2
9
|
class Settings
|
3
10
|
include Singleton
|
4
11
|
|
@@ -9,6 +16,8 @@ module Madness
|
|
9
16
|
reset
|
10
17
|
end
|
11
18
|
|
19
|
+
# Force reload of the config file, set defaults, and then read from
|
20
|
+
# file.
|
12
21
|
def reset
|
13
22
|
@config_file = nil
|
14
23
|
set_defaults
|
@@ -51,5 +60,6 @@ module Madness
|
|
51
60
|
{}
|
52
61
|
end
|
53
62
|
end
|
63
|
+
|
54
64
|
end
|
55
65
|
end
|
data/lib/madness/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.7
|
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: 2016-06-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-contrib
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: slim
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|