Skip to content

Commit 0fecb94

Browse files
committed
Add make html-server for live-reloading doc preview
RDoc now has a `--server` mode that starts a local HTTP server with live reload. Add an `html-server` make target so developers can preview Ruby documentation while editing source files. Usage: `make html-server` from the build directory, then visit http://localhost:4000. Editing any source file's documentation comment will automatically refresh the browser. Use `make html-server RDOC_SERVER_PORT=8080` to change the port. Pin rdoc in `bundled_gems` to the commit that includes server mode support (e4e332f2).
1 parent 251fd7a commit 0fecb94

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

common.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ INSTALL_DOC_OPTS = --rdoc-output="$(RDOCOUT)" --html-output="$(HTMLOUT)"
7777
RDOC_GEN_OPTS = --no-force-update \
7878
--exclude '^lib/rubygems/core_ext/kernel_require\.rb$$' \
7979
$(empty)
80+
RDOC_SERVER_PORT = 4000
8081

8182
INITOBJS = dmyext.$(OBJEXT) dmyenc.$(OBJEXT)
8283
NORMALMAINOBJ = main.$(OBJEXT)
@@ -630,6 +631,10 @@ html: PHONY $(RDOC_DEPENDS) $(RBCONFIG)
630631
@echo Generating RDoc HTML files
631632
$(Q) $(RDOC) --op "$(HTMLOUT)" $(RDOC_GEN_OPTS) $(RDOCFLAGS) .
632633

634+
html-server: PHONY $(RDOC_DEPENDS) $(RBCONFIG)
635+
@echo Starting RDoc server with live reload
636+
$(Q) $(RDOC) --server=$(RDOC_SERVER_PORT) $(RDOC_GEN_OPTS) $(RDOCFLAGS) .
637+
633638
RDOC_COVERAGE_EXCLUDES = -x ^ext/json -x ^ext/openssl -x ^ext/psych \
634639
-x ^lib/bundler -x ^lib/rubygems \
635640
-x ^lib/did_you_mean -x ^lib/error_highlight -x ^lib/syntax_suggest

doc/contributing/documentation_guide.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ build directory:
2020
make html
2121
```
2222

23+
Or, to start a live-reloading server that automatically refreshes
24+
the browser when you edit source files:
25+
26+
```sh
27+
make html-server
28+
```
29+
30+
Then visit http://localhost:4000 in your browser.
31+
To use a different port: `make html-server RDOC_SERVER_PORT=8080`.
32+
2333
If you don't have a build directory, follow the [quick start
2434
guide](building_ruby.md#label-Quick+start+guide) up to step 4.
2535

26-
Then you can preview your changes by opening
27-
`{build folder}/.ext/html/index.html` file in your browser.
28-
2936
## Goal
3037

3138
The goal of Ruby documentation is to impart the most important

gems/bundled_gems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ostruct 0.6.3 https://github.com/ruby/ostruct
3737
pstore 0.2.1 https://github.com/ruby/pstore
3838
benchmark 0.5.0 https://github.com/ruby/benchmark
3939
logger 1.7.0 https://github.com/ruby/logger
40-
rdoc 7.2.0 https://github.com/ruby/rdoc
40+
rdoc 7.2.0 https://github.com/ruby/rdoc e4e332f2857f37f04f2f0aa359ce269a2c624176
4141
win32ole 1.9.3 https://github.com/ruby/win32ole
4242
irb 1.17.0 https://github.com/ruby/irb
4343
reline 0.6.3 https://github.com/ruby/reline

0 commit comments

Comments
 (0)