Commit 94390fc7b42e92d4e1d38c8392a2e310a256c4ca
1 parent
88abe66c
Exists in
master
and in
4 other branches
Proper routing. blobs for blobs, raw for send_data
Showing
19 changed files
with
132 additions
and
67 deletions
Show diff stats
app/controllers/blob_controller.rb
@@ -8,15 +8,6 @@ class BlobController < ProjectResourceController | @@ -8,15 +8,6 @@ class BlobController < ProjectResourceController | ||
8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
9 | 9 | ||
10 | def show | 10 | def show |
11 | - if @tree.is_blob? | ||
12 | - send_data( | ||
13 | - @tree.data, | ||
14 | - type: @tree.mime_type, | ||
15 | - disposition: 'inline', | ||
16 | - filename: @tree.name | ||
17 | - ) | ||
18 | - else | ||
19 | - not_found! | ||
20 | - end | 11 | + @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) |
21 | end | 12 | end |
22 | end | 13 | end |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +# Controller for viewing a file's raw | ||
2 | +class RawController < ProjectResourceController | ||
3 | + include ExtractsPath | ||
4 | + | ||
5 | + # Authorize | ||
6 | + before_filter :authorize_read_project! | ||
7 | + before_filter :authorize_code_access! | ||
8 | + before_filter :require_non_empty_project | ||
9 | + | ||
10 | + def show | ||
11 | + @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) | ||
12 | + | ||
13 | + if @blob.exists? | ||
14 | + send_data( | ||
15 | + @blob.data, | ||
16 | + type: @blob.mime_type, | ||
17 | + disposition: 'inline', | ||
18 | + filename: @blob.name | ||
19 | + ) | ||
20 | + else | ||
21 | + not_found! | ||
22 | + end | ||
23 | + end | ||
24 | +end | ||
25 | + |
app/helpers/tree_helper.rb
@@ -18,7 +18,7 @@ module TreeHelper | @@ -18,7 +18,7 @@ module TreeHelper | ||
18 | render partial: 'tree/submodule_item', object: f | 18 | render partial: 'tree/submodule_item', object: f |
19 | else | 19 | else |
20 | # Object is a Blob | 20 | # Object is a Blob |
21 | - render partial: 'tree/tree_item', object: f, locals: {type: 'file'} | 21 | + render partial: 'tree/blob_item', object: f, locals: {type: 'file'} |
22 | end | 22 | end |
23 | 23 | ||
24 | tree += html if html.present? | 24 | tree += html if html.present? |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +.btn-group.tree-btn-group | ||
2 | + -# only show edit link for text files | ||
3 | + - if @blob.text? | ||
4 | + = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-tiny", disabled: !allowed_tree_edit? | ||
5 | + = link_to "raw", project_raw_path(@project, @id), class: "btn btn-tiny", target: "_blank" | ||
6 | + -# only show normal/blame view links for text files | ||
7 | + - if @blob.text? | ||
8 | + - if current_page? project_blame_path(@project, @id) | ||
9 | + = link_to "normal view", project_tree_path(@project, @id), class: "btn btn-tiny" | ||
10 | + - else | ||
11 | + = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" | ||
12 | + = link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny" |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +%ul.breadcrumb | ||
2 | + %li | ||
3 | + %i.icon-angle-right | ||
4 | + = link_to project_tree_path(@project, @ref) do | ||
5 | + = @project.path | ||
6 | + - tree_breadcrumbs(@tree, 6) do |title, path| | ||
7 | + \/ | ||
8 | + %li | ||
9 | + - if path | ||
10 | + = link_to truncate(title, length: 40), project_tree_path(@project, path) | ||
11 | + - else | ||
12 | + = link_to title, '#' | ||
13 | + | ||
14 | +%div#tree-content-holder.tree-content-holder | ||
15 | + .file_holder | ||
16 | + .file_title | ||
17 | + %i.icon-file | ||
18 | + %span.file_name | ||
19 | + = blob.name | ||
20 | + %small= number_to_human_size blob.size | ||
21 | + %span.options= render "actions" | ||
22 | + - if blob.text? | ||
23 | + = render "text", blob: blob | ||
24 | + - elsif blob.image? | ||
25 | + = render "image", blob: blob | ||
26 | + - else | ||
27 | + = render "download", blob: blob |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +- if gitlab_markdown?(blob.name) | ||
2 | + .file_content.wiki | ||
3 | + = preserve do | ||
4 | + = markdown(blob.data) | ||
5 | +- elsif markup?(blob.name) | ||
6 | + .file_content.wiki | ||
7 | + = raw GitHub::Markup.render(blob.name, blob.data) | ||
8 | +- else | ||
9 | + .file_content.code | ||
10 | + - unless blob.empty? | ||
11 | + %div{class: user_color_scheme_class} | ||
12 | + = raw blob.colorize(formatter: :gitlab) | ||
13 | + - else | ||
14 | + %p.nothing_here_message Empty file |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +:plain | ||
2 | + // Load Files list | ||
3 | + $("#tree-holder").html("#{escape_javascript(render(partial: "blob", locals: {blob: @blob}))}"); | ||
4 | + $("#tree-content-holder").show("slide", { direction: "right" }, 400); | ||
5 | + $('.project-refs-form #path').val("#{@path}"); | ||
6 | + | ||
7 | + // Load last commit log for each file in tree | ||
8 | + $('#tree-slider').waitForImages(function() { | ||
9 | + ajaxGet('#{@logs_path}'); | ||
10 | + }); |
app/views/tree/_blob.html.haml
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -.file_holder | ||
2 | - .file_title | ||
3 | - %i.icon-file | ||
4 | - %span.file_name | ||
5 | - = blob.name | ||
6 | - %small= number_to_human_size blob.size | ||
7 | - %span.options= render "tree/blob_actions" | ||
8 | - - if blob.text? | ||
9 | - = render "tree/blob/text", blob: blob | ||
10 | - - elsif blob.image? | ||
11 | - = render "tree/blob/image", blob: blob | ||
12 | - - else | ||
13 | - = render "tree/blob/download", blob: blob |
app/views/tree/_blob_actions.html.haml
@@ -1,12 +0,0 @@ | @@ -1,12 +0,0 @@ | ||
1 | -.btn-group.tree-btn-group | ||
2 | - -# only show edit link for text files | ||
3 | - - if @tree.text? | ||
4 | - = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-tiny", disabled: !allowed_tree_edit? | ||
5 | - = link_to "raw", project_blob_path(@project, @id), class: "btn btn-tiny", target: "_blank" | ||
6 | - -# only show normal/blame view links for text files | ||
7 | - - if @tree.text? | ||
8 | - - if current_page? project_blame_path(@project, @id) | ||
9 | - = link_to "normal view", project_tree_path(@project, @id), class: "btn btn-tiny" | ||
10 | - - else | ||
11 | - = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" | ||
12 | - = link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny" |
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +%tr{ class: "tree-item #{tree_hex_class(blob_item)}" } | ||
2 | + %td.tree-item-file-name | ||
3 | + = tree_icon(type) | ||
4 | + %strong= link_to truncate(blob_item.name, length: 40), project_blob_path(@project, tree_join(@id || @commit.id, blob_item.name)) | ||
5 | + %td.tree_time_ago.cgray | ||
6 | + %span.log_loading.hide | ||
7 | + Loading commit data... | ||
8 | + = image_tag "ajax_loader_tree.gif", width: 14 | ||
9 | + %td.tree_commit{ colspan: 2 } |
app/views/tree/_tree.html.haml
@@ -39,9 +39,8 @@ | @@ -39,9 +39,8 @@ | ||
39 | 39 | ||
40 | %div.tree_progress | 40 | %div.tree_progress |
41 | 41 | ||
42 | -- unless tree.is_blob? | ||
43 | - :javascript | ||
44 | - // Load last commit log for each file in tree | ||
45 | - $(window).load(function(){ | ||
46 | - ajaxGet('#{@logs_path}'); | ||
47 | - }); | 42 | +:javascript |
43 | + // Load last commit log for each file in tree | ||
44 | + $(window).load(function(){ | ||
45 | + ajaxGet('#{@logs_path}'); | ||
46 | + }); |
app/views/tree/blob/_download.html.haml
app/views/tree/blob/_image.html.haml
app/views/tree/blob/_text.html.haml
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -- if gitlab_markdown?(blob.name) | ||
2 | - .file_content.wiki | ||
3 | - = preserve do | ||
4 | - = markdown(blob.data) | ||
5 | -- elsif markup?(blob.name) | ||
6 | - .file_content.wiki | ||
7 | - = raw GitHub::Markup.render(blob.name, blob.data) | ||
8 | -- else | ||
9 | - .file_content.code | ||
10 | - - unless blob.empty? | ||
11 | - %div{class: user_color_scheme_class} | ||
12 | - = raw blob.colorize(formatter: :gitlab) | ||
13 | - - else | ||
14 | - %p.nothing_here_message Empty file |
config/routes.rb
@@ -170,6 +170,7 @@ Gitlab::Application.routes.draw do | @@ -170,6 +170,7 @@ Gitlab::Application.routes.draw do | ||
170 | end | 170 | end |
171 | 171 | ||
172 | resources :blob, only: [:show], constraints: {id: /.+/} | 172 | resources :blob, only: [:show], constraints: {id: /.+/} |
173 | + resources :raw, only: [:show], constraints: {id: /.+/} | ||
173 | resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ } | 174 | resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ } |
174 | resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit' | 175 | resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit' |
175 | resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} | 176 | resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} |
lib/gitlab/git/blob.rb
@@ -23,7 +23,19 @@ module Gitlab | @@ -23,7 +23,19 @@ module Gitlab | ||
23 | end | 23 | end |
24 | 24 | ||
25 | def exists? | 25 | def exists? |
26 | - @raw_blob | 26 | + raw_blob |
27 | + end | ||
28 | + | ||
29 | + def empty? | ||
30 | + data.blank? | ||
31 | + end | ||
32 | + | ||
33 | + def mode | ||
34 | + raw_blob.mode | ||
35 | + end | ||
36 | + | ||
37 | + def size | ||
38 | + raw_blob.size | ||
27 | end | 39 | end |
28 | end | 40 | end |
29 | end | 41 | end |