Module: RendersBlob

Extended by:
ActiveSupport::Concern
Included in:
Projects::ArtifactsController, Projects::BlobController, Projects::BuildArtifactsController, SnippetsActions
Defined in:
app/controllers/concerns/renders_blob.rb

Instance Method Summary collapse

Instance Method Details

#blob_json(blob) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/concerns/renders_blob.rb', line 6

def blob_json(blob)
  viewer =
    case params[:viewer]
    when 'rich'
      blob.rich_viewer
    when 'auxiliary'
      blob.auxiliary_viewer
    else
      blob.simple_viewer
    end

  return unless viewer

  {
    html: view_to_html_string("projects/blob/_viewer", viewer: viewer, load_async: false)
  }
end

#conditionally_expand_blob(blob) ⇒ Object


31
32
33
# File 'app/controllers/concerns/renders_blob.rb', line 31

def conditionally_expand_blob(blob)
  conditionally_expand_blobs([blob])
end

#conditionally_expand_blobs(blobs) ⇒ Object


35
36
37
38
39
# File 'app/controllers/concerns/renders_blob.rb', line 35

def conditionally_expand_blobs(blobs)
  return unless params[:expanded] == 'true'

  blobs.each { |blob| blob.expand! }
end

#render_blob_json(blob) ⇒ Object


24
25
26
27
28
29
# File 'app/controllers/concerns/renders_blob.rb', line 24

def render_blob_json(blob)
  json = blob_json(blob)
  return render_404 unless json

  render json: json
end