Skip to content

Commit 5f52f02

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.
1 parent 634707a commit 5f52f02

2 files changed

Lines changed: 15 additions & 3 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

0 commit comments

Comments
 (0)