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 12:29:35 +00:00
def blob_json(blob)
viewer =
2017-05-08 23:50:23 +00:00
case params[:viewer]
when 'rich'
blob.rich_viewer
2017-05-08 23:50:23 +00:00
when 'auxiliary'
blob.auxiliary_viewer
else
blob.simple_viewer
end
2017-08-03 12:29:35 +00: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 16:47:28 +00: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 16:47:28 +00:00
end
end