madness 0.5.5 → 0.5.6

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: b6f4a303db577b3f07559d4f2089503e17cdb89d83ef78792f4d6ed2e28a8386
4
- data.tar.gz: 6a37141d3f5835ce3b847a503de82e01c24dba20a65323f4cf1f9c30b5e5a0a6
3
+ metadata.gz: 61800bba372a7802c94d6e1b03ae7ae976a272bd46e70bcd6ee4c6840c0f99b9
4
+ data.tar.gz: 80b9b50292629189fb9592eff557a63aa23cf856541a174782dffc253f0c1adf
5
5
  SHA512:
6
- metadata.gz: feaa75621dcf013bac0e9b63feb9a4ae06a3a6e085e2534c71099ba69d9031a44253cd545e98b7b175a769628333c9c27144293efe364822be006658e2842643
7
- data.tar.gz: 5f37aada6e275be6836074ae155dfaaa8e6a4d1244600ed7e51faa62c33203fe3861b4b9963ad4c04ef2f19fb9f72de6ecb47844981dbf2d686b59513bd18643
6
+ metadata.gz: 7e25d76930f8ebad4bb54edeb033b0cd8fc1cd90c8455ebfbc534cd09df211c4f49b4ce616930ba2ca30dc9f7f8685f1bf12a1d541e43779071390f8fa1b0e50
7
+ data.tar.gz: fa5f24750e105497e026c1afe6d5ac0a5815e0db7aaf3c5aec97afbc6ac07044f6249e329b169292828543dfabe128ecb13a1862a63f6bb1a0b1a66461ff45b3
data/README.md CHANGED
@@ -30,7 +30,7 @@ Table of Contents
30
30
  * [Automatic H1](#automatic-h1)
31
31
  * [Table of Contents Generation](#table-of-contents-generation)
32
32
  * [Hidden Directories](#hidden-directories)
33
- * [Changing Theme](#changing-theme)
33
+ * [Customizing Theme](#customizing-theme)
34
34
  * [Docker Image](#docker-image)
35
35
 
36
36
 
@@ -53,11 +53,13 @@ searching for local, markdown based documentation directories.
53
53
  Feature Highlights
54
54
  --------------------------------------------------
55
55
 
56
- - Easy to use
57
- - Built in full text search
58
- - Compatible with how markdown files are displayed on GitHub andGitHub pages.
59
- - Configure with a configuration file or command arguments
60
- - Automatic generation of Table of Contents
56
+ - Easy to use.
57
+ - Built-in full text search.
58
+ - Compatible with how markdown files are displayed on GitHub and GitHub pages.
59
+ - Configure with a configuration file or command arguments.
60
+ - Fully customizable theme.
61
+ - Automatic generation of navigation sidebar.
62
+ - Automatic generation of Table of Contents.
61
63
 
62
64
 
63
65
 
@@ -95,7 +97,6 @@ Example structure:
95
97
  ├── README.md
96
98
  ├── File.md
97
99
  ├── Another File.md
98
- ├── File-with-Dashes.md
99
100
  ├── Folder
100
101
  │ ├── File.md
101
102
  │ └── image.png
@@ -125,6 +126,13 @@ highlighter: true
125
126
  line_numbers: true
126
127
  index: false
127
128
  toc: Table of Contents
129
+ theme: _theme
130
+ ```
131
+
132
+ For convenience, you can get a template config file by running:
133
+
134
+ ```shell
135
+ $ madness create config
128
136
  ```
129
137
 
130
138
 
@@ -194,18 +202,45 @@ numbers (`/^[a-z_\-0-9]+$/`) will not be displayed in the navigation.
194
202
 
195
203
 
196
204
 
197
- Changing Theme
205
+ Customizing Theme
198
206
  --------------------------------------------------
199
207
 
200
- To change the CSS of your documentation server:
208
+ There are two ways to change how Madness looks.
209
+
210
+
211
+ ### Option 1: Change CSS and HTML (Slim)
212
+
213
+ In order to have complete control over the CSS and generated HTML, you
214
+ can override the views and styles. Views are provided as Slim templates,
215
+ and CSS is provided as SCSS.
216
+
217
+ Madness comes with a command that copies the default theme to a folder of
218
+ your choice, where you can customize it to your taste. Run:
219
+
220
+ ```shell
221
+ $ madness create config my_theme
222
+ ```
223
+
224
+ Where `_theme` is the folder that will be created.
225
+
226
+ To use the created theme, simply run Madness with the `--theme my_theme`
227
+ option.
228
+
229
+ ```shell
230
+ $ madness --theme my_theme
231
+ ```
232
+
233
+
234
+ ### Option 2: Change CSS only
235
+
236
+ If you are looking to implement a more minor CSS change, follow these steps:
201
237
 
202
238
  - Create a directory named `css` in your root documentation directory.
203
239
  - Copy the [main.css][css] file to it.
204
240
  - Update it as you see fit.
205
241
 
206
242
  Note that this functionality is not guaranteed to stay as is in future
207
- versions of madness, since support for themes is still not yet fully
208
- implemented.
243
+ versions of madness.
209
244
 
210
245
 
211
246
 
@@ -234,4 +269,5 @@ For more information see:
234
269
  [dockerhub]: https://hub.docker.com/r/dannyben/madness/
235
270
  [dockerfile]: https://github.com/DannyBen/docker-madness
236
271
  [css]: app/public/css/main.css
272
+ [app]: app
237
273
 
data/lib/madness.rb CHANGED
@@ -31,5 +31,6 @@ require 'madness/server'
31
31
  require 'madness/server_base'
32
32
  require 'madness/settings'
33
33
  require 'madness/table_of_contents'
34
+ require 'madness/theme'
34
35
  require 'madness/version'
35
36
 
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Madness
2
4
 
3
5
  # Handle command line execution. Used by bin/madness.
@@ -5,28 +7,39 @@ module Madness
5
7
  include Singleton
6
8
  include Colsole
7
9
 
8
- # Launch the server
10
+ # Process ARGV by putting it through docopt
9
11
  def execute(argv=[])
10
- launch_server_with_options argv
11
- end
12
-
13
- private
14
-
15
- # Execute the docopt engine to parse the options and then launch the
16
- # server.
17
- def launch_server_with_options(argv)
18
12
  doc = File.read File.expand_path('docopt.txt', __dir__)
13
+
19
14
  begin
20
15
  args = Docopt.docopt(doc, argv: argv, version: VERSION)
21
- set_config args
22
- generate_stuff
23
- launch_server unless args['--and-quit']
24
-
16
+ handle args
25
17
  rescue Docopt::Exit => e
26
18
  puts e.message
27
19
  end
28
20
  end
29
21
 
22
+ private
23
+
24
+ # Separate between the two main modes: Create something, or launch
25
+ # the server.
26
+ def handle(args)
27
+ if args['create']
28
+ create_config if args['config']
29
+ create_theme(args['FOLDER']) if args['theme']
30
+ else
31
+ launch_server_with_options args
32
+ end
33
+ end
34
+
35
+ # Execute some pre-server-launch operations if needed, and execute
36
+ # the server.
37
+ def launch_server_with_options(args)
38
+ set_config args
39
+ generate_stuff
40
+ launch_server unless args['--and-quit']
41
+ end
42
+
30
43
  # Launch the server, but not before doing some checks and making sure
31
44
  # we ask it to "prepare". This will set the server options such as port
32
45
  # and static files folder.
@@ -44,16 +57,17 @@ module Madness
44
57
  # Get the arguments as provided by docopt, and set them to our own
45
58
  # config object.
46
59
  def set_config(args)
47
- config.path = args['PATH'] if args['PATH']
48
- config.port = args['--port'] if args['--port']
49
- config.bind = args['--bind'] if args['--bind']
50
- config.toc = args['--toc'] if args['--toc']
51
- config.auto_h1 = false if args['--no-auto-h1']
52
- config.auto_nav = false if args['--no-auto-nav']
53
- config.sidebar = false if args['--no-sidebar']
54
- config.highlighter = false if args['--no-syntax']
55
- config.line_numbers = false if args['--no-line-numbers']
56
- config.index = true if args['--index']
60
+ config.path = args['PATH'] if args['PATH']
61
+ config.port = args['--port'] if args['--port']
62
+ config.bind = args['--bind'] if args['--bind']
63
+ config.toc = args['--toc'] if args['--toc']
64
+ config.auto_h1 = false if args['--no-auto-h1']
65
+ config.auto_nav = false if args['--no-auto-nav']
66
+ config.sidebar = false if args['--no-sidebar']
67
+ config.highlighter = false if args['--no-syntax']
68
+ config.line_numbers = false if args['--no-line-numbers']
69
+ config.index = true if args['--index']
70
+ config.theme = File.expand_path(args['--theme'], config.path) if args['--theme']
57
71
  end
58
72
 
59
73
  # Generate index and toc, if requested by the user.
@@ -62,6 +76,26 @@ module Madness
62
76
  build_toc if config.toc
63
77
  end
64
78
 
79
+ # Create config
80
+ def create_config
81
+ if File.exist? config.filename
82
+ say "!txtred!Abort: config file #{config.filename} already exists"
83
+ else
84
+ FileUtils.cp File.expand_path('templates/madness.yml', __dir__), config.filename
85
+ say "!txtgrn!Created #{config.filename} config file"
86
+ end
87
+ end
88
+
89
+ # Create theme
90
+ def create_theme(path)
91
+ if Dir.exist? path
92
+ say "!txtred!Abort: folder #{path} already exists"
93
+ else
94
+ FileUtils.cp_r File.expand_path('../../app', __dir__), path
95
+ say "!txtgrn!Created #{path} theme folder"
96
+ end
97
+ end
98
+
65
99
  # Say hello to everybody when the server starts, showing the known
66
100
  # config.
67
101
  def show_status
@@ -70,7 +104,9 @@ module Madness
70
104
  say_status :listen, "#{config.bind}:#{config.port}", :txtblu
71
105
  say_status :path, File.realpath(config.path), :txtblu
72
106
  say_status :use, config.filename if config.file_exist?
73
- say "-" * 40
107
+ say_status :theme, config.theme, :txtblu if config.theme
108
+
109
+ say "-" * 60
74
110
  end
75
111
 
76
112
  # Build the search index
@@ -2,42 +2,67 @@ Madness
2
2
 
3
3
  Usage:
4
4
  madness [PATH] [options]
5
+ madness create config
6
+ madness create theme FOLDER
5
7
  madness (-h|--help|--version)
6
8
 
9
+ Subcommands:
10
+ create config
11
+ Initialize a new default .madness.yml config file.
12
+
13
+ create theme
14
+ Initialize a new theme folder, based on the default theme. You can then
15
+ customize it to your needs and use it with --theme.
16
+
7
17
  Parameters:
8
18
  PATH:
9
19
  Optional path to the markdown directory.
20
+ (Config option: path)
10
21
 
11
22
  Options:
12
23
  -p, --port NUMBER
13
24
  Set server port number.
25
+ (Config option: port)
14
26
 
15
27
  -b, --bind ADDRESS
16
28
  Set server listen address.
29
+ (Config option: bind)
17
30
 
18
31
  --no-auto-h1
19
32
  By default, if a markdown document does not start with an H1 caption,
20
33
  it will be added automatically based on the file name. To disable this
21
34
  behavior, use --no-auto-h1.
35
+ (Config option: auto_h1)
22
36
 
23
37
  --no-syntax
24
38
  Disable code syntax highlighting.
39
+ (Config option: highlighter)
25
40
 
26
41
  --no-line-numbers
27
42
  Disable line numbering for syntax highlighter.
43
+ (Config option: line_numbers)
28
44
 
29
45
  --no-sidebar
30
46
  Disable sidebar navigation.
47
+ (Config option: sidebar)
31
48
 
32
49
  --no-auto-nav
33
50
  Disable automatic generation of footer navigation for folder README
34
51
  files.
52
+ (Config option: auto_nav)
53
+
54
+ --theme FOLDER
55
+ Use a custom theme. FOLDER is either absolute or relative to the main
56
+ documentation path.
57
+ (Config option: theme)
35
58
 
36
59
  --index
37
60
  Build or rebuild the index for the search page.
61
+ (Config option: index)
38
62
 
39
63
  --toc FILE
40
64
  Generate a table of contents file.
65
+ (Config option: toc)
41
66
 
42
67
  --and-quit
43
68
  Quit instead of running the server. Useful with --index or --toc.
@@ -49,4 +74,8 @@ Examples:
49
74
  madness --no-sidebar --no-auto-nav
50
75
  madness --index --and-quit
51
76
  madness --toc "Table of Contents.md" --index --and-quit
77
+ madness --theme _mytheme
78
+ madness create config
79
+ madness create theme
80
+
52
81
 
@@ -6,15 +6,9 @@ module Madness
6
6
  class ServerBase < Sinatra::Application
7
7
  helpers ServerHelper
8
8
 
9
- Sass::Plugin.options[:template_location] = 'app/styles'
10
- Sass::Plugin.options[:css_location] = 'app/public/css'
11
9
  Slim::Engine.set_options pretty: true
12
-
13
10
  use Sass::Plugin::Rack
14
-
15
11
  set :root, File.expand_path('../../', __dir__)
16
- set :views, File.expand_path('../../app/views', __dir__)
17
- set :public_folder, File.expand_path('../../app/public', __dir__)
18
12
  set :server, :puma
19
13
 
20
14
  configure :development do
@@ -31,6 +25,17 @@ module Madness
31
25
  use Rack::TryStatic, root: "#{config.path}/", :urls => %w[/]
32
26
  set :bind, config.bind
33
27
  set :port, config.port
28
+
29
+ set_tempalate_locations
30
+ end
31
+
32
+ def self.set_tempalate_locations
33
+ theme = Theme.new config.theme
34
+
35
+ set :views, theme.views_path
36
+ set :public_folder, theme.public_path
37
+ Sass::Plugin.options[:template_location] = theme.css_source_path
38
+ Sass::Plugin.options[:css_location] = theme.css_target_path
34
39
  end
35
40
 
36
41
  def self.config
@@ -8,8 +8,18 @@ module Madness
8
8
  class Settings
9
9
  include Singleton
10
10
 
11
- attr_accessor :port, :bind, :path, :auto_h1,
12
- :highlighter, :line_numbers, :index, :toc, :sidebar, :auto_nav
11
+ attr_accessor \
12
+ :auto_h1,
13
+ :auto_nav,
14
+ :bind,
15
+ :highlighter,
16
+ :index,
17
+ :line_numbers,
18
+ :path,
19
+ :port,
20
+ :sidebar,
21
+ :theme,
22
+ :toc
13
23
 
14
24
  def initialize
15
25
  reset
@@ -43,6 +53,7 @@ module Madness
43
53
  self.highlighter = true
44
54
  self.line_numbers = true
45
55
  self.index = false
56
+ self.theme = nil
46
57
  end
47
58
 
48
59
  def load_from_file
@@ -0,0 +1,14 @@
1
+ # Madness configuration file
2
+ # Uncomment any of the options below
3
+
4
+ # path: '.'
5
+ # port: '3000'
6
+ # bind: '0.0.0.0'
7
+ # sidebar: true
8
+ # auto_h1: true
9
+ # auto_nav: true
10
+ # highlighter: true
11
+ # line_numbers: true
12
+ # index: false
13
+ # toc: Table of Contents
14
+ # theme: _theme
@@ -0,0 +1,30 @@
1
+ module Madness
2
+ class Theme
3
+ attr_reader :path
4
+
5
+ def initialize(path=nil)
6
+ @path = path
7
+ end
8
+
9
+ def views_path
10
+ custom? ? "#{path}/views" : File.expand_path('../../app/views', __dir__)
11
+ end
12
+
13
+ def public_path
14
+ custom? ? "#{path}/public" : File.expand_path('../../app/public', __dir__)
15
+ end
16
+
17
+ def css_source_path
18
+ custom? ? "#{path}/styles" : 'app/styles'
19
+ end
20
+
21
+ def css_target_path
22
+ custom? ? "#{path}/public/css" : 'app/public/css'
23
+ end
24
+
25
+ def custom?
26
+ @custom ||= (path and Dir.exist? path)
27
+ end
28
+ end
29
+ end
30
+
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
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.5.5
4
+ version: 0.5.6
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-26 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -381,6 +381,8 @@ files:
381
381
  - lib/madness/server_helper.rb
382
382
  - lib/madness/settings.rb
383
383
  - lib/madness/table_of_contents.rb
384
+ - lib/madness/templates/madness.yml
385
+ - lib/madness/theme.rb
384
386
  - lib/madness/version.rb
385
387
  homepage: https://github.com/DannyBen/madness
386
388
  licenses: