Permalink
Browse files

Server displays README on index route if available.

Renames the index route to /docs/[library/]index.

Closes #385
  • Loading branch information...
1 parent 2063c21 commit 050518e88af4dd92a563205bb95c539b5794d76d @lsegal committed Apr 29, 2012
@@ -3,8 +3,20 @@ module Server
module Commands
# Displays documentation for a specific object identified by the path
class DisplayObjectCommand < LibraryCommand
+ include DocServerHelper
+
def run
- return index if path.empty?
+ if path.empty?
+ if options.readme
+ url = url_for_file(options.readme)
+ self.status, self.headers, self.body = *router.send(:route, url)
+ cache(body.first)
+ return
+ else
+ self.path = 'index'
+ end
+ end
+ return index if path == 'index'
if object = Registry.at(object_path)
options.update(:type => :layout)
@@ -17,14 +29,9 @@ def run
def index
Registry.load_all
- title = options[:title]
- unless title
- title = "Documentation for #{library.name} #{library.version ? '(' + library.version + ')' : ''}"
- end
options.update(
:object => '_index.html',
:objects => Registry.all(:module, :class),
- :title => title,
:type => :layout
)
render
@@ -9,6 +9,7 @@ module DocServerHelper
# @return (see Templates::Helpers::HtmlHelper#url_for)
def url_for(obj, anchor = nil, relative = false)
return '' if obj.nil?
+ return url_for_index if obj == '_index.html'
return "/#{obj}" if String === obj
File.join('', base_path(router.docs_prefix), super(obj, anchor, false))
end
@@ -54,7 +55,7 @@ def url_for_main
# Returns the URL for the alphabetic index page
# @return (see Templates::Helpers::HtmlHelper#url_for_index)
def url_for_index
- File.join('', base_path(router.docs_prefix))
+ File.join('', base_path(router.docs_prefix), 'index')
end
# @example The base path for a library 'foo'
@@ -97,8 +97,8 @@ def parse_library_from_path(paths)
#
# @return [Array(Numeric,Hash,Array<String>)] the Rack-style response
# @return [nil] if no route is matched
- def route
- path = request.path.gsub(%r{//+}, '/').gsub(%r{^/|/$}, '')
+ def route(path = request.path)
+ path = path.gsub(%r{//+}, '/').gsub(%r{^/|/$}, '')
return route_index if path.empty? || path == docs_prefix
case path
when /^(#{docs_prefix}|#{list_prefix}|#{search_prefix})(\/.*|$)/
@@ -31,13 +31,13 @@
<% end %>
<% if object.is_a?(CodeObjects::Base) && @file.nil? %>
<% unless @single_library %>&raquo;<% end %>
- <a href="/<%= base_path(router.docs_prefix) %>"><% if object.root? || object.type == :method %>Index<% else %>Index (<%= object.name.to_s[0] %>)<% end %></a> &raquo;
+ <a href="<%= url_for_index %>"><% if object.root? || object.type == :method %>Index<% else %>Index (<%= object.name.to_s[0] %>)<% end %></a> &raquo;
<%= @breadcrumb.map {|obj| "<span class='title'>" + linkify(obj, obj.name) + "</span>" }.join(" &raquo; ") %>
<%= @breadcrumb.size > 0 ? " &raquo; " : "" %>
<span class='title'><%= object.root? ? "Top Level Namespace" : object.name(true) %></span>
<% else %>
<% if (@breadcrumb_title || object != '_index.html') && !@single_library %>&raquo; <% end %>
- <% if object != '_index.html' %><a href="/<%= base_path(router.docs_prefix) %>">Index</a> &raquo; <% end %>
+ <% if object != '_index.html' %><a href="<%= url_for_index %>">Index</a> &raquo; <% end %>
<span class='title'><%= @breadcrumb_title %></span>
<% end %>

0 comments on commit 050518e

Please sign in to comment.