Commit dde2879589f8e86fdc614a64512cec971d8d8606

Authored by Aleksei Kvitinskii
2 parents cee93250 1477a6c8

Merge branch 'master' of dev.gitlabhq.com:gitlabhq

1 v 1.1.0 1 v 1.1.0
  2 + - project dashboard
  3 + - wall redesigned
2 - feature: code snippets 4 - feature: code snippets
3 - fixed horizontal scroll on file preview 5 - fixed horizontal scroll on file preview
4 - fixed app crash if commit message has invalid chars 6 - fixed app crash if commit message has invalid chars
@@ -15,7 +15,7 @@ gem 'therubyracer' @@ -15,7 +15,7 @@ gem 'therubyracer'
15 gem 'faker' 15 gem 'faker'
16 gem 'seed-fu', :git => 'git://github.com/mbleigh/seed-fu.git' 16 gem 'seed-fu', :git => 'git://github.com/mbleigh/seed-fu.git'
17 gem "inifile" 17 gem "inifile"
18 -gem "albino", :git => "git://github.com/gitlabhq/albino.git" 18 +gem "pygments.rb", "0.2.3"
19 gem "kaminari" 19 gem "kaminari"
20 gem "thin" 20 gem "thin"
21 gem "git" 21 gem "git"
@@ -5,13 +5,6 @@ GIT @@ -5,13 +5,6 @@ GIT
5 annotate (2.4.1.beta1) 5 annotate (2.4.1.beta1)
6 6
7 GIT 7 GIT
8 - remote: git://github.com/gitlabhq/albino.git  
9 - revision: 118380924969f3a856659f86ea1f40c1ba7bfcb1  
10 - specs:  
11 - albino (1.3.3)  
12 - posix-spawn (>= 0.3.6)  
13 -  
14 -GIT  
15 remote: git://github.com/gitlabhq/grit.git 8 remote: git://github.com/gitlabhq/grit.git
16 revision: ff015074ef35bd94cba943f9c0f98e161ab5851c 9 revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
17 specs: 10 specs:
@@ -72,6 +65,7 @@ GEM @@ -72,6 +65,7 @@ GEM
72 ZenTest (= 4.5) 65 ZenTest (= 4.5)
73 awesome_print (0.4.0) 66 awesome_print (0.4.0)
74 bcrypt-ruby (3.0.1) 67 bcrypt-ruby (3.0.1)
  68 + blankslate (2.1.2.4)
75 builder (3.0.0) 69 builder (3.0.0)
76 capybara (1.0.1) 70 capybara (1.0.1)
77 mime-types (>= 1.16) 71 mime-types (>= 1.16)
@@ -138,6 +132,8 @@ GEM @@ -138,6 +132,8 @@ GEM
138 orm_adapter (0.0.5) 132 orm_adapter (0.0.5)
139 polyglot (0.3.2) 133 polyglot (0.3.2)
140 posix-spawn (0.3.6) 134 posix-spawn (0.3.6)
  135 + pygments.rb (0.2.3)
  136 + rubypython (>= 0.5.1)
141 rack (1.3.2) 137 rack (1.3.2)
142 rack-cache (1.0.3) 138 rack-cache (1.0.3)
143 rack (>= 0.4) 139 rack (>= 0.4)
@@ -189,6 +185,9 @@ GEM @@ -189,6 +185,9 @@ GEM
189 ruby-debug-base19 (>= 0.11.19) 185 ruby-debug-base19 (>= 0.11.19)
190 ruby_core_source (0.1.5) 186 ruby_core_source (0.1.5)
191 archive-tar-minitar (>= 0.5.2) 187 archive-tar-minitar (>= 0.5.2)
  188 + rubypython (0.5.1)
  189 + blankslate (>= 2.1.2.3)
  190 + ffi (~> 1.0.7)
192 rubyzip (0.9.4) 191 rubyzip (0.9.4)
193 sass (3.1.7) 192 sass (3.1.7)
194 sass-rails (3.1.1) 193 sass-rails (3.1.1)
@@ -242,7 +241,6 @@ PLATFORMS @@ -242,7 +241,6 @@ PLATFORMS
242 241
243 DEPENDENCIES 242 DEPENDENCIES
244 acts_as_list 243 acts_as_list
245 - albino!  
246 annotate! 244 annotate!
247 autotest 245 autotest
248 autotest-rails 246 autotest-rails
@@ -260,6 +258,7 @@ DEPENDENCIES @@ -260,6 +258,7 @@ DEPENDENCIES
260 jquery-rails 258 jquery-rails
261 kaminari 259 kaminari
262 launchy 260 launchy
  261 + pygments.rb (= 0.2.3)
263 rails (= 3.1.0) 262 rails (= 3.1.0)
264 rails-footnotes (>= 3.7.5.rc4) 263 rails-footnotes (>= 3.7.5.rc4)
265 rspec-rails 264 rspec-rails
1 -1.0.2 1 +1.1.0
app/controllers/projects_controller.rb
@@ -60,24 +60,21 @@ class ProjectsController < ApplicationController @@ -60,24 +60,21 @@ class ProjectsController < ApplicationController
60 end 60 end
61 61
62 def show 62 def show
63 - if @project.repo_exists?  
64 - @date = case params[:view]  
65 - when "week" then Date.today - 7.days  
66 - else Date.today  
67 - end.at_beginning_of_day  
68 -  
69 - @heads = @project.repo.heads  
70 - @commits = @heads.map do |h|  
71 - @project.repo.log(h.name, nil, :since => @date)  
72 - end.flatten.uniq { |c| c.id }  
73 -  
74 - @commits.sort! do |x, y|  
75 - y.committed_date <=> x.committed_date  
76 - end 63 + return render "projects/empty" unless @project.repo_exists?
  64 + @date = case params[:view]
  65 + when "week" then Date.today - 7.days
  66 + when "day" then Date.today
  67 + else nil
  68 + end
77 69
  70 + if @date
  71 + @date = @date.at_beginning_of_day
  72 +
  73 + @commits = @project.commits_since(@date)
78 @messages = project.notes.since(@date).order("created_at DESC") 74 @messages = project.notes.since(@date).order("created_at DESC")
79 - else  
80 - return render "projects/empty" 75 + else
  76 + @commits = @project.fresh_commits
  77 + @messages = project.notes.fresh.limit(10)
81 end 78 end
82 end 79 end
83 80
@@ -86,15 +83,15 @@ class ProjectsController &lt; ApplicationController @@ -86,15 +83,15 @@ class ProjectsController &lt; ApplicationController
86 # 83 #
87 84
88 def wall 85 def wall
89 - @date = case params[:view]  
90 - when "week" then Date.today - 7.days  
91 - when "all" then nil  
92 - else Date.today  
93 - end  
94 -  
95 - @notes = @project.common_notes.order("created_at DESC")  
96 - @notes = @notes.since(@date.at_beginning_of_day) if @date  
97 @note = Note.new 86 @note = Note.new
  87 + @notes = @project.common_notes.order("created_at DESC")
  88 +
  89 + @notes = case params[:view]
  90 + when "week" then @notes.since((Date.today - 7.days).at_beginning_of_day)
  91 + when "all" then @notes.all
  92 + when "day" then @notes.since(Date.today.at_beginning_of_day)
  93 + else @notes.fresh.limit(10)
  94 + end
98 end 95 end
99 96
100 # 97 #
app/helpers/application_helper.rb
@@ -53,25 +53,4 @@ module ApplicationHelper @@ -53,25 +53,4 @@ module ApplicationHelper
53 [projects, default_nav, project_nav].flatten.to_json 53 [projects, default_nav, project_nav].flatten.to_json
54 end 54 end
55 55
56 - def handle_file_type(file_name, mime_type = nil)  
57 - if file_name =~ /(\.rb|\.ru|\.rake|Rakefile|\.gemspec|\.rbx|Gemfile)$/  
58 - :ruby  
59 - elsif file_name =~ /\.py$/  
60 - :python  
61 - elsif file_name =~ /(\.pl|\.scala|\.c|\.cpp|\.java|\.haml|\.html|\.sass|\.scss|\.xml|\.php|\.erb)$/  
62 - $1[1..-1].to_sym  
63 - elsif file_name =~ /\.js$/  
64 - :javascript  
65 - elsif file_name =~ /\.sh$/  
66 - :bash  
67 - elsif file_name =~ /\.coffee$/  
68 - :coffeescript  
69 - elsif file_name =~ /\.yml$/  
70 - :yaml  
71 - elsif file_name =~ /\.md$/  
72 - :minid  
73 - else  
74 - :text  
75 - end  
76 - end  
77 end 56 end
app/models/note.rb
@@ -24,6 +24,7 @@ class Note &lt; ActiveRecord::Base @@ -24,6 +24,7 @@ class Note &lt; ActiveRecord::Base
24 24
25 scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) 25 scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days))
26 scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } 26 scope :since, lambda { |day| where("created_at >= :date", :date => (day)) }
  27 + scope :fresh, order("created_at DESC")
27 28
28 mount_uploader :attachment, AttachmentUploader 29 mount_uploader :attachment, AttachmentUploader
29 end 30 end
app/models/project.rb
@@ -126,6 +126,34 @@ class Project &lt; ActiveRecord::Base @@ -126,6 +126,34 @@ class Project &lt; ActiveRecord::Base
126 end 126 end
127 end 127 end
128 128
  129 + def heads
  130 + @heads ||= repo.heads
  131 + end
  132 +
  133 + def fresh_commits
  134 + commits = heads.map do |h|
  135 + repo.commits(h.name, 10)
  136 + end.flatten.uniq { |c| c.id }
  137 +
  138 + commits.sort! do |x, y|
  139 + y.committed_date <=> x.committed_date
  140 + end
  141 +
  142 + commits[0..10]
  143 + end
  144 +
  145 + def commits_since(date)
  146 + commits = heads.map do |h|
  147 + repo.log(h.name, nil, :since => date)
  148 + end.flatten.uniq { |c| c.id }
  149 +
  150 + commits.sort! do |x, y|
  151 + y.committed_date <=> x.committed_date
  152 + end
  153 +
  154 + commits
  155 + end
  156 +
129 def tree(fcommit, path = nil) 157 def tree(fcommit, path = nil)
130 fcommit = commit if fcommit == :head 158 fcommit = commit if fcommit == :head
131 tree = fcommit.tree 159 tree = fcommit.tree
app/models/snippet.rb
1 class Snippet < ActiveRecord::Base 1 class Snippet < ActiveRecord::Base
  2 + include Utils::Colorize
  3 +
2 belongs_to :project 4 belongs_to :project
3 belongs_to :author, :class_name => "User" 5 belongs_to :author, :class_name => "User"
4 has_many :notes, :as => :noteable 6 has_many :notes, :as => :noteable
@@ -28,6 +30,10 @@ class Snippet &lt; ActiveRecord::Base @@ -28,6 +30,10 @@ class Snippet &lt; ActiveRecord::Base
28 ".js", ".sh", ".coffee", ".yml", ".md" 30 ".js", ".sh", ".coffee", ".yml", ".md"
29 ] 31 ]
30 end 32 end
  33 +
  34 + def colorize
  35 + system_colorize(content, file_name)
  36 + end
31 end 37 end
32 # == Schema Information 38 # == Schema Information
33 # 39 #
app/views/commits/_diff.html.haml
1 -- require "utils"  
2 .file_stats 1 .file_stats
3 - @commit.diffs.each do |diff| 2 - @commit.diffs.each do |diff|
4 - if diff.deleted_file 3 - if diff.deleted_file
@@ -35,7 +34,7 @@ @@ -35,7 +34,7 @@
35 %strong{:id => "#{diff.b_path}"}= diff.b_path 34 %strong{:id => "#{diff.b_path}"}= diff.b_path
36 %br/ 35 %br/
37 .diff_file_content 36 .diff_file_content
38 - - if file.mime_type =~ /application|text/ && !Utils.binary?(file.data) 37 + - if file.text?
39 - lines_arr = diff.diff.lines.to_a 38 - lines_arr = diff.diff.lines.to_a
40 - line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0 39 - line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0
41 - line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0 40 - line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0
@@ -50,9 +49,9 @@ @@ -50,9 +49,9 @@
50 - else 49 - else
51 - line_new += 1 50 - line_new += 1
52 - line_old += 1 51 - line_old += 1
53 - - elsif file.mime_type =~ /image/ 52 + - elsif file.image?
54 .diff_file_content_image 53 .diff_file_content_image
55 - %img{:src => "data:image/jpeg;base64,#{Base64.encode64(file.data)}"} 54 + %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"}
56 - else 55 - else
57 %p 56 %p
58 %center No preview for this file type 57 %center No preview for this file type
app/views/projects/_tree_file.html.haml
1 -- require "utils" 1 +:css
2 .view_file 2 .view_file
3 .view_file_header 3 .view_file_header
4 %strong 4 %strong
@@ -6,14 +6,13 @@ @@ -6,14 +6,13 @@
6 = link_to "raw", blob_project_path(@project, :commit_id => @commit.id, :path => params[:path] ), :class => "right", :target => "_blank" 6 = link_to "raw", blob_project_path(@project, :commit_id => @commit.id, :path => params[:path] ), :class => "right", :target => "_blank"
7 = link_to "history", project_commits_path(@project, :path => params[:path]), :class => "right", :style => "margin-right:10px;" 7 = link_to "history", project_commits_path(@project, :path => params[:path]), :class => "right", :style => "margin-right:10px;"
8 %br/ 8 %br/
9 - - if file.mime_type =~ /application|text/ && !Utils.binary?(file.data) 9 + - if file.text?
10 .view_file_content 10 .view_file_content
11 - - ft = handle_file_type(file.name, file.mime_type)  
12 :erb 11 :erb
13 - <%= raw Albino.colorize(content, ft, :html, 'utf-8', "linenos=True") %>  
14 - - elsif file.mime_type =~ /image/ 12 + <%= raw file.colorize %>
  13 + - elsif file.image?
15 .view_file_content_image 14 .view_file_content_image
16 - %img{ :src => "data:image/jpeg;base64,#{Base64.encode64(file.data)}"} 15 + %img{ :src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"}
17 - else 16 - else
18 %p 17 %p
19 %center No preview for this file type 18 %center No preview for this file type
app/views/projects/empty.html.erb
  1 +<% bash_lexer = Pygments::Lexer[:bash] %>
1 <div class=""> 2 <div class="">
2 <div class="git-empty"> 3 <div class="git-empty">
3 <h2>Git global setup:</h2> 4 <h2>Git global setup:</h2>
@@ -6,7 +7,7 @@ git config --global user.name &quot;#{current_user.name}&quot; @@ -6,7 +7,7 @@ git config --global user.name &quot;#{current_user.name}&quot;
6 git config --global user.email "#{current_user.email}" 7 git config --global user.email "#{current_user.email}"
7 eos 8 eos
8 %> 9 %>
9 - <%= raw Albino.colorize(setup_str, :bash) %> 10 + <%= raw bash_lexer.highlight(setup_str) %>
10 <br /> 11 <br />
11 <br /> 12 <br />
12 <h2>Next steps:</h2> 13 <h2>Next steps:</h2>
@@ -21,7 +22,7 @@ git remote add origin #{@project.url_to_repo} @@ -21,7 +22,7 @@ git remote add origin #{@project.url_to_repo}
21 git push -u origin master 22 git push -u origin master
22 eos 23 eos
23 %> 24 %>
24 - <%= raw Albino.colorize(repo_setup_str, :bash) %> 25 + <%= raw bash_lexer.highlight(repo_setup_str) %>
25 26
26 <br /><br /> 27 <br /><br />
27 <h2>Existing Git Repo?</h2> 28 <h2>Existing Git Repo?</h2>
@@ -31,7 +32,7 @@ git remote add origin #{@project.url_to_repo} @@ -31,7 +32,7 @@ git remote add origin #{@project.url_to_repo}
31 git push -u origin master 32 git push -u origin master
32 eos 33 eos
33 %> 34 %>
34 - <%= raw Albino.colorize(exist_repo_setup_str, :bash) %> 35 + <%= raw bash_lexer.highlight(exist_repo_setup_str) %>
35 36
36 <br /><br /> 37 <br /><br />
37 <h2>Remove this project?</h2> 38 <h2>Remove this project?</h2>
app/views/projects/show.html.haml
1 %div 1 %div
2 - %h2.left Recent history 2 + %h2.left History
3 .right 3 .right
4 = form_tag project_path(@project), :method => :get do 4 = form_tag project_path(@project), :method => :get do
5 .span-2 5 .span-2
6 - = radio_button_tag :view, "day", (params[:view] || "day") == "day", :onclick => "this.form.submit()", :id => "day_view" 6 + = radio_button_tag :view, "recent", (params[:view] || "recent") == "recent", :onclick => "this.form.submit()", :id => "recent_view"
  7 + = label_tag "recent_view","Recent"
  8 + .span-2
  9 + = radio_button_tag :view, "day", params[:view] == "day", :onclick => "this.form.submit()", :id => "day_view"
7 = label_tag "day_view","Today" 10 = label_tag "day_view","Today"
8 .span-2 11 .span-2
9 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view" 12 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view"
app/views/projects/wall.html.haml
@@ -4,7 +4,10 @@ @@ -4,7 +4,10 @@
4 .right 4 .right
5 = form_tag wall_project_path(@project), :method => :get do 5 = form_tag wall_project_path(@project), :method => :get do
6 .span-2 6 .span-2
7 - = radio_button_tag :view, "day", (params[:view] || "day") == "day", :onclick => "this.form.submit()", :id => "day_view" 7 + = radio_button_tag :view, "recent", (params[:view] || "recent") == "recent", :onclick => "this.form.submit()", :id => "recent_view"
  8 + = label_tag "recent_view","Recent"
  9 + .span-2
  10 + = radio_button_tag :view, "day", params[:view] == "day", :onclick => "this.form.submit()", :id => "day_view"
8 = label_tag "day_view","Today" 11 = label_tag "day_view","Today"
9 .span-2 12 .span-2
10 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view" 13 = radio_button_tag :view, "week", params[:view] == "week", :onclick => "this.form.submit()", :id => "week_view"
app/views/snippets/show.html.haml
@@ -7,9 +7,8 @@ @@ -7,9 +7,8 @@
7 = @snippet.file_name 7 = @snippet.file_name
8 %br/ 8 %br/
9 .view_file_content 9 .view_file_content
10 - - ft = handle_file_type(@snippet.file_name)  
11 :erb 10 :erb
12 - <%= raw Albino.colorize(@snippet.content, ft, :html, 'utf-8', "linenos=True") %> 11 + <%= raw @snippet.colorize %>
13 12
14 - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user 13 - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
15 = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive" 14 = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive"
config/initializers/grit_ext.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +require 'grit'
  2 +require 'pygments'
  3 +require "utils"
  4 +
  5 +Grit::Blob.class_eval do
  6 + include Utils::FileHelper
  7 + include Utils::Colorize
  8 +end
1 module Utils 1 module Utils
2 - def self.binary?(string)  
3 - string.each_byte do |x|  
4 - x.nonzero? or return true 2 + module FileHelper
  3 + def binary?(string)
  4 + string.each_byte do |x|
  5 + x.nonzero? or return true
  6 + end
  7 + false
  8 + end
  9 +
  10 + def image?
  11 + mime_type =~ /image/
  12 + end
  13 +
  14 + def text?
  15 + mime_type =~ /application|text/ && !binary?(data)
  16 + end
  17 + end
  18 +
  19 + module Colorize
  20 + def colorize
  21 + system_colorize(data, name)
  22 + end
  23 +
  24 + def system_colorize(data, file_name)
  25 + ft = handle_file_type(file_name)
  26 + Pygments.highlight(data, :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' })
  27 + end
  28 +
  29 + def handle_file_type(file_name, mime_type = nil)
  30 + if file_name =~ /(\.rb|\.ru|\.rake|Rakefile|\.gemspec|\.rbx|Gemfile)$/
  31 + :ruby
  32 + elsif file_name =~ /\.py$/
  33 + :python
  34 + elsif file_name =~ /(\.pl|\.scala|\.c|\.cpp|\.java|\.haml|\.html|\.sass|\.scss|\.xml|\.php|\.erb)$/
  35 + $1[1..-1].to_sym
  36 + elsif file_name =~ /\.js$/
  37 + :javascript
  38 + elsif file_name =~ /\.sh$/
  39 + :bash
  40 + elsif file_name =~ /\.coffee$/
  41 + :coffeescript
  42 + elsif file_name =~ /\.yml$/
  43 + :yaml
  44 + elsif file_name =~ /\.md$/
  45 + :minid
  46 + else
  47 + :text
  48 + end
5 end 49 end
6 - false  
7 end 50 end
8 end 51 end
spec/requests/projects_spec.rb
@@ -73,7 +73,7 @@ describe &quot;Projects&quot; do @@ -73,7 +73,7 @@ describe &quot;Projects&quot; do
73 end 73 end
74 74
75 it "should beahave like dashboard" do 75 it "should beahave like dashboard" do
76 - page.should have_content("Recent history") 76 + page.should have_content("History")
77 end 77 end
78 78
79 end 79 end
@@ -19,8 +19,8 @@ env = if envs.include?(ARGV[0]) @@ -19,8 +19,8 @@ env = if envs.include?(ARGV[0])
19 puts yellow "== RAILS ENV | #{env}" 19 puts yellow "== RAILS ENV | #{env}"
20 current_version = version 20 current_version = version
21 puts yellow "Your version is #{current_version}" 21 puts yellow "Your version is #{current_version}"
22 -puts yellow "Check for new version: $ git pull origin"  
23 -`git pull origin` # pull from origin 22 +puts yellow "Check for new version: $ git pull origin 1x"
  23 +`git pull origin 1x` # pull from origin
24 24
25 # latest version 25 # latest version
26 if version == current_version 26 if version == current_version