Skip to content

Instantly share code, notes, and snippets.

@akiatoji
Last active October 6, 2015 19:57
Show Gist options
  • Save akiatoji/3044907 to your computer and use it in GitHub Desktop.
Save akiatoji/3044907 to your computer and use it in GitHub Desktop.
Setting up Yard server as rack app in Nginx

Run Yard server to serve Gem docs

Based on good work found at http://goo.gl/bKjJe

If you have Nginx running, you can run Yard as a rack app to serve docs for locally installed Gem.

  1. Create a directory to host Rack app. Install yard gem
mkdir -p ~/Dropbox/yard/public
gem install yard
  1. Add config.ru as ~/Dropbox/yard/config.ru
  2. Add Gemfile as ~/Dropbox/yard/Gemfile
  3. Run cd ~/Dropbox/yard; bundle install
  4. In nginx config, add gems.doc virtualhost
  5. Add a localhost alias gems.doc to /etc/hosts file.
  6. Restart nginx and access http://gems.doc:8010 to see docs.
  7. You'll need to re-start nginx everytime you add new gems to your Ruby installation.
require 'rubygems'
require 'yard'
libraries = {}
gems = Gem.source_index.find_name('').each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
end
run YARD::Server::RackAdapter.new libraries
source 'https://rubygems.org'
gem 'rack'
gem 'yard'
gem 'redcarpet'
server {
listen 8010;
server_name gems.doc;
root /Users/Aki/Dropbox/yard/public;
rails_env development;
passenger_enabled on;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment