diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-13 12:10:21 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:26 -0500 |
commit | 121c5f66180acd78cedf18b19b0e86ee5bf1204d (patch) | |
tree | cec9700bc7b076381d8275fbcbb0013e82b01c49 /app | |
parent | ee17c659dc3899802ff3a21ddcab0c943d13dd53 (diff) | |
download | gitlab-ce-121c5f66180acd78cedf18b19b0e86ee5bf1204d.tar.gz |
Add JSON endpoint to get simple blob viewer
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/renders_blob.rb | 17 | ||||
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 15 |
2 files changed, 30 insertions, 2 deletions
diff --git a/app/controllers/concerns/renders_blob.rb b/app/controllers/concerns/renders_blob.rb new file mode 100644 index 00000000000..ab9f0d01c7b --- /dev/null +++ b/app/controllers/concerns/renders_blob.rb @@ -0,0 +1,17 @@ +module RendersBlob + extend ActiveSupport::Concern + + def render_blob_json(blob) + viewer = + if params[:viewer] == 'rich' + blob.rich_viewer + else + blob.simple_viewer + end + return render_404 unless viewer + + render json: { + html: view_to_html_string("projects/blob/_viewer", viewer: viewer) + } + end +end diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 4c6db91d7c0..173c6bcee53 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -2,6 +2,7 @@ class Projects::BlobController < Projects::ApplicationController include ExtractsPath include CreatesCommit + include RendersBlob include ActionView::Helpers::SanitizeHelper # Raised when given an invalid file path @@ -34,8 +35,18 @@ class Projects::BlobController < Projects::ApplicationController end def show - environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit } - @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last + respond_to do |format| + format.html do + environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit } + @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last + + render 'show' + end + + format.json do + render_blob_json(@blob) + end + end end def edit |