Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prepend 'git-' to man pages

This allows for shorter URLs like /docs/commit that will redirect to the
correct ones.
  • Loading branch information...
commit e93b1f16b27f5090f531000d4aef7f3f8445a5f6 1 parent 4fba176
@koraktor koraktor authored
View
19 app/controllers/doc_controller.rb
@@ -51,10 +51,11 @@ def man
@cache_key = "man-#{filename}-#{latest}-#{version}"
if !Rails.cache.exist?("views/" + @cache_key)
- if params[:version]
- doc_version = DocVersion.for_version(filename, params[:version])
- else
- doc_version = DocVersion.latest_for(filename)
+ doc_version = doc_for filename, version
+ if doc_version.nil?
+ filename = "git-#{filename}"
+ doc_version = doc_for filename, version
+ redirect_to doc_file_url(filename) unless doc_version.nil?
end
if doc_version.nil?
@@ -191,4 +192,14 @@ def watch
def ext
end
+ private
+
+ def doc_for(filename, version = nil)
+ if version
+ doc_version = DocVersion.for_version filename, version
+ else
+ doc_version = DocVersion.latest_for filename
+ end
+ end
+
end
View
8 config/routes.rb
@@ -12,12 +12,12 @@
root :to => 'site#redirect_book'
match '*path' => 'site#redirect_combook'
end
-
+
get "site/index"
match "/doc" => "doc#index"
match "/docs" => "doc#ref"
- match "/docs/:file" => "doc#man"
+ match "/docs/:file" => "doc#man", :as => :doc_file
match "/docs/:file/:version" => "doc#man", :version => /[^\/]+/
match "/test" => "doc#test"
match "/doc/ext" => "doc#ext"
@@ -34,8 +34,8 @@
match "/book/:lang/:slug" => "doc#book_section"
match "/publish" => "doc#book_update"
match "/related" => "doc#related_update"
- match "/:year/:month/:day/:slug" => "doc#blog", :year => /\d{4}/,
- :month => /\d{2}/,
+ match "/:year/:month/:day/:slug" => "doc#blog", :year => /\d{4}/,
+ :month => /\d{2}/,
:day => /\d{2}/
match "/about" => "about#index"
View
10 test/functional/doc_controller_test.rb
@@ -28,4 +28,14 @@ class DocControllerTest < ActionController::TestCase
get :man, :file => 'test-command', :version => 'v1.0'
assert_response :success
end
+
+ test "tries to prepend 'git-' to find a command" do
+ file = FactoryGirl.create(:doc_file, :name => 'git-commit')
+ doc = FactoryGirl.create(:doc, :plain => "Doc 1")
+ vers = FactoryGirl.create(:version, :name => "v1.0")
+ dver = FactoryGirl.create(:doc_version, :doc_file => file, :version => vers, :doc => doc)
+ get :man, :file => 'commit', :version => 'v1.0'
+ assert_response :success
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.