Class: Projects::BlobController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::SanitizeHelper, CreatesCommit, ExtractsPath
Defined in:
app/controllers/projects/blob_controller.rb

Overview

Controller for viewing a file's blame

Defined Under Namespace

Classes: InvalidPathError

Instance Method Summary collapse

Methods included from CreatesCommit

#authorize_edit_tree!, #create_commit

Methods included from ExtractsPath

#assign_ref_vars, #extract_ref, #tree

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#createObject


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

def create
  create_commit(Files::CreateService, success_notice: "The file has been successfully created.",
                                      success_path: namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path)),
                                      failure_view: :new,
                                      failure_path: namespace_project_new_blob_path(@project.namespace, @project, @ref))
end

#destroyObject


64
65
66
67
68
69
# File 'app/controllers/projects/blob_controller.rb', line 64

def destroy
  create_commit(Files::DeleteService, success_notice: "The file has been successfully deleted.",
                                      success_path: namespace_project_tree_path(@project.namespace, @project, @target_branch),
                                      failure_view: :show,
                                      failure_path: namespace_project_blob_path(@project.namespace, @project, @id))
end

#diffObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/projects/blob_controller.rb', line 71

def diff
  @form  = UnfoldForm.new(params)
  @lines = Gitlab::Highlight.highlight_lines(repository, @ref, @path)
  @lines = @lines[@form.since - 1..@form.to - 1]

  if @form.bottom?
    @match_line = ''
  else
    lines_length = @lines.length - 1
    line = [@form.since, lines_length].join(',')
    @match_line = "@@ -#{line}+#{line} @@"
  end

  render layout: false
end

#editObject


34
35
36
37
# File 'app/controllers/projects/blob_controller.rb', line 34

def edit
  @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha
  blob.load_all_data!(@repository)
end

#newObject


20
21
22
# File 'app/controllers/projects/blob_controller.rb', line 20

def new
  commit unless @repository.empty?
end

#previewObject


53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/projects/blob_controller.rb', line 53

def preview
  @content = params[:content]
  @blob.load_all_data!(@repository)
  diffy = Diffy::Diff.new(@blob.data, @content, diff: '-U 3', include_diff_info: true)
  diff_lines = diffy.diff.scan(/.*\n/)[2..-1]
  diff_lines = Gitlab::Diff::Parser.new.parse(diff_lines)
  @diff_lines = Gitlab::Diff::Highlight.new(diff_lines).highlight

  render layout: false
end

#showObject


31
32
# File 'app/controllers/projects/blob_controller.rb', line 31

def show
end

#updateObject


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/projects/blob_controller.rb', line 39

def update
  after_edit_path =
    if from_merge_request && @target_branch == @ref
      diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) +
        "#file-path-#{hexdigest(@path)}"
    else
      namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path))
    end

  create_commit(Files::UpdateService, success_path: after_edit_path,
                                      failure_view: :edit,
                                      failure_path: namespace_project_blob_path(@project.namespace, @project, @id))
end