diff --git a/CHANGELOG b/CHANGELOG index 7b410dfe85e531c0616df1d54f634f736897255b..db3e5744b0e2c31320688ae1b925ab87f05f497c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -61,6 +61,7 @@ v 7.10.0 (unreleased) - Import GitHub, Bitbucket or GitLab.com projects owned by authenticated user into current namespace. - Project labels are now available over the API under the "tag_list" field (Cristian Medina) - Fixed link paths for HTTP and SSH on the admin project view (Jeremy Maziarz) + - Fix and improve help rendering (Sullivan Sénéchal) v 7.9.2 diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index c4d620d87b15d2e84bdd1128976d4d2205c1f612..fbd9e67e6df931baa69fef9d7cd36fb90d437648 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -3,17 +3,35 @@ class HelpController < ApplicationController end def show - @category = params[:category] - @file = params[:file] + @filepath = params[:filepath] + @format = params[:format] - if File.exists?(Rails.root.join('doc', @category, @file + '.md')) - render 'show' + respond_to do |format| + format.md { render_doc } + format.all { send_file_data } + end + end + + def shortcuts + end + + private + + def render_doc + if File.exists?(Rails.root.join('doc', @filepath + '.md')) + render 'show.html.haml' else not_found! end end - def shortcuts + def send_file_data + path = Rails.root.join('doc', "#{@filepath}.#{@format}") + if File.exists?(path) + send_file(path, disposition: 'inline') + else + head :not_found + end end def ui diff --git a/app/views/help/show.html.haml b/app/views/help/show.html.haml index eca34dbff06fabb474c16aab5517d9585e58601d..f22aa92caf7435ee9fc81faf763df144bbc08ac2 100644 --- a/app/views/help/show.html.haml +++ b/app/views/help/show.html.haml @@ -1,2 +1,2 @@ .documentation.wiki - = markdown File.read(Rails.root.join('doc', @category, @file + '.md')).gsub("$your_email", current_user.email) + = markdown File.read(Rails.root.join('doc', @filepath + '.md')).gsub("$your_email", current_user.email) diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 8f8bef42befd6c13ced10f6345d7d40cb7bec968..6978ad9302402ed85db235d392997f1f5fc969ba 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -6,3 +6,4 @@ Mime::Type.register_alias "text/plain", :diff Mime::Type.register_alias "text/plain", :patch +Mime::Type.register_alias 'text/html', :md diff --git a/config/routes.rb b/config/routes.rb index 388858d2670ae582440b2b18762f0b7f431bf033..c1b85b025b5777a9d1058581c5e54b8271f1507f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,9 +39,9 @@ Gitlab::Application.routes.draw do # Help get 'help' => 'help#index' - get 'help/:category/:file' => 'help#show', as: :help_page get 'help/shortcuts' get 'help/ui' => 'help#ui' + get 'help/:filepath' => 'help#show', as: :help_page, constraints: { filepath: /[^\.]+/ } # # Global snippets diff --git a/features/steps/dashboard/help.rb b/features/steps/dashboard/help.rb index ef433c57c6eebfc4dfafd134e8053484eba03e9c..fa52e391f05bbe7273d8300ff66410bdf427cb18 100644 --- a/features/steps/dashboard/help.rb +++ b/features/steps/dashboard/help.rb @@ -8,7 +8,7 @@ class Spinach::Features::DashboardHelp < Spinach::FeatureSteps end step 'I visit the "Rake Tasks" help page' do - visit help_page_path("raketasks", "maintenance") + visit help_page_path('raketasks/maintenance', format: 'md') end step 'I should see "Rake Tasks" page markdown rendered' do diff --git a/spec/features/help_pages_spec.rb b/spec/features/help_pages_spec.rb index 41088ce8271922233d38e1fcf24e49081e8aa8a5..28423eb8caa5568c3a75e5fe39f5783f28dee6ad 100644 --- a/spec/features/help_pages_spec.rb +++ b/spec/features/help_pages_spec.rb @@ -6,7 +6,7 @@ describe 'Help Pages', feature: true do login_as :user end it 'replace the variable $your_email with the email of the user' do - visit help_page_path(category: 'ssh', file: 'README.md') + visit help_page_path(filepath: 'ssh/README', format: 'md') expect(page).to have_content("ssh-keygen -t rsa -C \"#{@user.email}\"") end end diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index d4915b519520e240510600df21d529cdb9c911b6..f5db548f97c8f8f1dc5cd79e4e74da71180bd320 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -73,41 +73,41 @@ end # help_markdown GET /help/markdown(.:format) help#markdown # help_ssh GET /help/ssh(.:format) help#ssh # help_raketasks GET /help/raketasks(.:format) help#raketasks -describe HelpController, "routing" do - it "to #index" do - expect(get("/help")).to route_to('help#index') +describe HelpController, 'routing' do + it 'to #index' do + expect(get('/help')).to route_to('help#index') end - it "to #permissions" do - expect(get("/help/permissions/permissions")).to route_to('help#show', category: "permissions", file: "permissions") + it 'to #permissions' do + expect(get('/help/permissions/permissions')).to route_to('help#show', filepath: 'permissions/permissions') end - it "to #workflow" do - expect(get("/help/workflow/README")).to route_to('help#show', category: "workflow", file: "README") + it 'to #workflow' do + expect(get('/help/workflow/README')).to route_to('help#show', filepath: 'workflow/README') end - it "to #api" do - expect(get("/help/api/README")).to route_to('help#show', category: "api", file: "README") + it 'to #api' do + expect(get('/help/api/README')).to route_to('help#show', filepath: 'api/README') end - it "to #web_hooks" do - expect(get("/help/web_hooks/web_hooks")).to route_to('help#show', category: "web_hooks", file: "web_hooks") + it 'to #web_hooks' do + expect(get('/help/web_hooks/web_hooks')).to route_to('help#show', filepath: 'web_hooks/web_hooks') end - it "to #system_hooks" do - expect(get("/help/system_hooks/system_hooks")).to route_to('help#show', category: "system_hooks", file: "system_hooks") + it 'to #system_hooks' do + expect(get('/help/system_hooks/system_hooks')).to route_to('help#show', filepath: 'system_hooks/system_hooks') end - it "to #markdown" do - expect(get("/help/markdown/markdown")).to route_to('help#show',category: "markdown", file: "markdown") + it 'to #markdown' do + expect(get('/help/markdown/markdown')).to route_to('help#show',filepath: 'markdown/markdown') end - it "to #ssh" do - expect(get("/help/ssh/README")).to route_to('help#show', category: "ssh", file: "README") + it 'to #ssh' do + expect(get('/help/ssh/README')).to route_to('help#show', filepath: 'ssh/README') end - it "to #raketasks" do - expect(get("/help/raketasks/README")).to route_to('help#show', category: "raketasks", file: "README") + it 'to #raketasks' do + expect(get('/help/raketasks/README')).to route_to('help#show', filepath: 'raketasks/README') end end