madness 1.0.0.rc1 → 1.0.0.rc2

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.
@@ -1,130 +0,0 @@
1
- require 'fileutils'
2
- require 'singleton'
3
- require 'colsole'
4
- require 'docopt'
5
-
6
- module Madness
7
- # Handle command line execution. Used by bin/madness.
8
- class CommandLine
9
- include Singleton
10
- include Colsole
11
-
12
- # Process ARGV by putting it through docopt
13
- def execute(argv = [])
14
- doc = File.read File.expand_path('docopt.txt', __dir__)
15
-
16
- begin
17
- args = Docopt.docopt(doc, argv: argv, version: VERSION)
18
- handle args
19
- rescue Docopt::Exit => e
20
- puts e.message
21
- end
22
- end
23
-
24
- private
25
-
26
- # Separate between the two main modes: Create something, or launch
27
- # the server.
28
- def handle(args)
29
- if args['create']
30
- create_config if args['config']
31
- create_theme(args['FOLDER']) if args['theme']
32
- else
33
- launch_server_with_options args
34
- end
35
- end
36
-
37
- # Execute some pre-server-launch operations if needed, execute the
38
- # server, and launch the browser if requested.
39
- def launch_server_with_options(args)
40
- set_config args
41
- generate_stuff
42
- open_browser if config.open
43
- launch_server unless args['--and-quit']
44
- end
45
-
46
- # Launch the server, but not before doing some checks and making sure
47
- # we ask it to "prepare". This will set the server options such as port
48
- # and static files folder.
49
- def launch_server
50
- unless File.directory? config.path
51
- $stderr.puts "Invalid path (#{config.path})"
52
- return
53
- end
54
-
55
- show_status
56
- Server.prepare
57
- Server.run!
58
- end
59
-
60
- # Get the arguments as provided by docopt, and set them to our own
61
- # config object.
62
- def set_config(args)
63
- config.path = args['PATH'] if args['PATH']
64
- config.port = args['--port'].to_i if args['--port']
65
- config.bind = args['--bind'] if args['--bind']
66
- config.toc = args['--toc'] if args['--toc']
67
- config.auth = args['--auth'] if args['--auth']
68
- config.auth_realm = args['--auth-realm'] if args['--auth-realm']
69
- config.open = true if args['--open']
70
- config.theme = File.expand_path(args['--theme'], config.path) if args['--theme']
71
- end
72
-
73
- # Generate index and toc, if requested by the user.
74
- def generate_stuff
75
- build_toc if config.toc
76
- end
77
-
78
- # Create config
79
- def create_config
80
- if File.exist? config.filename
81
- say "!txtred!Abort: config file #{config.filename} already exists"
82
- else
83
- FileUtils.cp File.expand_path('templates/madness.yml', __dir__), config.filename
84
- say "!txtgrn!Created #{config.filename} config file"
85
- end
86
- end
87
-
88
- # Create theme
89
- def create_theme(path)
90
- if Dir.exist? path
91
- say "!txtred!Abort: folder #{path} already exists"
92
- else
93
- FileUtils.cp_r File.expand_path('../../app', __dir__), path
94
- say "!txtgrn!Created #{path} theme folder"
95
- end
96
- end
97
-
98
- # Say hello to everybody when the server starts, showing the known
99
- # config.
100
- def show_status
101
- say_status :start, 'the madness'
102
- say_status :env, Server.environment, :txtblu
103
- say_status :listen, "#{config.bind}:#{config.port}", :txtblu
104
- say_status :path, File.realpath(config.path), :txtblu
105
- say_status :use, config.filename if config.file_exist?
106
- say_status :theme, config.theme, :txtblu if config.theme
107
-
108
- say '-' * 60
109
- end
110
-
111
- # Generate the table of contents file
112
- def build_toc
113
- say_status :toc, "generating #{config.toc}"
114
- TableOfContents.new.build(config.toc)
115
- end
116
-
117
- def config
118
- @config ||= Settings.instance
119
- end
120
-
121
- # Open a web browser if the server is running. This is done in a
122
- # non-blocking manner, so it can be executed before starting the server.
123
- def open_browser
124
- browser = Browser.new config.bind, config.port
125
- browser.open do |error|
126
- say "!txtred!#{error}" if error
127
- end
128
- end
129
- end
130
- end
@@ -1,64 +0,0 @@
1
- Madness
2
-
3
- Usage:
4
- madness [PATH] [options]
5
- madness create config
6
- madness create theme FOLDER
7
- madness (-h|--help|--version)
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
-
17
- Parameters:
18
- PATH:
19
- Path to the markdown directory.
20
- (Config option: path, default: .)
21
-
22
- Options:
23
- -p, --port NUMBER
24
- Set server port number.
25
- (Config option: port, default: 3000)
26
-
27
- -b, --bind ADDRESS
28
- Set server listen address.
29
- (Config option: bind, default: 0.0.0.0)
30
-
31
- --theme FOLDER
32
- Use a custom theme. FOLDER is either absolute or relative to the main
33
- documentation path.
34
- (Config option: theme)
35
-
36
- --toc FILE
37
- Generate a table of contents file.
38
- (Config option: toc)
39
-
40
- --auth USER:PASS
41
- Enable basic authentication.
42
- (Config option: auth)
43
-
44
- --auth-realm REALM
45
- The basic authentication realm.
46
- (Config option: auth_realm, default: Madness)
47
-
48
- --open
49
- Open the browser pointing at the madness webserver.
50
- (Config option: open)
51
-
52
- --and-quit
53
- Quit instead of running the server. Useful with --toc.
54
-
55
- Examples:
56
- madness
57
- madness docs
58
- madness docs -p 4567
59
- madness docs --open
60
- madness --toc "Table of Contents.md" --and-quit
61
- madness --auth user:secret --port 4000
62
- madness --theme _mytheme
63
- madness create config
64
- madness create theme