Add JSON endpoint to get simple blob viewer
This commit is contained in:
parent
ee17c659dc
commit
121c5f6618
|
@ -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
|
|
@ -2,6 +2,7 @@
|
||||||
class Projects::BlobController < Projects::ApplicationController
|
class Projects::BlobController < Projects::ApplicationController
|
||||||
include ExtractsPath
|
include ExtractsPath
|
||||||
include CreatesCommit
|
include CreatesCommit
|
||||||
|
include RendersBlob
|
||||||
include ActionView::Helpers::SanitizeHelper
|
include ActionView::Helpers::SanitizeHelper
|
||||||
|
|
||||||
# Raised when given an invalid file path
|
# Raised when given an invalid file path
|
||||||
|
@ -34,8 +35,18 @@ class Projects::BlobController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
|
respond_to do |format|
|
||||||
@environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last
|
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
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
Loading…
Reference in New Issue