gitlab-org--gitlab-foss/app/controllers/concerns/renders_blob.rb

41 lines
767 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module RendersBlob
extend ActiveSupport::Concern
2017-08-03 08:29:35 -04:00
def blob_json(blob)
viewer =
2017-05-08 19:50:23 -04:00
case params[:viewer]
when 'rich'
blob.rich_viewer
2017-05-08 19:50:23 -04:00
when 'auxiliary'
blob.auxiliary_viewer
else
blob.simple_viewer
end
2017-08-03 08:29:35 -04:00
return unless viewer
{
html: view_to_html_string("projects/blob/_viewer", viewer: viewer, load_async: false)
}
end
def render_blob_json(blob)
json = blob_json(blob)
return render_404 unless json
render json: json
end
2017-04-13 12:47:28 -04:00
def conditionally_expand_blob(blob)
conditionally_expand_blobs([blob])
end
def conditionally_expand_blobs(blobs)
return unless params[:expanded] == 'true'
blobs.each { |blob| blob.expand! }
2017-04-13 12:47:28 -04:00
end
end