Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 460 lines (390 sloc) 13.15 kb
2e57ee2 @zapnap update sinatra / modernize
zapnap authored
1 require File.join(File.dirname(__FILE__), 'init')
4422c74 @lsegal Require 'init' before gems.
authored
2
524c225 @lsegal Initial commit
authored
3 require 'yard'
4 require 'sinatra'
5 require 'json'
89f8a6c @lsegal Add caching support
authored
6 require 'fileutils'
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
7 require 'airbrake'
524c225 @lsegal Initial commit
authored
8
9 require 'extensions'
10 require 'scm_router'
11 require 'scm_checkout'
12 require 'gems_router'
680a2ca @lsegal Add featured section with featured library docs
authored
13 require 'featured_router'
d342536 @lsegal Add section for stdlib docs
authored
14 require 'stdlib_router'
caab733 @zapnap add recent projects list to homepage
zapnap authored
15 require 'recent_store'
524c225 @lsegal Initial commit
authored
16
1ce0995 @lsegal Use ETag Rack middleware
authored
17 require 'rack/etag'
18
67fd1be @lsegal Update to new Hoptoad
authored
19 class Hash; alias blank? empty? end
20 class NilClass; def blank?; true end end
21
8484992 @lsegal Don't cache empty bodies
authored
22 class NoCacheEmptyBody
23 def initialize(app) @app = app end
24 def call(env)
25 status, headers, body = *@app.call(env)
838c4ae @lsegal Update checks for empty body middleware
authored
26 if headers.has_key?('Content-Length') && headers['Content-Length'].to_i == 0
7eb8b95 @lsegal Add Last-Modified header
authored
27 headers['Cache-Control'] = 'max-age=0'
838c4ae @lsegal Update checks for empty body middleware
authored
28 end
8484992 @lsegal Don't cache empty bodies
authored
29 [status, headers, body]
30 end
31 end
32
524c225 @lsegal Initial commit
authored
33 class DocServer < Sinatra::Base
34 include YARD::Server
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
35
524c225 @lsegal Initial commit
authored
36 def self.adapter_options
8774004 @lsegal Update caching value for YARD server
authored
37 caching = %w(staging production).include?(ENV['RACK_ENV']) ? $CONFIG.caching : false
524c225 @lsegal Initial commit
authored
38 {
39 :libraries => {},
40 :options => {caching: caching, single_library: false},
41 :server_options => {DocumentRoot: STATIC_PATH}
42 }
43 end
177700d @lsegal Big whitespace fix
authored
44
a95d2fb @lsegal Refactor config.yaml loading and error notification.
authored
45 def self.load_configuration
81dc4ea @lsegal Capitalization of RubyDoc.info
authored
46 set :name, 'RubyDoc.info'
f8686f3 @zapnap www canonical domain
zapnap authored
47 set :url, 'http://www.rubydoc.info'
d9dc2ca @zapnap allow name and base url to be set in config.yaml
zapnap authored
48
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
49 set :disallowed_projects, []
50 set :disallowed_gems, []
51 set :whitelisted_projects, []
52 set :whitelisted_gems, []
7cbd081 @lsegal Move caching setting into config
authored
53 set :caching, false
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
54
fec7f4c @lsegal Allow HTTP requests to Varnish host
authored
55 if $CONFIG.varnish_host
5c49de6 @lsegal Fix whitelist host
authored
56 set :protection, :origin_whitelist => ["http://#{$CONFIG.varnish_host}"]
fec7f4c @lsegal Allow HTTP requests to Varnish host
authored
57 end
58
a95d2fb @lsegal Refactor config.yaml loading and error notification.
authored
59 puts ">> Loading #{CONFIG_FILE}"
5c02cf6 @lsegal Revamp configuration
authored
60 $CONFIG.each do |key, value|
a95d2fb @lsegal Refactor config.yaml loading and error notification.
authored
61 set key, value
62 end
63 end
177700d @lsegal Big whitespace fix
authored
64
524c225 @lsegal Initial commit
authored
65 def self.copy_static_files
66 # Copy template files
67 puts ">> Copying static system files..."
c3794f6 @lsegal Copy static files using new static file support
authored
68 YARD::Templates::Engine.template(:default, :fulldoc, :html).full_paths.each do |path|
524c225 @lsegal Initial commit
authored
69 %w(css js images).each do |ext|
97e8bb4 @lsegal Make sure dst dirs exist when copying static files
authored
70 srcdir, dstdir = File.join(path, ext), File.join('public', ext)
71 next unless File.directory?(srcdir)
72 system "mkdir -p #{dstdir} && cp #{srcdir}/* #{dstdir}/"
524c225 @lsegal Initial commit
authored
73 end
74 end
75 end
caab733 @zapnap add recent projects list to homepage
zapnap authored
76
524c225 @lsegal Initial commit
authored
77 def self.load_gems_adapter
e15b311 @lsegal Update configuration and initialization routines, add rake server:setup ...
authored
78 remote_file = REMOTE_GEMS_FILE
524c225 @lsegal Initial commit
authored
79 contents = File.readlines(remote_file)
80 puts ">> Loading remote gems list..."
81 opts = adapter_options
82 contents.each do |line|
83 name, *versions = *line.split(/\s+/)
3afa36e @lsegal Update remote gem fetcher / installer to understand platform suffixes on...
authored
84 opts[:libraries][name] = versions.map do |v|
85 ver, platform = *v.split(',')
86 lib = LibraryVersion.new(name, ver, nil, :remote_gem)
87 lib.platform = platform
88 lib
89 end
524c225 @lsegal Initial commit
authored
90 end
91 opts[:options][:router] = GemsRouter
ed4d662 @lsegal Support featured libraries loaded from gems
authored
92 set :gems_adapter, $gems_adapter = RackAdapter.new(*opts.values)
524c225 @lsegal Initial commit
authored
93 rescue Errno::ENOENT
94 log.error "No remote_gems file to load remote gems from, not serving gems."
95 end
177700d @lsegal Big whitespace fix
authored
96
524c225 @lsegal Initial commit
authored
97 def self.load_scm_adapter
98 opts = adapter_options
99 opts[:options][:router] = ScmRouter
100 opts[:libraries] = ScmLibraryStore.new
101 set :scm_adapter, RackAdapter.new(*opts.values)
102 end
177700d @lsegal Big whitespace fix
authored
103
680a2ca @lsegal Add featured section with featured library docs
authored
104 def self.find_featured_yardoc(name, libdir)
105 [File.join(FEATURED_PATH, libdir, '.yardoc'), File.join(libdir, '.yardoc')].each do |path|
106 return path if File.directory?(path)
107 end
108 log.error "Invalid featured repository #{libdir} for #{name}"
109 exit
110 end
177700d @lsegal Big whitespace fix
authored
111
680a2ca @lsegal Add featured section with featured library docs
authored
112 def self.load_featured_adapter
9ae1938 @lsegal Fix parsing of featured configuration data
authored
113 if !$CONFIG.featured
114 log.error "No featured section in config.yaml, not serving featured docs."
115 set :featured_adapter, nil
116 return
117 end
118
680a2ca @lsegal Add featured section with featured library docs
authored
119 opts = adapter_options
120 opts[:options][:router] = FeaturedRouter
9ae1938 @lsegal Fix parsing of featured configuration data
authored
121 $CONFIG.featured.each do |key, value|
680a2ca @lsegal Add featured section with featured library docs
authored
122 opts[:libraries][key] = case value
123 when String
ed4d662 @lsegal Support featured libraries loaded from gems
authored
124 if value == "gem"
125 $gems_adapter && $gems_adapter.libraries[key] ? $gems_adapter.libraries[key] : []
126 else
127 [LibraryVersion.new(key, nil, find_featured_yardoc(key, value))]
128 end
3bc4bfc @lsegal Update featured.yaml handling
authored
129 when Array, Hash
130 value = value.first if Array === value
131 value.map do |version, libdir|
680a2ca @lsegal Add featured section with featured library docs
authored
132 LibraryVersion.new(key, version, find_featured_yardoc(key, libdir))
133 end
134 end
135 end
136 set :featured_adapter, RackAdapter.new(*opts.values)
137 end
d342536 @lsegal Add section for stdlib docs
authored
138
177700d @lsegal Big whitespace fix
authored
139
d342536 @lsegal Add section for stdlib docs
authored
140 def self.load_stdlib_adapter
141 unless File.directory?(STDLIB_PATH)
142 log.error "No stdlib repository, not serving standard library"
143 return
144 end
145
146 opts = adapter_options
147 opts[:options][:router] = StdlibRouter
148 versions = Dir.glob(File.join(STDLIB_PATH, '*'))
b06ecda @lsegal Try to reverse order (again)
authored
149 versions.sort_by {|v| File.basename(v) }.each do |version|
d342536 @lsegal Add section for stdlib docs
authored
150 next unless File.directory?(version)
151 version = File.basename(version)
152 libs = Dir.glob(File.join(STDLIB_PATH, version, '*'))
153 libs.each do |lib|
154 next unless File.directory?(lib)
155 libname = File.basename(lib)
156 yardoc = File.join(lib, '.yardoc')
157 opts[:libraries][libname] ||= []
158 opts[:libraries][libname] << LibraryVersion.new(libname, version, nil, :disk_on_demand)
159 end
160 end
161 set :stdlib_adapter, RackAdapter.new(*opts.values)
162 end
177700d @lsegal Big whitespace fix
authored
163
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
164 def self.post_all(*args, &block)
165 args.each {|arg| post(arg, &block) }
166 end
524c225 @lsegal Initial commit
authored
167
168 use Rack::ConditionalGet
169 use Rack::Head
838c4ae @lsegal Update checks for empty body middleware
authored
170 use NoCacheEmptyBody
524c225 @lsegal Initial commit
authored
171
172 enable :static
173 enable :dump_errors
33b3ccb @lsegal Must use locking due to new safe_mode restrictions
authored
174 enable :lock
524c225 @lsegal Initial commit
authored
175 disable :raise_errors
176
177 set :views, TEMPLATES_PATH
2e57ee2 @zapnap update sinatra / modernize
zapnap authored
178 set :public_folder, STATIC_PATH
524c225 @lsegal Initial commit
authored
179 set :repos, REPOS_PATH
180 set :tmp, TMP_PATH
181
182 configure(:production) do
183 enable :logging
89f8a6c @lsegal Add caching support
authored
184 # log to file
97e034a @zapnap add log directory
zapnap authored
185 file = File.open("log/sinatra.log", "a")
524c225 @lsegal Initial commit
authored
186 STDOUT.reopen(file)
187 STDERR.reopen(file)
188 end
177700d @lsegal Big whitespace fix
authored
189
524c225 @lsegal Initial commit
authored
190 configure do
a95d2fb @lsegal Refactor config.yaml loading and error notification.
authored
191 load_configuration
e15b311 @lsegal Update configuration and initialization routines, add rake server:setup ...
authored
192 load_gems_adapter
524c225 @lsegal Initial commit
authored
193 load_scm_adapter
680a2ca @lsegal Add featured section with featured library docs
authored
194 load_featured_adapter
d342536 @lsegal Add section for stdlib docs
authored
195 load_stdlib_adapter
a95d2fb @lsegal Refactor config.yaml loading and error notification.
authored
196 copy_static_files
524c225 @lsegal Initial commit
authored
197 end
177700d @lsegal Big whitespace fix
authored
198
524c225 @lsegal Initial commit
authored
199 helpers do
9b9165c @lsegal Escape search results data
authored
200 include YARD::Templates::Helpers::HtmlHelper
177700d @lsegal Big whitespace fix
authored
201
caab733 @zapnap add recent projects list to homepage
zapnap authored
202 def recent_store
203 @@recent_store ||= RecentStore.new(20)
204 end
205
524c225 @lsegal Initial commit
authored
206 def notify_error
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
207 if settings.airbrake && %w(staging production).include?(ENV['RACK_ENV'])
208 Airbrake.configure do |config|
209 config.api_key = settings.airbrake
210 end unless @airbrake_configured
211 @airbrake_configured = true
67fd1be @lsegal Update to new Hoptoad
authored
212 exc = request.env['sinatra.error']
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
213 Airbrake.notify exc,
67fd1be @lsegal Update to new Hoptoad
authored
214 error_message: exc.message,
215 request: request,
216 environment: request.env,
217 session: request.session,
218 backtrace: caller
524c225 @lsegal Initial commit
authored
219 end
220 erb(:error)
221 end
177700d @lsegal Big whitespace fix
authored
222
89f8a6c @lsegal Add caching support
authored
223 def cache(output)
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
224 return output if settings.caching != true
685fd4b @lsegal Don't cache empty files
authored
225 return '' if output.nil? || output.empty?
89f8a6c @lsegal Add caching support
authored
226 path = request.path.gsub(%r{^/|/$}, '')
57d9bbd @lsegal Cache / to index.html instead of /.html
authored
227 path = 'index' if path == ''
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
228 path = File.join(settings.public_folder, path + '.html')
89f8a6c @lsegal Add caching support
authored
229 FileUtils.mkdir_p(File.dirname(path))
230 File.open(path, "w") {|f| f.write(output) }
231 output
232 end
177700d @lsegal Big whitespace fix
authored
233
89f8a6c @lsegal Add caching support
authored
234 def next_row(prefix = 'r', base = 1)
235 prefix + (@row = @row == base ? base + 1 : base).to_s
236 end
177700d @lsegal Big whitespace fix
authored
237
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
238 def translate_file_links(extra)
239 extra.sub(%r{^/(frames/)?file:}, '/\1file/')
240 end
db0ece9 @zapnap redirect old rdoc.info links
zapnap authored
241
242 def shorten_commit_link(commit)
243 commit.slice(0..5)
244 end
524c225 @lsegal Initial commit
authored
245 end
177700d @lsegal Big whitespace fix
authored
246
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
247 # Filters
248
249 # Always reset safe mode
250 before { YARD::Config.options[:safe_mode] = true }
7565c12 @lsegal Add Last-Modified after
authored
251
252 # Set Last-Modified on all requests
253 after { last_modified Time.now }
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
254
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
255 # Checkout and post commit hooks
177700d @lsegal Big whitespace fix
authored
256
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
257 post_all '/checkout', '/projects/update' do
258 begin
2e0958a @zapnap fix and modernize github webhook
zapnap authored
259 if params[:payload] # backwards compatibility
0917964 @zapnap provide web-hooks for rdoc.info backwards compatibility
zapnap authored
260 payload = JSON.parse(params[:payload])
2e0958a @zapnap fix and modernize github webhook
zapnap authored
261 url = payload['repository']['url']
262 elsif request.media_type.match(/json/)
263 payload = JSON.parse(request.body.read || '{}')
264 payload = payload['payload'] if payload.keys.include?('payload')
265 url = payload['repository']['url']
0917964 @zapnap provide web-hooks for rdoc.info backwards compatibility
zapnap authored
266 else
267 url = params[:url]
268 commit = params[:commit]
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
269 commit = nil if commit == ''
0917964 @zapnap provide web-hooks for rdoc.info backwards compatibility
zapnap authored
270 end
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
271
2e0958a @zapnap fix and modernize github webhook
zapnap authored
272 url = (url || '').sub(%r{^http://}, 'git://')
273 commit ||= nil
274
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
275 if url =~ %r{github\.com/([^/]+)/([^/]+)}
276 username, project = $1, $2
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
277 if settings.whitelisted_projects.include?("#{username}/#{project}")
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
278 puts "Dropping safe mode for #{username}/#{project}"
279 YARD::Config.options[:safe_mode] = false
280 end
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
281 if settings.disallowed_projects.include?("#{username}/#{project}")
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
282 return status(503) && "Cannot parse this project"
283 end
284 end
285
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
286 scm = GithubCheckout.new(self, url, commit)
287 scm.flush_cache
fe72273 @lsegal Don't fork checkouts
authored
288 scm.checkout
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
289 "OK"
290 rescue InvalidSchemeError
291 "INVALIDSCHEME"
524c225 @lsegal Initial commit
authored
292 end
293 end
294
295 get '/checkout/:username/:project/:commit' do
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
296 git = GithubCheckout.new(self, [params[:username], params[:project]], params[:commit])
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
297 if libs = settings.scm_adapter.libraries[git.name]
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
298 if lib = libs.find {|l| l.version == git.commit }
299 return "NO" unless File.exist?(File.join(lib.source_path, '.yardoc', 'complete'))
177700d @lsegal Big whitespace fix
authored
300 return "YES"
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
301 end
524c225 @lsegal Initial commit
authored
302 end
177700d @lsegal Big whitespace fix
authored
303
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
304 if File.exist?(git.error_file)
305 puts "#{git.error_file} found"
524c225 @lsegal Initial commit
authored
306 "ERROR"
307 else
f14aa14 @lsegal Refactor checkout code and remove SVN support. Cache should now get flus...
authored
308 puts "#{git.error_file} not found"
524c225 @lsegal Initial commit
authored
309 "NO"
310 end
311 end
177700d @lsegal Big whitespace fix
authored
312
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
313 # Main URL handlers
177700d @lsegal Big whitespace fix
authored
314
4b307c5 @lsegal Update templates
authored
315 get %r{^/github(?:/~([a-z])?|/)?$} do |letter|
e40a0e2 @lsegal Show latest github projects if no letter is selected
authored
316 if letter.nil?
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
317 @adapter = settings.scm_adapter
e40a0e2 @lsegal Show latest github projects if no letter is selected
authored
318 @libraries = recent_store
319 cache erb(:home)
320 else
04ac4e9 @lsegal Refactor default github/ url
authored
321 @letter = letter
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
322 @adapter = settings.scm_adapter
e40a0e2 @lsegal Show latest github projects if no letter is selected
authored
323 @libraries = @adapter.libraries
324 @sorted_libraries = @libraries.sorted_by_project(@letter)
325 cache erb(:scm_index)
326 end
524c225 @lsegal Initial commit
authored
327 end
177700d @lsegal Big whitespace fix
authored
328
4b307c5 @lsegal Update templates
authored
329 get %r{^/gems(?:/~([a-z])?|/)?$} do |letter|
524c225 @lsegal Initial commit
authored
330 @letter = letter || 'a'
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
331 @adapter = settings.gems_adapter
524c225 @lsegal Initial commit
authored
332 @libraries = @adapter.libraries.find_all {|k, v| k[0].downcase == @letter }
89f8a6c @lsegal Add caching support
authored
333 cache erb(:gems_index)
524c225 @lsegal Initial commit
authored
334 end
177700d @lsegal Big whitespace fix
authored
335
7278340 @lsegal Add nicer 404 pages
authored
336 get %r{^/(?:(?:search|list)/)?github/([^/]+)/([^/]+)} do |username, project|
337 @username, @project = username, project
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
338 if settings.whitelisted_projects.include?("#{username}/#{project}")
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
339 puts "Dropping safe mode for #{username}/#{project}"
340 YARD::Config.options[:safe_mode] = false
341 end
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
342 result = settings.scm_adapter.call(env)
7278340 @lsegal Add nicer 404 pages
authored
343 return status(404) && erb(:scm_404) if result.first == 404
344 result
524c225 @lsegal Initial commit
authored
345 end
346
7278340 @lsegal Add nicer 404 pages
authored
347 get %r{^/(?:(?:search|list)/)?gems/([^/]+)} do |gemname|
22d8c8f @lsegal Moved disallowed/whitelisted gems/projects to config file
authored
348 return status(503) && "Cannot parse this gem" if settings.disallowed_gems.include?(gemname)
349 if settings.whitelisted_gems.include?(gemname)
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
350 puts "Dropping safe mode for #{gemname}"
351 YARD::Config.options[:safe_mode] = false
352 end
7278340 @lsegal Add nicer 404 pages
authored
353 @gemname = gemname
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
354 result = settings.gems_adapter.call(env)
7278340 @lsegal Add nicer 404 pages
authored
355 return status(404) && erb(:gems_404) if result.first == 404
356 result
524c225 @lsegal Initial commit
authored
357 end
177700d @lsegal Big whitespace fix
authored
358
d342536 @lsegal Add section for stdlib docs
authored
359 # Stdlib
177700d @lsegal Big whitespace fix
authored
360
d342536 @lsegal Add section for stdlib docs
authored
361 get %r{^/(?:(?:search|list)/)?stdlib/([^/]+)} do |libname|
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
362 YARD::Config.options[:safe_mode] = false
d342536 @lsegal Add section for stdlib docs
authored
363 @libname = libname
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
364 pass unless settings.stdlib_adapter.libraries[libname]
365 result = settings.stdlib_adapter.call(env)
d342536 @lsegal Add section for stdlib docs
authored
366 return status(404) && erb(:stdlib_404) if result.first == 404
367 result
368 end
177700d @lsegal Big whitespace fix
authored
369
d342536 @lsegal Add section for stdlib docs
authored
370 get %r{^/stdlib/?$} do
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
371 @stdlib = settings.stdlib_adapter.libraries
d342536 @lsegal Add section for stdlib docs
authored
372 cache erb(:stdlib_index)
373 end
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
374
680a2ca @lsegal Add featured section with featured library docs
authored
375 # Featured libraries
177700d @lsegal Big whitespace fix
authored
376
0c94e2f @lsegal Redirect featured gem docs
authored
377 get %r{^/(?:(?:search|list)/)?docs/([^/]+)(/?.*)} do |libname, extra|
9b98396 @lsegal Respect safe_mode and allow whitelisted projects/gems to run with safe_m...
authored
378 YARD::Config.options[:safe_mode] = false
680a2ca @lsegal Add featured section with featured library docs
authored
379 @libname = libname
0c94e2f @lsegal Redirect featured gem docs
authored
380 lib = settings.featured_adapter.libraries[libname]
381 pass if lib.nil? || lib.empty?
382 if lib.first.source == :remote_gem
383 return redirect("/gems/#{libname}#{extra}", 302)
384 end
385
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
386 result = settings.featured_adapter.call(env)
680a2ca @lsegal Add featured section with featured library docs
authored
387 return status(404) && erb(:featured_404) if result.first == 404
388 result
389 end
177700d @lsegal Big whitespace fix
authored
390
680a2ca @lsegal Add featured section with featured library docs
authored
391 get %r{^/(featured|docs/?$)} do
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
392 @featured = settings.featured_adapter.libraries
680a2ca @lsegal Add featured section with featured library docs
authored
393 cache erb(:featured_index)
394 end
395
653b8b1 @zapnap basic gem / project search
zapnap authored
396 # Simple search interfaces
397
398 get %r{^/find/github} do
399 @search = params[:q]
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
400 @adapter = settings.scm_adapter
653b8b1 @zapnap basic gem / project search
zapnap authored
401 @libraries = @adapter.libraries
402 @sorted_libraries = @libraries.sorted_by_project("*#{@search}")
c89bba1 @zapnap don't cache search results
zapnap authored
403 erb(:scm_index)
653b8b1 @zapnap basic gem / project search
zapnap authored
404 end
405
406 get %r{^/find/gems} do
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
407 self.class.load_gems_adapter unless defined? settings.gems_adapter
d0d679d @zapnap prevent match on nil
zapnap authored
408 @search = params[:q] || ''
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
409 @adapter = settings.gems_adapter
9b9165c @lsegal Escape search results data
authored
410 @libraries = @adapter.libraries.find_all {|k,v| k.match(/#{Regexp.quote @search}/) }
c89bba1 @zapnap don't cache search results
zapnap authored
411 erb(:gems_index)
653b8b1 @zapnap basic gem / project search
zapnap authored
412 end
413
d342536 @lsegal Add section for stdlib docs
authored
414 # Redirect /docs/ruby-core
415 get(%r{^/docs/ruby-core/?(.*)}) do |all|
416 redirect("/stdlib/core/#{all}", 301)
417 end
177700d @lsegal Big whitespace fix
authored
418
d342536 @lsegal Add section for stdlib docs
authored
419 # Redirect /docs/ruby-stdlib
420 get(%r{^/docs/ruby-stdlib/?(.*)}) do |all|
421 redirect("/stdlib")
422 end
423
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
424 # Old URL structure redirection for yardoc.org
177700d @lsegal Big whitespace fix
authored
425
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
426 get(%r{^/docs/([^/]+)-([^/]+)(/?.*)}) do |user, proj, extra|
9778bbb @lsegal Fix redirection from yardoc.org
authored
427 redirect("/github/#{user}/#{proj}#{translate_file_links extra}", 301)
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
428 end
429
430 get(%r{^/docs/([^/]+)(/?.*)}) do |lib, extra|
d99b99c @lsegal Make URL redirection permanent
authored
431 redirect("/gems/#{lib}#{translate_file_links extra}", 301)
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
432 end
177700d @lsegal Big whitespace fix
authored
433
d99b99c @lsegal Make URL redirection permanent
authored
434 get('/docs/?') { redirect('/github', 301) }
177700d @lsegal Big whitespace fix
authored
435
db0ece9 @zapnap redirect old rdoc.info links
zapnap authored
436 # Old URL structure redirection for rdoc.info
437
438 get(%r{^/(?:projects|rdoc)/([^/]+)/([^/]+)(/?.*)}) do |user, proj, extra|
bcf1402 @zapnap strip the blobs from rdoc.info redirects
zapnap authored
439 redirect("/github/#{user}/#{proj}", 301)
db0ece9 @zapnap redirect old rdoc.info links
zapnap authored
440 end
441
03b71d9 @lsegal Add redirects to support old yardoc.org URL structure
authored
442 # Root URL redirection
177700d @lsegal Big whitespace fix
authored
443
524c225 @lsegal Initial commit
authored
444 get '/' do
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
445 @adapter = settings.scm_adapter
caab733 @zapnap add recent projects list to homepage
zapnap authored
446 @libraries = recent_store
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
447 @featured = settings.featured_adapter.libraries if settings.featured_adapter
caab733 @zapnap add recent projects list to homepage
zapnap authored
448 cache erb(:home)
524c225 @lsegal Initial commit
authored
449 end
177700d @lsegal Big whitespace fix
authored
450
524c225 @lsegal Initial commit
authored
451 error do
452 @page_title = "Unknown Error!"
a076f79 @zapnap modern versions of sinatra use settings
zapnap authored
453 @error = "Something quite unexpected just happened.
454 Thanks to <a href='http://airbrake.io'>Airbrake</a> we know about the
455 issue, but feel free to email <a href='mailto:support@rdoc.info'>someone</a>
524c225 @lsegal Initial commit
authored
456 about it."
457 notify_error
458 end
459 end
Something went wrong with that request. Please try again.