Commit dde2879589f8e86fdc614a64512cec971d8d8606
Exists in
master
and in
4 other branches
Merge branch 'master' of dev.gitlabhq.com:gitlabhq
Showing
19 changed files
with
147 additions
and
80 deletions
Show diff stats
CHANGELOG
Gemfile
| ... | ... | @@ -15,7 +15,7 @@ gem 'therubyracer' |
| 15 | 15 | gem 'faker' |
| 16 | 16 | gem 'seed-fu', :git => 'git://github.com/mbleigh/seed-fu.git' |
| 17 | 17 | gem "inifile" |
| 18 | -gem "albino", :git => "git://github.com/gitlabhq/albino.git" | |
| 18 | +gem "pygments.rb", "0.2.3" | |
| 19 | 19 | gem "kaminari" |
| 20 | 20 | gem "thin" |
| 21 | 21 | gem "git" | ... | ... |
Gemfile.lock
| ... | ... | @@ -5,13 +5,6 @@ GIT |
| 5 | 5 | annotate (2.4.1.beta1) |
| 6 | 6 | |
| 7 | 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 | 8 | remote: git://github.com/gitlabhq/grit.git |
| 16 | 9 | revision: ff015074ef35bd94cba943f9c0f98e161ab5851c |
| 17 | 10 | specs: |
| ... | ... | @@ -72,6 +65,7 @@ GEM |
| 72 | 65 | ZenTest (= 4.5) |
| 73 | 66 | awesome_print (0.4.0) |
| 74 | 67 | bcrypt-ruby (3.0.1) |
| 68 | + blankslate (2.1.2.4) | |
| 75 | 69 | builder (3.0.0) |
| 76 | 70 | capybara (1.0.1) |
| 77 | 71 | mime-types (>= 1.16) |
| ... | ... | @@ -138,6 +132,8 @@ GEM |
| 138 | 132 | orm_adapter (0.0.5) |
| 139 | 133 | polyglot (0.3.2) |
| 140 | 134 | posix-spawn (0.3.6) |
| 135 | + pygments.rb (0.2.3) | |
| 136 | + rubypython (>= 0.5.1) | |
| 141 | 137 | rack (1.3.2) |
| 142 | 138 | rack-cache (1.0.3) |
| 143 | 139 | rack (>= 0.4) |
| ... | ... | @@ -189,6 +185,9 @@ GEM |
| 189 | 185 | ruby-debug-base19 (>= 0.11.19) |
| 190 | 186 | ruby_core_source (0.1.5) |
| 191 | 187 | archive-tar-minitar (>= 0.5.2) |
| 188 | + rubypython (0.5.1) | |
| 189 | + blankslate (>= 2.1.2.3) | |
| 190 | + ffi (~> 1.0.7) | |
| 192 | 191 | rubyzip (0.9.4) |
| 193 | 192 | sass (3.1.7) |
| 194 | 193 | sass-rails (3.1.1) |
| ... | ... | @@ -242,7 +241,6 @@ PLATFORMS |
| 242 | 241 | |
| 243 | 242 | DEPENDENCIES |
| 244 | 243 | acts_as_list |
| 245 | - albino! | |
| 246 | 244 | annotate! |
| 247 | 245 | autotest |
| 248 | 246 | autotest-rails |
| ... | ... | @@ -260,6 +258,7 @@ DEPENDENCIES |
| 260 | 258 | jquery-rails |
| 261 | 259 | kaminari |
| 262 | 260 | launchy |
| 261 | + pygments.rb (= 0.2.3) | |
| 263 | 262 | rails (= 3.1.0) |
| 264 | 263 | rails-footnotes (>= 3.7.5.rc4) |
| 265 | 264 | rspec-rails | ... | ... |
VERSION
app/controllers/projects_controller.rb
| ... | ... | @@ -60,24 +60,21 @@ class ProjectsController < ApplicationController |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | 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 | 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 | 78 | end |
| 82 | 79 | end |
| 83 | 80 | |
| ... | ... | @@ -86,15 +83,15 @@ class ProjectsController < ApplicationController |
| 86 | 83 | # |
| 87 | 84 | |
| 88 | 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 | 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 | 95 | end |
| 99 | 96 | |
| 100 | 97 | # | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -53,25 +53,4 @@ module ApplicationHelper |
| 53 | 53 | [projects, default_nav, project_nav].flatten.to_json |
| 54 | 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 | 56 | end | ... | ... |
app/models/note.rb
| ... | ... | @@ -24,6 +24,7 @@ class Note < ActiveRecord::Base |
| 24 | 24 | |
| 25 | 25 | scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) |
| 26 | 26 | scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } |
| 27 | + scope :fresh, order("created_at DESC") | |
| 27 | 28 | |
| 28 | 29 | mount_uploader :attachment, AttachmentUploader |
| 29 | 30 | end | ... | ... |
app/models/project.rb
| ... | ... | @@ -126,6 +126,34 @@ class Project < ActiveRecord::Base |
| 126 | 126 | end |
| 127 | 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 | 157 | def tree(fcommit, path = nil) |
| 130 | 158 | fcommit = commit if fcommit == :head |
| 131 | 159 | tree = fcommit.tree | ... | ... |
app/models/snippet.rb
| 1 | 1 | class Snippet < ActiveRecord::Base |
| 2 | + include Utils::Colorize | |
| 3 | + | |
| 2 | 4 | belongs_to :project |
| 3 | 5 | belongs_to :author, :class_name => "User" |
| 4 | 6 | has_many :notes, :as => :noteable |
| ... | ... | @@ -28,6 +30,10 @@ class Snippet < ActiveRecord::Base |
| 28 | 30 | ".js", ".sh", ".coffee", ".yml", ".md" |
| 29 | 31 | ] |
| 30 | 32 | end |
| 33 | + | |
| 34 | + def colorize | |
| 35 | + system_colorize(content, file_name) | |
| 36 | + end | |
| 31 | 37 | end |
| 32 | 38 | # == Schema Information |
| 33 | 39 | # | ... | ... |
app/views/commits/_diff.html.haml
| 1 | -- require "utils" | |
| 2 | 1 | .file_stats |
| 3 | 2 | - @commit.diffs.each do |diff| |
| 4 | 3 | - if diff.deleted_file |
| ... | ... | @@ -35,7 +34,7 @@ |
| 35 | 34 | %strong{:id => "#{diff.b_path}"}= diff.b_path |
| 36 | 35 | %br/ |
| 37 | 36 | .diff_file_content |
| 38 | - - if file.mime_type =~ /application|text/ && !Utils.binary?(file.data) | |
| 37 | + - if file.text? | |
| 39 | 38 | - lines_arr = diff.diff.lines.to_a |
| 40 | 39 | - line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0 |
| 41 | 40 | - line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0 |
| ... | ... | @@ -50,9 +49,9 @@ |
| 50 | 49 | - else |
| 51 | 50 | - line_new += 1 |
| 52 | 51 | - line_old += 1 |
| 53 | - - elsif file.mime_type =~ /image/ | |
| 52 | + - elsif file.image? | |
| 54 | 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 | 55 | - else |
| 57 | 56 | %p |
| 58 | 57 | %center No preview for this file type | ... | ... |
app/views/projects/_tree_file.html.haml
| 1 | -- require "utils" | |
| 1 | +:css | |
| 2 | 2 | .view_file |
| 3 | 3 | .view_file_header |
| 4 | 4 | %strong |
| ... | ... | @@ -6,14 +6,13 @@ |
| 6 | 6 | = link_to "raw", blob_project_path(@project, :commit_id => @commit.id, :path => params[:path] ), :class => "right", :target => "_blank" |
| 7 | 7 | = link_to "history", project_commits_path(@project, :path => params[:path]), :class => "right", :style => "margin-right:10px;" |
| 8 | 8 | %br/ |
| 9 | - - if file.mime_type =~ /application|text/ && !Utils.binary?(file.data) | |
| 9 | + - if file.text? | |
| 10 | 10 | .view_file_content |
| 11 | - - ft = handle_file_type(file.name, file.mime_type) | |
| 12 | 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 | 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 | 16 | - else |
| 18 | 17 | %p |
| 19 | 18 | %center No preview for this file type | ... | ... |
app/views/projects/empty.html.erb
| 1 | +<% bash_lexer = Pygments::Lexer[:bash] %> | |
| 1 | 2 | <div class=""> |
| 2 | 3 | <div class="git-empty"> |
| 3 | 4 | <h2>Git global setup:</h2> |
| ... | ... | @@ -6,7 +7,7 @@ git config --global user.name "#{current_user.name}" |
| 6 | 7 | git config --global user.email "#{current_user.email}" |
| 7 | 8 | eos |
| 8 | 9 | %> |
| 9 | - <%= raw Albino.colorize(setup_str, :bash) %> | |
| 10 | + <%= raw bash_lexer.highlight(setup_str) %> | |
| 10 | 11 | <br /> |
| 11 | 12 | <br /> |
| 12 | 13 | <h2>Next steps:</h2> |
| ... | ... | @@ -21,7 +22,7 @@ git remote add origin #{@project.url_to_repo} |
| 21 | 22 | git push -u origin master |
| 22 | 23 | eos |
| 23 | 24 | %> |
| 24 | - <%= raw Albino.colorize(repo_setup_str, :bash) %> | |
| 25 | + <%= raw bash_lexer.highlight(repo_setup_str) %> | |
| 25 | 26 | |
| 26 | 27 | <br /><br /> |
| 27 | 28 | <h2>Existing Git Repo?</h2> |
| ... | ... | @@ -31,7 +32,7 @@ git remote add origin #{@project.url_to_repo} |
| 31 | 32 | git push -u origin master |
| 32 | 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 | 37 | <br /><br /> |
| 37 | 38 | <h2>Remove this project?</h2> | ... | ... |
app/views/projects/show.html.haml
| 1 | 1 | %div |
| 2 | - %h2.left Recent history | |
| 2 | + %h2.left History | |
| 3 | 3 | .right |
| 4 | 4 | = form_tag project_path(@project), :method => :get do |
| 5 | 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 | 10 | = label_tag "day_view","Today" |
| 8 | 11 | .span-2 |
| 9 | 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 | 4 | .right |
| 5 | 5 | = form_tag wall_project_path(@project), :method => :get do |
| 6 | 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 | 11 | = label_tag "day_view","Today" |
| 9 | 12 | .span-2 |
| 10 | 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 | 7 | = @snippet.file_name |
| 8 | 8 | %br/ |
| 9 | 9 | .view_file_content |
| 10 | - - ft = handle_file_type(@snippet.file_name) | |
| 11 | 10 | :erb |
| 12 | - <%= raw Albino.colorize(@snippet.content, ft, :html, 'utf-8', "linenos=True") %> | |
| 11 | + <%= raw @snippet.colorize %> | |
| 13 | 12 | |
| 14 | 13 | - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user |
| 15 | 14 | = link_to 'Edit', edit_project_snippet_path(@project, @snippet), :class => "lbutton positive" | ... | ... |
lib/utils.rb
| 1 | 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 | 49 | end |
| 6 | - false | |
| 7 | 50 | end |
| 8 | 51 | end | ... | ... |
spec/requests/projects_spec.rb
update.rb
| ... | ... | @@ -19,8 +19,8 @@ env = if envs.include?(ARGV[0]) |
| 19 | 19 | puts yellow "== RAILS ENV | #{env}" |
| 20 | 20 | current_version = version |
| 21 | 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 | 25 | # latest version |
| 26 | 26 | if version == current_version | ... | ... |