Commit 94390fc7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Proper routing. blobs for blobs, raw for send_data

parent 88abe66c
......@@ -8,15 +8,6 @@ class BlobController < ProjectResourceController
before_filter :require_non_empty_project
def show
if @tree.is_blob?
send_data(
@tree.data,
type: @tree.mime_type,
disposition: 'inline',
filename: @tree.name
)
else
not_found!
end
@blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
end
end
# Controller for viewing a file's raw
class RawController < ProjectResourceController
include ExtractsPath
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
def show
@blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
if @blob.exists?
send_data(
@blob.data,
type: @blob.mime_type,
disposition: 'inline',
filename: @blob.name
)
else
not_found!
end
end
end
......@@ -18,7 +18,7 @@ module TreeHelper
render partial: 'tree/submodule_item', object: f
else
# Object is a Blob
render partial: 'tree/tree_item', object: f, locals: {type: 'file'}
render partial: 'tree/blob_item', object: f, locals: {type: 'file'}
end
tree += html if html.present?
......
.btn-group.tree-btn-group
-# only show edit link for text files
- if @tree.text?
- if @blob.text?
= link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-tiny", disabled: !allowed_tree_edit?
= link_to "raw", project_blob_path(@project, @id), class: "btn btn-tiny", target: "_blank"
= link_to "raw", project_raw_path(@project, @id), class: "btn btn-tiny", target: "_blank"
-# only show normal/blame view links for text files
- if @tree.text?
- if @blob.text?
- if current_page? project_blame_path(@project, @id)
= link_to "normal view", project_tree_path(@project, @id), class: "btn btn-tiny"
- else
......
%ul.breadcrumb
%li
%i.icon-angle-right
= link_to project_tree_path(@project, @ref) do
= @project.path
- tree_breadcrumbs(@tree, 6) do |title, path|
\/
%li
- if path
= link_to truncate(title, length: 40), project_tree_path(@project, path)
- else
= link_to title, '#'
%div#tree-content-holder.tree-content-holder
.file_holder
.file_title
%i.icon-file
%span.file_name
= blob.name
%small= number_to_human_size blob.size
%span.options= render "actions"
- if blob.text?
= render "text", blob: blob
- elsif blob.image?
= render "image", blob: blob
- else
= render "download", blob: blob
%div.tree-ref-holder
= render 'shared/ref_switcher', destination: 'tree', path: @path
%div#tree-holder.tree-holder
= render 'blob', blob: @blob
:plain
// Load Files list
$("#tree-holder").html("#{escape_javascript(render(partial: "blob", locals: {blob: @blob}))}");
$("#tree-content-holder").show("slide", { direction: "right" }, 400);
$('.project-refs-form #path').val("#{@path}");
// Load last commit log for each file in tree
$('#tree-slider').waitForImages(function() {
ajaxGet('#{@logs_path}');
});
.file_holder
.file_title
%i.icon-file
%span.file_name
= blob.name
%small= number_to_human_size blob.size
%span.options= render "tree/blob_actions"
- if blob.text?
= render "tree/blob/text", blob: blob
- elsif blob.image?
= render "tree/blob/image", blob: blob
- else
= render "tree/blob/download", blob: blob
%tr{ class: "tree-item #{tree_hex_class(blob_item)}" }
%td.tree-item-file-name
= tree_icon(type)
%strong= link_to truncate(blob_item.name, length: 40), project_blob_path(@project, tree_join(@id || @commit.id, blob_item.name))
%td.tree_time_ago.cgray
%span.log_loading.hide
Loading commit data...
= image_tag "ajax_loader_tree.gif", width: 14
%td.tree_commit{ colspan: 2 }
......@@ -39,8 +39,7 @@
%div.tree_progress
- unless tree.is_blob?
:javascript
:javascript
// Load last commit log for each file in tree
$(window).load(function(){
ajaxGet('#{@logs_path}');
......
......@@ -170,6 +170,7 @@ Gitlab::Application.routes.draw do
end
resources :blob, only: [:show], constraints: {id: /.+/}
resources :raw, only: [:show], constraints: {id: /.+/}
resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ }
resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit'
resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/}
......
......@@ -23,7 +23,19 @@ module Gitlab
end
def exists?
@raw_blob
raw_blob
end
def empty?
data.blank?
end
def mode
raw_blob.mode
end
def size
raw_blob.size
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment