madman 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/madman/server.rb CHANGED
@@ -1,30 +1,40 @@
1
1
  module Madman
2
- class Server < Sinatra::Base
3
- @@options = {}
4
-
5
- def self.options(opts)
6
- @@options = opts
7
- set :bind, @@options[:bind]
8
- set :port, @@options[:port]
9
- set :public_folder, File.expand_path(File.dirname(@@options[:file]))
2
+ class Server < ServerBase
3
+ set :public_folder, -> { File.expand_path(settings.dir) }
4
+
5
+ before do
6
+ @renderer = settings.respond_to?(:renderer) ? settings.renderer : :default
10
7
  end
11
8
 
12
- get '/' do
13
- template.render doc.render
9
+ get '/favicon.ico' do
10
+
14
11
  end
15
12
 
16
- get '/github' do
17
- template.render doc.render(:github)
13
+ get '/*' do
14
+ path = params[:splat].first
15
+
16
+ type, file = find_file(path)
17
+ redirect "#{path}/" if type == :dir and path[-1] != '/'
18
+
19
+ @doc = Document.from_file file
20
+ slim :template
18
21
  end
19
22
 
20
23
  private
21
24
 
22
- def doc
23
- Madman::Document.from_file @@options[:file]
24
- end
25
+ def find_file(path)
26
+ type = :file
27
+ file = File.expand_path path, settings.dir
28
+
29
+ if File.directory? file
30
+ type = path.empty? ? :root : :dir
31
+ file ="#{file}/README.md"
32
+ else
33
+ file ="#{file}.md"
34
+ end
25
35
 
26
- def template
27
- Madman::Template.new :default, rtl: @@options[:rtl]
36
+ [type, file]
28
37
  end
38
+
29
39
  end
30
40
  end
@@ -0,0 +1,12 @@
1
+ module Madman
2
+ class ServerBase < Sinatra::Base
3
+ set :views, File.expand_path('../views', __dir__)
4
+
5
+ Slim::Engine.set_options pretty: true
6
+
7
+ configure :development do
8
+ register Sinatra::Reloader
9
+ also_reload "#{__dir__}/*.rb"
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Madman
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/madman.rb CHANGED
@@ -1,10 +1,20 @@
1
1
  require 'commonmarker'
2
2
  require 'octokit'
3
3
  require 'sinatra/base'
4
+ require 'sinatra/reloader'
5
+ require 'slim'
6
+ require 'string-direction'
4
7
 
8
+ require 'madman/injector'
9
+
10
+ require 'madman/directory'
5
11
  require 'madman/document'
12
+ require 'madman/item'
6
13
  require 'madman/renderers'
14
+ require 'madman/navigation'
15
+
16
+ require 'madman/server_base'
17
+ require 'madman/preview_server'
7
18
  require 'madman/server'
8
- require 'madman/template'
9
19
 
10
20
  require 'byebug' if ENV['BYEBUG']
@@ -0,0 +1,25 @@
1
+ doctype html
2
+ html
3
+ head
4
+ meta name="viewport" content="width=device-width, initial-scale=1"
5
+
6
+ body
7
+ link href='https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' rel='stylesheet' type='text/css'
8
+
9
+ css:
10
+ .markdown-body {
11
+ box-sizing: border-box;
12
+ min-width: 200px;
13
+ max-width: 980px;
14
+ margin: 0 auto;
15
+ padding: 45px;
16
+ }
17
+
18
+ @media (max-width: 767px) {
19
+ .markdown-body {
20
+ padding: 15px;
21
+ }
22
+ }
23
+
24
+ article class="markdown-body" dir=('rtl' if @doc.rtl?)
25
+ == @doc.render @renderer
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-19 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commonmarker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.17'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: mister_bin
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puma
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.11'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: sinatra
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -39,33 +67,47 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '2.0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: commonmarker
70
+ name: sinatra-contrib
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '0.17'
75
+ version: '2.0'
48
76
  type: :runtime
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '0.17'
82
+ version: '2.0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: puma
84
+ name: slim
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '3.11'
89
+ version: '3.0'
62
90
  type: :runtime
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '3.11'
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: string-direction
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.2'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.2'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: byebug
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +136,20 @@ dependencies:
94
136
  - - "~>"
95
137
  - !ruby/object:Gem::Version
96
138
  version: '1.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: lp
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.0'
97
153
  - !ruby/object:Gem::Dependency
98
154
  name: octokit
99
155
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +294,8 @@ description: A command line utility for markdown fun
238
294
  email: db@dannyben.com
239
295
  executables:
240
296
  - madman
297
+ - madman-nav.rb
298
+ - madman-preview.rb
241
299
  - madman-render.rb
242
300
  - madman-serve.rb
243
301
  extensions: []
@@ -245,18 +303,24 @@ extra_rdoc_files: []
245
303
  files:
246
304
  - README.md
247
305
  - bin/madman
306
+ - bin/madman-nav.rb
307
+ - bin/madman-preview.rb
248
308
  - bin/madman-render.rb
249
309
  - bin/madman-serve.rb
250
310
  - lib/madman.rb
311
+ - lib/madman/directory.rb
251
312
  - lib/madman/document.rb
313
+ - lib/madman/injector.rb
314
+ - lib/madman/item.rb
315
+ - lib/madman/navigation.rb
316
+ - lib/madman/preview_server.rb
252
317
  - lib/madman/renderers.rb
253
318
  - lib/madman/renderers/default.rb
254
319
  - lib/madman/renderers/github.rb
255
320
  - lib/madman/server.rb
256
- - lib/madman/template.rb
321
+ - lib/madman/server_base.rb
257
322
  - lib/madman/version.rb
258
- - lib/templates/css.css
259
- - lib/templates/template.html
323
+ - lib/views/template.slim
260
324
  homepage: https://github.com/dannyben/madman
261
325
  licenses:
262
326
  - MIT
@@ -1,45 +0,0 @@
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