[issue #195] Added blob show. Some changes.

This commit is contained in:
George Vinogradov 2012-02-23 02:11:55 +04:00
parent 328cd17f46
commit 43b7ccd3dc
15 changed files with 211 additions and 258 deletions

View File

@ -0,0 +1,5 @@
$(document).ready(function() {
SyntaxHighlighter.defaults.toolbar = false;
SyntaxHighlighter.defaults.gutter = false;
SyntaxHighlighter.all();
});

View File

@ -85,3 +85,11 @@ div.activity .data-expander.expanded {
background: #FFF image-url('expand-gray2.png') no-repeat;
background-position: 0 2px;
}
table.blob td.lines pre {
background-color: #ECECEC;
border-right: 1px solid #DDDDDD;
color: #AAAAAA;
padding: 10px;
text-align: right;
}

View File

@ -1,7 +1,7 @@
html, body {
margin: 0;
padding: 0;
font-family: Tahoma, Arial;
font-family: Tahoma, Geneva, Arial;
color: #565657;
background: #1f60a1 image-url("bg.png") repeat-x;
min-width: 940px;
@ -1300,18 +1300,17 @@ div.description-top div.img {
margin-top: 14px;
}
div.description-top div.name {
float: left;
margin-top: 5px;
margin-left: 10px;
background: #FFF;
border: 1px solid #d1deeb;
height: 21px;
width: auto;
color: #575756;
padding-right: 5px;
padding-left: 5px;
padding-top: 5px;
div.description-top input.name {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #D1DEEB;
color: #575756;
float: left;
font-size: 12px;
height: 21px;
margin-left: 10px;
margin-top: 5px;
padding: 2px 5px 3px;
width: 315px;
}
div.description-top div.role {

View File

@ -30,7 +30,7 @@ class Git::BaseController < ApplicationController
end
def set_treeish
@treeish = params[:treeish].present? ? params[:treeish] : "master"
@treeish = params[:treeish].present? ? params[:treeish] : @project.default_branch
end
def set_current_tag

View File

@ -1,8 +1,9 @@
# -*- encoding : utf-8 -*-
class Git::BlobsController < Git::BaseController
before_filter :find_tree
before_filter :set_path_blob
before_filter :find_branch
before_filter :set_commit_hash
before_filter :set_path_blob
def show
redirect_to project_repo_path(@project) and return unless @blob.present?
@ -50,6 +51,10 @@ class Git::BlobsController < Git::BaseController
end
protected
def find_branch
@branch = @project.branch(@treeish)
end
def set_path_blob
@path = params[:path]
@path.force_encoding(Encoding::ASCII_8BIT)
@ -68,9 +73,7 @@ class Git::BlobsController < Git::BaseController
else
puts "2"
@tree = @git_repository.tree(@treeish)
puts @tree.name.inspect
@commit = @git_repository.log(@treeish, @path).first # TODO WTF nil ?
@commit = @git_repository.log(@treeish, @path, :max_count => 1).first # TODO WTF nil ?
end
end
end

View File

@ -42,9 +42,9 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter
def committer_link
@committer_link ||= if committer.is_a? User
link_to committer.uname, user_path(committer)
self.link_to committer.uname, user_path(committer)
else
mail_to committer.email.encode_to_default, committer.name.encode_to_default
self.mail_to committer.email.encode_to_default, committer.name.encode_to_default
end
end

View File

@ -0,0 +1,46 @@
- render_way = choose_render_way(@blob)
.file
.top
.l
= @blob.mode + ' | '
- if (render_way == :text)
- text = @blob.data.split("\n")
= "#{text.length} lines (#{text.select{|s| s.strip.length > 0}.length} sloc) | "
= "#{(@blob.size / 1024.0).round(3)} Kb"
.r
- if render_way == :text and can? :write, @project and @treeish.in? @project.branches.map(&:name)
= raw "#{link_to "Edit", edit_blob_path(@project, @treeish, @path) } | "
= raw "#{link_to "Raw", raw_path(@project, @treeish, @path)} | "
= raw "#{link_to "Blame", blame_path(@project, @treeish, @path)} | "
= link_to "History", commits_path(@project, @treeish, @path)
.both
.data
- case render_way
- when :image
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<center> <img src='?raw=true'/></center>
<br/>
- when :text
%table.table.blob
%tr
%td.lines
:plain
<pre>#{render_line_numbers(text.length)}</pre>
%td.blob
%pre{:class => "brush: #{@blob.mime_type.split('/').last}"}
=#{render_blob(@blob)}
= @blob.data.encode_to_default.html_safe
- when :binary
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<pre>#{ link_to @blob.basename.encode_to_default, raw_path(@project, @treeish, @path) }</pre>
<br/>

View File

@ -1,60 +1 @@
.block
= render :partial => "git/shared/navigation"
= render :partial => "git/shared/info"
- if @commit
.block
.content
.inner
= render :partial => "git/commits/commits", :object => [@commit]
.block
.content
.inner
%h3= render_path
%h3= @blob.mime_type
.blob_header
.size #{(@blob.size / 1024.0).round(3)} Kb
.buttons
- if @commit_hash
#{link_to "Raw", raw_commit_path(@project, @commit_hash, @path)}
#{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)}
#{link_to "History", commits_path(@project, @treeish, @path)}
- else
#{link_to "Edit", edit_blob_path(@project, @treeish, @path) if choose_render_way(@blob) == :text and can? :write, @project}
#{link_to "Raw", raw_path(@project, @treeish, @path)}
#{link_to "Blame", blame_path(@project, @treeish, @path)}
#{link_to "History", commits_path(@project, @treeish, @path)}
.clear
- case choose_render_way(@blob)
- when :image
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<center> <img src='?raw=true'/></center>
<br/>
- when :text
%table.table.blob
%tr
%td.lines
:plain
<pre>#{render_line_numbers(@blob.data.split("\n").length)}</pre>
%td.blob
:plain
<pre>#{render_blob(@blob)}</pre>
- when :binary
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<pre>#{ link_to @blob.basename.encode_to_default, raw_path(@project, @treeish, @path) }</pre>
<br/>
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
= render :partial => "git/blobs/show", :layout => 'projects/show'

View File

@ -0,0 +1,39 @@
%table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.th1.header= t("layout.project.filename")
%th.th2.header= t("layout.project.age")
%th.th3= t("layout.project.message")
%th.th4.header= t("layout.project.author")
%tbody
- if @path.present?
%tr
%td
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to "..", tree_path(@project, @treeish, File.join([@path.dup.encode_to_default, ".."].compact).encode_to_default)
%td== &nbsp;
%td== &nbsp;
%td== &nbsp;
- @project.tree_info(@tree, @treeish, @path).each_pair do |entry, commit|
%tr
%td
- entry_path = File.join([@path.present? ? @path : nil, entry.name].compact).encode_to_default
- if entry.is_a? Grit::Blob
.pic
%img{:src => "/assets/code.png"}/
.name
= link_to(entry.name, blob_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
- else
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to(entry.name, tree_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
%td
%span{:style => "display: none;"}= commit.committed_date || commit.authored_date#> Dec 31, 2011
= l(commit.committed_date || commit.authored_date, :format => :short) #31 декабря 2011
%td
= commit.short_message.encode_to_default #Redo autostart script to start from user
%td
= (commit.committer || commit.author).name.encode_to_default #chipiga

View File

@ -1,117 +1 @@
= render :partial => 'projects/submenu'
= render :partial => 'projects/repo_block', :locals => {:project => @project}
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch) do |presenter|
= render :partial => 'shared/feed_message', :locals => {:presenter => presenter, :item_no => 1}
%h3= t("layout.projects.files_in_project")
.files
.l
= render :partial => 'git/shared/whereami'
#fork-and-edit.r
%a.button{:href => "#"} Fork and edit
.both
#repo-wrapper
%table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.th1.header= t("layout.project.filename")
%th.th2.header= t("layout.project.age")
%th.th3= t("layout.project.message")
%th.th4.header= t("layout.project.author")
%tbody
- if @path.present?
%tr
%td
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to "..", tree_path(@project, @treeish, File.join([@path.dup.encode_to_default, ".."].compact).encode_to_default)
%td== &nbsp;
%td== &nbsp;
%td== &nbsp;
- @project.tree_info(@tree, @treeish, @path).each_pair do |entry, commit|
%tr
%td
- entry_path = File.join([@path.present? ? @path : nil, entry.name].compact).encode_to_default
- if entry.is_a? Grit::Blob
.pic
%img{:src => "/assets/code.png"}/
.name
= link_to(entry.name, blob_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
- else
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to(entry.name, tree_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
%td
%span{:style => "display: none;"}= commit.committed_date || commit.authored_date#> Dec 31, 2011
= l(commit.committed_date || commit.authored_date, :format => :short) #31 декабря 2011
%td
= commit.short_message.encode_to_default #Redo autostart script to start from user
%td
= (commit.committer || commit.author).name.encode_to_default #chipiga
-#.block
= render :partial => "git/shared/navigation"
= render :partial => "git/shared/info"
-#- if @commit
.block
.content
.inner
= render :partial => "git/commits/commits", :object => [@commit]
-#.block
.content
.inner
%h3= render_path
%table.table.git_tree
%tr
%th.icon
%th name
%th age
%th.last message
- if @path.present?
%tr.odd
%td
%td.icon
= link_to "..", tree_path(@project, @treeish, File.join([@path, ".."].compact))
%td== &nbsp;
%td.last== &nbsp;
- (@tree.trees + @tree.blobs).each do |entry|
%tr{ :class => cycle("even", "odd")}
%td.icon
- if entry.is_a?(Grit::Blob)
= image_tag("git/icons/text_document_16.png")
- else
= image_tag("git/icons/folder_16.png")
%td.tree_element
- entry_path = File.join([@path.present? ? @path.encode_to_default : nil, entry.name.encode_to_default].compact)
- if entry.is_a?(Grit::Blob)
= link_to entry.name.encode_to_default,
blob_path(@project, @treeish.encode_to_default, entry_path)
- else
= link_to "#{entry.name.encode_to_default}/",
tree_path(@project, @treeish.encode_to_default, entry_path)
%td== &nbsp;
%td.last== &nbsp;
-#- content_for :sidebar, render(:partial => 'git/shared/sidebar')
= render :partial => "git/repositories/show", :layout => 'projects/show'

View File

@ -1,16 +1,24 @@
.description-top
.img
%img{:alt => "pic", :src => "/assets/code.png"}/
.name
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'url-field',
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name',
:type => 'text',:spellcheck => 'false', :disabled => 'disabled'
.role
чтение и запись
.lineForm.fork
= form_tag do
= form_tag project_path(project), :id => 'branch_changer' do
= select_tag :branch,
options_from_collection_for_select(project.branches, :name, :name),
options_from_collection_for_select(project.branches, :name, :name, @branch.name),
:class => 'sel80', :id => 'branch_selector'
.fork
%p= t('layout.projects.current_branch')+':'
.both
:javascript
$(document).ready(function() {
$('select#branch_selector').live('change', function(e) {
$form = $('form#branch_changer');
$form.attr('action', $form.attr('action') + '/git/tree/' + $(this).val());
$form.submit();
});
});

View File

@ -0,0 +1,24 @@
= render :partial => 'projects/submenu'
= render :partial => 'projects/repo_block', :locals => {:project => @project}
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch) do |presenter|
= render :partial => 'shared/feed_message', :locals => {:presenter => presenter, :item_no => 1}
%h3= t("layout.projects.files_in_project")
.files
.l
= render :partial => 'git/shared/whereami'
#fork-and-edit.r
%a.button{:href => "#"} Fork and edit
.both
#repo-wrapper
= yield

View File

@ -5,7 +5,7 @@
= @project.name
%nav
%ul
%li= link_to t("project_menu.project"), project_path(@project), {:class => (act == :show && contr == :projects) ? 'active' : ''}
%li= link_to t("project_menu.project"), project_path(@project), {:class => (act == :show && contr.in?([:trees, :blobs])) ? 'active' : ''}
%li= link_to t("project_menu.commits"), commits_path(@project), {:class => (act == :index && contr == :commits) ? 'active' : ''}
%li= link_to t("project_menu.builds"), project_build_lists_path(@project), {:class => (act == :index && contr == :builds) ? 'active' : ''}
%li= link_to t("project_menu.tracker"), project_issues_path(@project), {:class => (act == :index && contr == :issues) ? 'active' : ''}

View File

@ -1,5 +1,5 @@
= render :partial => 'submenu'
= render :partial => 'repo_block', :locals => {:project => @project}
= render :partial => 'projects/submenu'
= render :partial => 'projects/repo_block', :locals => {:project => @project}
.description
%h3= t("layout.projects.about_subheader")
@ -8,59 +8,55 @@
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit,
:branch => @branch) do |presenter|
= render :partial => 'shared/feed_message', :locals => {:presenter => presenter,
:item_no => 1}
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch) do |presenter|
= render :partial => 'shared/feed_message', :locals => {:presenter => presenter, :item_no => 1}
-#.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.projects.list"), projects_path
%li= link_to t("layout.projects.new"), new_project_path
%li.active= link_to t("layout.projects.show"), project_path(@project)
%li= link_to t("layout.git.repositories.source"), project_repo_path(@project)
- if can? :write, @project
%li= link_to t("layout.projects.build"), new_project_build_list_path(@project)
%li= link_to t("layout.projects.issues"), project_issues_path(@project)
- if @project.has_wiki
%li= link_to t("layout.projects.wiki"), project_wiki_index_path(@project)
%h3= t("layout.projects.files_in_project")
.files
.l
= render :partial => 'git/shared/whereami'
.content
.inner
%p
%b
= t("activerecord.attributes.project.name")
\:
= @project.name
%p
%b
= t("activerecord.attributes.project.owner")
\:
= link_to @project.owner.try(:name), url_for(@project.owner)
%p
%b
= t("activerecord.attributes.project.visibility")
\:
= @project.visibility
%p
%b
= t("activerecord.attributes.project.repository")
\:
= git_repo_url @project.git_repo_name
.wat-cf
= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_project_path(@project), :class => "button" if can? :update, @project
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_path(@project), :method => "delete", :class => "button", :confirm => t("layout.projects.confirm_delete") if can? :destroy, @project
= link_to "Fork", fork_project_path(@project), :class => "button", :method => "post", :confirm => t("layout.confirm") if can? :fork, @project
#fork-and-edit.r
%a.button{:href => "#"} Fork and edit
.both
-#%a{ :name => "build_lists"}
-#.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.build_lists.current"), project_path(@project) + "#build_lists"
%li= link_to t("layout.build_lists.all"), project_build_lists_path(@project)
.content
= render :partial => "build_lists/build_lists", :object => @current_build_lists
-# content_for :sidebar, render('sidebar')
#repo-wrapper
%table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.th1.header= t("layout.project.filename")
%th.th2.header= t("layout.project.age")
%th.th3= t("layout.project.message")
%th.th4.header= t("layout.project.author")
%tbody
- if @path.present?
%tr
%td
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to "..", tree_path(@project, @treeish, File.join([@path.dup.encode_to_default, ".."].compact).encode_to_default)
%td== &nbsp;
%td== &nbsp;
%td== &nbsp;
- @project.tree_info(@tree, @treeish, @path).each_pair do |entry, commit|
%tr
%td
- entry_path = File.join([@path.present? ? @path : nil, entry.name].compact).encode_to_default
- if entry.is_a? Grit::Blob
.pic
%img{:src => "/assets/code.png"}/
.name
= link_to(entry.name, blob_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
- else
.pic
%img{:src => "/assets/folder.png"}/
.name
= link_to(entry.name, tree_path(@project, @treeish, entry_path), :class => 'files-see').encode_to_default
%td
%span{:style => "display: none;"}= commit.committed_date || commit.authored_date#> Dec 31, 2011
= l(commit.committed_date || commit.authored_date, :format => :short) #31 декабря 2011
%td
= commit.short_message.encode_to_default #Redo autostart script to start from user
%td
= (commit.committer || commit.author).name.encode_to_default #chipiga

View File

@ -200,7 +200,7 @@ Rosa::Application.routes.draw do
match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :update, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :via => :put
# Blobs
match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob, :via => :get
match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob, :via => :get, :format => false
match '/projects/:project_id/git/commit/blob/:commit_hash/*path', :controller => "git/blobs", :action => :show, :project_id => /[0-9a-zA-Z_.\-]*/, :as => :blob_commit, :via => :get
# Blame