madness 0.7.3 → 0.7.4

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: 62a496bd766978ec0095976786632c03a6c26e72df950fcee0578512cff80147
4
- data.tar.gz: 7e24ebe336bfbac972df7eeb728d7341d1c1a6d955ee22a13913e39f3f13811b
3
+ metadata.gz: ec22db6e78f2280f7764aeb8a6d9651a4c1143c690a48e545418e3fe270de67a
4
+ data.tar.gz: d620d042133e056447287acc8de81c2f42998f146a694f448c4cc90da8377a25
5
5
  SHA512:
6
- metadata.gz: 372838e5d0345b941968b00579c795529e19216f1e5ccb6f2dcb152727dfe9b71591d3b74dc790ee841f01b32d96da0c2c33e7e925eef95c17c2388ddddb55c0
7
- data.tar.gz: bc57c2a3bb37886ad14b914e01f6affc4ebb8458f9679648b7fd227d1977e133f9b87634b71d956bc6c956439f32815701c9e31b73047064f2278464f5dba3ba
6
+ metadata.gz: a49197240d3b3ff61431a5a903cd4d3528e0185076a8c4084f27e00d973ad5a2be2e5e470d987d829ab9f5edf53fe331f78f734b14dfd5e469b8c6bc0275e3f9
7
+ data.tar.gz: bed7e069ba8d69cd657503c5394cd1c0b653a2ddde9ca8615e6807654622fc1586df4745643942f005fd029a846b243aa32383384a6b1d40cf77cedd0a057a76
data/README.md CHANGED
@@ -75,11 +75,12 @@ Go to any directory that contains markdown files and run:
75
75
 
76
76
  $ madness
77
77
 
78
+ And open <http://localhost:3000> in your browser.
79
+
78
80
  For more options, run:
79
81
 
80
82
  $ madness --help
81
83
 
82
-
83
84
  If you do not have Ruby installed, you can also
84
85
  [run madness with docker](#docker-image).
85
86
 
@@ -136,6 +137,7 @@ line_numbers: true
136
137
  index: false
137
138
  toc: Table of Contents
138
139
  theme: _theme
140
+ open: false
139
141
  ```
140
142
 
141
143
  For convenience, you can get a template config file by running:
@@ -164,7 +166,7 @@ documents change or new documents are added.
164
166
  Images and Static Files
165
167
  --------------------------------------------------
166
168
 
167
- You can put images and any other asset file anywhere in your documentation
169
+ You can put images and other asset files anywhere in your documentation
168
170
  folder.
169
171
 
170
172
  When linking to other pages or images in your documentation folder, simply
@@ -206,8 +208,10 @@ markdown file.
206
208
  Hidden Directories
207
209
  --------------------------------------------------
208
210
 
209
- Diretories that are made only of lowercase letters, underscoes, dash and/or
210
- numbers (`/^[a-z_\-0-9]+$/`) will not be displayed in the navigation.
211
+ Directories that are made only of lowercase letters, underscoes, dash and/or
212
+ numbers (`/^[a-z_\-0-9]+$/`) will not be displayed in the navigation. In
213
+ other words, directories must have at least one uppercase letter or a space
214
+ to be recognized as a documentation directory.
211
215
 
212
216
 
213
217
 
@@ -216,7 +220,8 @@ Controlling Sort Order
216
220
 
217
221
  To control the sort order of the automatically generated navigation elements,
218
222
  simply perfix your files and directories with digits followed by a dot and a
219
- space, just like you would create an ordered list in Markdown
223
+ space, just like you would create an ordered list in Markdown. The numbers
224
+ will be omitted when they are displayed.
220
225
 
221
226
  ```
222
227
  ./
@@ -257,7 +262,7 @@ $ madness --theme my_theme
257
262
 
258
263
  ### Option 2: Change CSS only
259
264
 
260
- If you are looking to implement a more minor CSS change, follow these steps:
265
+ If you are looking to implement a smaller CSS change, follow these steps:
261
266
 
262
267
  - Create a directory named `css` in your root documentation directory.
263
268
  - Copy the [main.css][css] file to it.
@@ -0,0 +1,63 @@
1
+ require 'socket'
2
+ require 'os'
3
+
4
+ module Madness
5
+ # Handles browser launching
6
+ class Browser
7
+ attr_reader :host, :port
8
+
9
+ def initialize(host, port)
10
+ @host, @port = host, port
11
+ end
12
+
13
+ # Returns a URL based on host, port and MADNESS_FORCE_SSL.
14
+ def server_url
15
+ scheme = ENV['MADNESS_FORCE_SSL'] ? 'https' : 'http'
16
+ url_host = ['0.0.0.0', '127.0.0.1'].include?(host) ? 'localhost' : host
17
+ "#{scheme}://#{url_host}:#{port}"
18
+ end
19
+
20
+ # Returns true if the server is running. Will attempt to connect
21
+ # multiple times. This is designed to assist in running some code after
22
+ # the server has launched.
23
+ def server_running?(retries: 5, delay: 1)
24
+ connected = false
25
+ attempts = 0
26
+
27
+ begin
28
+ connected = Socket.tcp(host, port)
29
+ rescue
30
+ sleep delay
31
+ retry if (attempts += 1) < retries
32
+ ensure
33
+ connected.close if connected
34
+ end
35
+
36
+ !!connected
37
+ end
38
+
39
+ # Open a web browser if the server is running. This is done in a
40
+ # non-blocking manner, so it can be executed before starting the server.
41
+ # It will yield an error message if it fails, or nil on success.
42
+ def open
43
+ fork do
44
+ if server_running?
45
+ success = open!
46
+ yield success ? nil : "Failed opening browser (#{open_command.join ' '})"
47
+ else
48
+ yield "Failed connecting to #{server_url}. Is the server running?"
49
+ end
50
+ end
51
+ end
52
+
53
+ # Runs the appropriate command (based on OS) to open a browser.
54
+ def open!
55
+ system *open_command, err: File::NULL, in: File::NULL, out: File::NULL
56
+ end
57
+
58
+ # Returns the appropriate command (based on OS) to open a browser.
59
+ def open_command
60
+ @open_command ||= [OS.open_file_command, server_url]
61
+ end
62
+ end
63
+ end
@@ -35,11 +35,12 @@ module Madness
35
35
  end
36
36
  end
37
37
 
38
- # Execute some pre-server-launch operations if needed, and execute
39
- # the server.
38
+ # Execute some pre-server-launch operations if needed, execute the
39
+ # server, and launch the browser if requested.
40
40
  def launch_server_with_options(args)
41
41
  set_config args
42
42
  generate_stuff
43
+ open_browser if config.open
43
44
  launch_server unless args['--and-quit']
44
45
  end
45
46
 
@@ -70,6 +71,7 @@ module Madness
70
71
  config.highlighter = false if args['--no-syntax']
71
72
  config.line_numbers = false if args['--no-line-numbers']
72
73
  config.index = true if args['--index']
74
+ config.open = true if args['--open']
73
75
  config.theme = File.expand_path(args['--theme'], config.path) if args['--theme']
74
76
  end
75
77
 
@@ -119,6 +121,7 @@ module Madness
119
121
  search.build_index
120
122
  end
121
123
 
124
+ # Generate the table of contents file
122
125
  def build_toc
123
126
  say_status :toc, "generating #{config.toc}"
124
127
  TableOfContents.new.build(config.toc)
@@ -127,5 +130,14 @@ module Madness
127
130
  def config
128
131
  @config ||= Settings.instance
129
132
  end
133
+
134
+ # Open a web browser if the server is running. This is done in a
135
+ # non-blocking manner, so it can be executed before starting the server.
136
+ def open_browser
137
+ browser = Browser.new config.bind, config.port
138
+ browser.open do |error|
139
+ say "!txtred!#{error}" if error
140
+ end
141
+ end
130
142
  end
131
143
  end
@@ -64,6 +64,10 @@ Options:
64
64
  Generate a table of contents file.
65
65
  (Config option: toc)
66
66
 
67
+ --open
68
+ Open the browser pointing at the madness webserver.
69
+ (Config option: open)
70
+
67
71
  --and-quit
68
72
  Quit instead of running the server. Useful with --index or --toc.
69
73
 
@@ -71,6 +75,7 @@ Examples:
71
75
  madness
72
76
  madness docs
73
77
  madness docs --no-auto-h1 -p 4567
78
+ madness docs --open
74
79
  madness --no-sidebar --no-auto-nav
75
80
  madness --index --and-quit
76
81
  madness --toc "Table of Contents.md" --index --and-quit
@@ -51,7 +51,7 @@ module Madness
51
51
  line_numbers: true,
52
52
  index: false,
53
53
  theme: nil,
54
-
54
+ open: false,
55
55
  auto_nav: true,
56
56
  sidebar: true
57
57
  }
@@ -12,3 +12,4 @@
12
12
  # index: false
13
13
  # toc: Table of Contents
14
14
  # theme: _theme
15
+ # open: false
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
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.7.3
4
+ version: 0.7.4
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: 2019-10-26 00:00:00.000000000 Z
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: os
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: puma
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -278,6 +292,7 @@ files:
278
292
  - bin/madness
279
293
  - lib/madness.rb
280
294
  - lib/madness/breadcrumbs.rb
295
+ - lib/madness/browser.rb
281
296
  - lib/madness/command_line.rb
282
297
  - lib/madness/directory.rb
283
298
  - lib/madness/docopt.txt