Skip to content

Commit 7909600

Browse files
authored
Merge pull request #534 from koic/add_a_docs_preview_rake_task
Add a `rake docs:preview` task serving the docs site locally
2 parents 411f6b9 + 636e494 commit 7909600

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
/spec/reports/
1010
/tmp/
1111
Gemfile.lock
12+
docs/_site/
13+
docs/.jekyll-cache/
14+
docs/.jekyll-metadata
15+
docs/_data/versions.yml

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is the official Ruby SDK for the Model Context Protocol (MCP), implementing
1717
- `rake rubocop` - Run linter
1818
- `rake` - Run tests and linting (default task)
1919
- `bundle exec rake conformance` - Run the MCP conformance suite (see conformance/README.md)
20+
- `bundle exec rake docs:preview` - Serve the documentation site locally at http://localhost:4000 (PORT to override)
2021
- `ruby -I lib -I test test/path/to/specific_test.rb` - Run single test file
2122
- `gem build mcp.gemspec` - Build the gem
2223

Rakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,42 @@ task :conformance_server do
5151
Conformance::Server.new(**options).start
5252
end
5353

54+
namespace :docs do
55+
desc "Serve the documentation site locally at http://localhost:4000 (PORT)"
56+
task :preview do
57+
docs_dir = File.expand_path("docs", __dir__)
58+
generate_docs_versions_data(docs_dir)
59+
60+
env = {
61+
"BUNDLE_GEMFILE" => File.join(docs_dir, "Gemfile"),
62+
"RUBYOPT" => "-r#{File.join(docs_dir, "_preview", "taint_shim.rb")}",
63+
}
64+
port = ENV.fetch("PORT", "4000")
65+
66+
Bundler.with_unbundled_env do
67+
system(env, "bundle", "install", "--quiet", chdir: docs_dir, exception: true)
68+
system(env, "bundle", "exec", "jekyll", "serve", "--port", port, chdir: docs_dir, exception: true)
69+
rescue Interrupt
70+
# Ctrl-C is the way to stop the preview, not an error.
71+
end
72+
end
73+
end
74+
75+
# Mirrors bin/generate-gh-pages.sh: the released site receives `_data/versions.yml` from
76+
# the version tags at deploy time, and the preview generates the same data so the nav footer
77+
# shows the released-gem version line.
78+
def generate_docs_versions_data(docs_dir)
79+
versions = %x(git tag --list).split("\n").filter_map { |tag|
80+
tag[/\A[^0-9]*(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)\z/, 1]
81+
}.sort_by { |version|
82+
Gem::Version.new(version)
83+
}.reverse
84+
return if versions.empty?
85+
86+
mkdir_p(File.join(docs_dir, "_data"))
87+
File.write(File.join(docs_dir, "_data", "versions.yml"), versions.map { |version| "- #{version}\n" }.join)
88+
end
89+
5490
def npx_available?(task_name)
5591
return true if system("which", "npx", out: File::NULL, err: File::NULL)
5692

docs/Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
# Dependencies for the local docs preview (`rake docs:preview`), kept out of the gem's own Gemfile:
4+
# github-pages mirrors the GitHub Pages runtime that builds the released site
5+
# (jekyll-remote-theme, jekyll-redirect-from, and the Jekyll version Pages actually runs).
6+
source "https://rubygems.org"
7+
8+
gem "github-pages", group: :jekyll_plugins
9+
gem "webrick"
10+
11+
# Former default gems that the Jekyll version pinned by github-pages still requires on Ruby 4.0.
12+
gem "base64"
13+
gem "bigdecimal"
14+
gem "csv"
15+
gem "logger"

docs/_preview/taint_shim.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# Liquid 4.0.3 (pinned by github-pages) still calls the taint API that Ruby 3.2 removed.
4+
# Restore it as a no-op for the local docs preview only; `rake docs:preview` loads
5+
# this file via `RUBYOPT`, so nothing outside the preview process is affected.
6+
class Object
7+
def tainted?
8+
false
9+
end
10+
11+
def taint
12+
self
13+
end
14+
15+
def untaint
16+
self
17+
end
18+
end

0 commit comments

Comments
 (0)