summaryrefslogtreecommitdiff
path: root/app/controllers/help_controller.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-04-15 12:45:31 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-04-15 12:45:31 -0400
commit3052e894207303bf9fed972aa60d3a655a6c58d9 (patch)
tree382f089e6e5ba89287bcf5aea6e86e853cf2d307 /app/controllers/help_controller.rb
parente24cb79f3196052395829b35d51693dc9de5afbe (diff)
downloadgitlab-ce-3052e894207303bf9fed972aa60d3a655a6c58d9.tar.gz
Re-fix image rendering for help pages
Diffstat (limited to 'app/controllers/help_controller.rb')
-rw-r--r--app/controllers/help_controller.rb42
1 files changed, 36 insertions, 6 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index 964f624d6d7..10094d86dfb 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -3,13 +3,36 @@ class HelpController < ApplicationController
end
def show
- @category = clean_path_info(params[:category])
- @file = clean_path_info(params[:file])
+ category = clean_path_info(path_params[:category])
+ file = clean_path_info(path_params[:file])
- if File.exists?(Rails.root.join('doc', @category, @file + '.md'))
- render 'show'
- else
- not_found!
+ respond_to do |format|
+ format.any(:markdown, :md, :html) do
+ 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
@@ -21,6 +44,13 @@ class HelpController < ApplicationController
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