Merge branch 'rs-issue-2212' into 'master'
Revert and re-fix image rendering in help pages Closes #2212 See merge request !1765
This commit is contained in:
commit
359f01c9e0
8 changed files with 125 additions and 64 deletions
|
@ -3,38 +3,52 @@ class HelpController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@filepath = clean_path_info(params[:filepath])
|
category = clean_path_info(path_params[:category])
|
||||||
@format = params[:format]
|
file = path_params[:file]
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.md { render_doc }
|
format.any(:markdown, :md, :html) do
|
||||||
format.all { send_file_data }
|
path = Rails.root.join('doc', category, "#{file}.md")
|
||||||
|
|
||||||
|
if File.exist?(path)
|
||||||
|
@markdown = File.read(path)
|
||||||
|
|
||||||
|
render 'show.html.haml'
|
||||||
|
else
|
||||||
|
# Force template to Haml
|
||||||
|
render 'errors/not_found.html.haml', layout: 'errors', status: 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Allow access to images in the doc folder
|
||||||
|
format.any(:png, :gif, :jpeg) do
|
||||||
|
path = Rails.root.join('doc', category, "#{file}.#{params[:format]}")
|
||||||
|
|
||||||
|
if File.exist?(path)
|
||||||
|
send_file(path, disposition: 'inline')
|
||||||
|
else
|
||||||
|
head :not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Any other format we don't recognize, just respond 404
|
||||||
|
format.any { head :not_found }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def shortcuts
|
def shortcuts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ui
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_doc
|
def path_params
|
||||||
if File.exists?(Rails.root.join('doc', @filepath + '.md'))
|
params.require(:category)
|
||||||
render 'show.html.haml'
|
params.require(:file)
|
||||||
else
|
|
||||||
not_found!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_file_data
|
params
|
||||||
path = Rails.root.join('doc', "#{@filepath}.#{@format}")
|
|
||||||
if File.exists?(path)
|
|
||||||
send_file(path, disposition: 'inline')
|
|
||||||
else
|
|
||||||
head :not_found
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def ui
|
|
||||||
end
|
end
|
||||||
|
|
||||||
PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
|
PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
.documentation.wiki
|
.documentation.wiki
|
||||||
= markdown File.read(Rails.root.join('doc', @filepath + '.md')).gsub("$your_email", current_user.email)
|
= markdown @markdown.gsub('$your_email', current_user.email)
|
||||||
|
|
|
@ -6,4 +6,5 @@
|
||||||
|
|
||||||
Mime::Type.register_alias "text/plain", :diff
|
Mime::Type.register_alias "text/plain", :diff
|
||||||
Mime::Type.register_alias "text/plain", :patch
|
Mime::Type.register_alias "text/plain", :patch
|
||||||
Mime::Type.register_alias 'text/html', :md
|
Mime::Type.register_alias 'text/html', :markdown
|
||||||
|
Mime::Type.register_alias 'text/html', :md
|
||||||
|
|
|
@ -39,9 +39,9 @@ Gitlab::Application.routes.draw do
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
get 'help' => 'help#index'
|
get 'help' => 'help#index'
|
||||||
|
get 'help/:category/:file' => 'help#show', as: :help_page, constraints: { category: /.*/, file: /[^\/\.]+/ }
|
||||||
get 'help/shortcuts'
|
get 'help/shortcuts'
|
||||||
get 'help/ui' => 'help#ui'
|
get 'help/ui' => 'help#ui'
|
||||||
get 'help/:filepath' => 'help#show', as: :help_page, constraints: { filepath: /[^\.]+/ }
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Global snippets
|
# Global snippets
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Spinach::Features::DashboardHelp < Spinach::FeatureSteps
|
||||||
end
|
end
|
||||||
|
|
||||||
step 'I visit the "Rake Tasks" help page' do
|
step 'I visit the "Rake Tasks" help page' do
|
||||||
visit help_page_path('raketasks/maintenance', format: 'md')
|
visit help_page_path("raketasks", "maintenance")
|
||||||
end
|
end
|
||||||
|
|
||||||
step 'I should see "Rake Tasks" page markdown rendered' do
|
step 'I should see "Rake Tasks" page markdown rendered' do
|
||||||
|
|
61
spec/controllers/help_controller_spec.rb
Normal file
61
spec/controllers/help_controller_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe HelpController do
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #show' do
|
||||||
|
context 'for Markdown formats' do
|
||||||
|
context 'when requested file exists' do
|
||||||
|
before do
|
||||||
|
get :show, category: 'ssh', file: 'README', format: :md
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns to @markdown' do
|
||||||
|
expect(assigns[:markdown]).not_to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders HTML' do
|
||||||
|
expect(response).to render_template('show.html.haml')
|
||||||
|
expect(response.content_type).to eq 'text/html'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when requested file is missing' do
|
||||||
|
it 'renders not found' do
|
||||||
|
get :show, category: 'foo', file: 'bar', format: :md
|
||||||
|
expect(response).to be_not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for image formats' do
|
||||||
|
context 'when requested file exists' do
|
||||||
|
it 'renders the raw file' do
|
||||||
|
get :show, category: 'workflow/protected_branches',
|
||||||
|
file: 'protected_branches1', format: :png
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(response.content_type).to eq 'image/png'
|
||||||
|
expect(response.headers['Content-Disposition']).to match(/^inline;/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when requested file is missing' do
|
||||||
|
it 'renders not found' do
|
||||||
|
get :show, category: 'foo', file: 'bar', format: :png
|
||||||
|
expect(response).to be_not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for other formats' do
|
||||||
|
it 'always renders not found' do
|
||||||
|
get :show, category: 'ssh', file: 'README', format: :foo
|
||||||
|
expect(response).to be_not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,7 +6,7 @@ describe 'Help Pages', feature: true do
|
||||||
login_as :user
|
login_as :user
|
||||||
end
|
end
|
||||||
it 'replace the variable $your_email with the email of the user' do
|
it 'replace the variable $your_email with the email of the user' do
|
||||||
visit help_page_path(filepath: 'ssh/README', format: 'md')
|
visit help_page_path('ssh', 'README')
|
||||||
expect(page).to have_content("ssh-keygen -t rsa -C \"#{@user.email}\"")
|
expect(page).to have_content("ssh-keygen -t rsa -C \"#{@user.email}\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,50 +64,35 @@ describe SnippetsController, "routing" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# help GET /help(.:format) help#index
|
# help GET /help(.:format) help#index
|
||||||
# help_permissions GET /help/permissions(.:format) help#permissions
|
# help_page GET /help/:category/:file(.:format) help#show {:category=>/.*/, :file=>/[^\/\.]+/}
|
||||||
# help_workflow GET /help/workflow(.:format) help#workflow
|
# help_shortcuts GET /help/shortcuts(.:format) help#shortcuts
|
||||||
# help_api GET /help/api(.:format) help#api
|
# help_ui GET /help/ui(.:format) help#ui
|
||||||
# help_web_hooks GET /help/web_hooks(.:format) help#web_hooks
|
describe HelpController, "routing" do
|
||||||
# help_system_hooks GET /help/system_hooks(.:format) help#system_hooks
|
it "to #index" do
|
||||||
# help_markdown GET /help/markdown(.:format) help#markdown
|
expect(get("/help")).to route_to('help#index')
|
||||||
# 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')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'to #permissions' do
|
it 'to #show' do
|
||||||
expect(get('/help/permissions/permissions')).to route_to('help#show', filepath: 'permissions/permissions')
|
path = '/help/markdown/markdown.md'
|
||||||
|
expect(get(path)).to route_to('help#show',
|
||||||
|
category: 'markdown',
|
||||||
|
file: 'markdown',
|
||||||
|
format: 'md')
|
||||||
|
|
||||||
|
path = '/help/workflow/protected_branches/protected_branches1.png'
|
||||||
|
expect(get(path)).to route_to('help#show',
|
||||||
|
category: 'workflow/protected_branches',
|
||||||
|
file: 'protected_branches1',
|
||||||
|
format: 'png')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'to #workflow' do
|
it 'to #shortcuts' do
|
||||||
expect(get('/help/workflow/README')).to route_to('help#show', filepath: 'workflow/README')
|
expect(get('/help/shortcuts')).to route_to('help#shortcuts')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'to #api' do
|
it 'to #ui' do
|
||||||
expect(get('/help/api/README')).to route_to('help#show', filepath: 'api/README')
|
expect(get('/help/ui')).to route_to('help#ui')
|
||||||
end
|
|
||||||
|
|
||||||
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', filepath: 'system_hooks/system_hooks')
|
|
||||||
end
|
|
||||||
|
|
||||||
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', filepath: 'ssh/README')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'to #raketasks' do
|
|
||||||
expect(get('/help/raketasks/README')).to route_to('help#show', filepath: 'raketasks/README')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue