diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-04-19 16:24:17 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-21 15:47:23 +0300 |
commit | 34192f2cf9ec37496cece9e771759a0f5de66cbf (patch) | |
tree | 33e03582a1a0188b6500e7ce671f3e4a1d78afaa /app | |
parent | 81112b54051c99c7546b282c47edc176f0aebd40 (diff) | |
download | gitlab-ce-34192f2cf9ec37496cece9e771759a0f5de66cbf.tar.gz |
Merge branch 'rs-issue-2212' into 'master'
Revert and re-fix image rendering in help pages
Closes #2212
See merge request !1765
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/help_controller.rb | 56 | ||||
-rw-r--r-- | app/views/help/show.html.haml | 2 |
2 files changed, 36 insertions, 22 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index 0e5567c7734..35ece5b270b 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -3,40 +3,54 @@ class HelpController < ApplicationController end def show - @filepath = clean_path_info(params[:filepath]) - @format = params[:format] + category = clean_path_info(path_params[:category]) + file = path_params[:file] respond_to do |format| - format.md { render_doc } - format.all { send_file_data } - end - end + format.any(:markdown, :md, :html) do + path = Rails.root.join('doc', category, "#{file}.md") - def shortcuts - end + if File.exist?(path) + @markdown = File.read(path) - private + 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 - def render_doc - if File.exists?(Rails.root.join('doc', @filepath + '.md')) - render 'show.html.haml' - else - not_found! + # Any other format we don't recognize, just respond 404 + format.any { head :not_found } end end - 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 + def shortcuts end def ui end + private + + def path_params + params.require(:category) + params.require(:file) + + params + end + PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact) # Taken from ActionDispatch::FileHandler diff --git a/app/views/help/show.html.haml b/app/views/help/show.html.haml index f22aa92caf7..cc1be6a717a 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', @filepath + '.md')).gsub("$your_email", current_user.email) + = markdown @markdown.gsub('$your_email', current_user.email) |