2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module RendersBlob
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def blob_json(blob)
|
2017-08-17 22:00:37 +05:30
|
|
|
viewer =
|
2017-09-10 17:25:29 +05:30
|
|
|
case params[:viewer]
|
|
|
|
when 'rich'
|
2017-08-17 22:00:37 +05:30
|
|
|
blob.rich_viewer
|
2017-09-10 17:25:29 +05:30
|
|
|
when 'auxiliary'
|
|
|
|
blob.auxiliary_viewer
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
blob.simple_viewer
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
return unless viewer
|
|
|
|
|
|
|
|
{
|
|
|
|
html: view_to_html_string("projects/blob/_viewer", viewer: viewer, load_async: false)
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def render_blob_json(blob)
|
|
|
|
json = blob_json(blob)
|
|
|
|
return render_404 unless json
|
|
|
|
|
|
|
|
render json: json
|
|
|
|
end
|
|
|
|
|
|
|
|
def conditionally_expand_blob(blob)
|
|
|
|
blob.expand! if params[:expanded] == 'true'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|