diff options
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 16 | ||||
-rw-r--r-- | app/models/snippet.rb | 18 | ||||
-rw-r--r-- | app/models/tree.rb | 2 | ||||
-rw-r--r-- | app/views/refs/_tree_file.html.haml | 8 | ||||
-rw-r--r-- | app/views/snippets/show.html.haml | 5 | ||||
-rw-r--r-- | config/initializers/gitlabhq/20_grit_ext.rb | 6 | ||||
-rw-r--r-- | lib/utils.rb | 44 |
8 files changed, 40 insertions, 62 deletions
@@ -18,7 +18,8 @@ gem "six" gem "therubyracer" gem "faker" gem "seed-fu" -gem "pygments.rb", "0.2.7" +gem "linguist", "~> 1.0.0", :git => "https://github.com/github/linguist.git" +gem "pygments.rb", "0.2.11" gem "thin" gem "unicorn" gem "git" diff --git a/Gemfile.lock b/Gemfile.lock index 30dc519dd9d..c852a8bd420 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,16 @@ GIT annotate (2.4.1.beta1) GIT + remote: https://github.com/github/linguist.git + revision: c444c25b27131cd2aca6017f2a9ce5eae60dfcd3 + specs: + linguist (1.0.0) + charlock_holmes (~> 0.6.6) + escape_utils (~> 0.2.3) + mime-types (~> 1.18) + pygments.rb (~> 0.2.11) + +GIT remote: https://github.com/gitlabhq/gitolite-client.git revision: 36dabd226caa40ff052677719adaacbfe667b36c specs: @@ -104,6 +114,7 @@ GEM diff-lcs (1.1.3) drapper (0.8.4) erubis (2.7.0) + escape_utils (0.2.4) eventmachine (0.12.10) execjs (1.3.0) multi_json (~> 1.0) @@ -169,7 +180,7 @@ GEM coderay (~> 1.0.5) method_source (~> 0.7) slop (>= 2.4.4, < 3) - pygments.rb (0.2.7) + pygments.rb (0.2.11) rubypython (~> 0.5.3) pyu-ruby-sasl (0.0.3.3) rack (1.4.1) @@ -326,11 +337,12 @@ DEPENDENCIES kaminari launchy letter_opener + linguist (~> 1.0.0)! modularity mysql2 omniauth-ldap pry - pygments.rb (= 0.2.7) + pygments.rb (= 0.2.11) rails (= 3.2.1) rails-footnotes rake diff --git a/app/models/snippet.rb b/app/models/snippet.rb index ae25e8a3bb8..17d23418556 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -1,5 +1,5 @@ class Snippet < ActiveRecord::Base - include Utils::Colorize + include Linguist::BlobHelper belongs_to :project belongs_to :author, :class_name => "User" @@ -38,8 +38,20 @@ class Snippet < ActiveRecord::Base ] end - def colorize - system_colorize(content, file_name) + def data + content + end + + def size + 0 + end + + def name + file_name + end + + def mode + nil end def expired? diff --git a/app/models/tree.rb b/app/models/tree.rb index 6040680b969..9d60f83015f 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -1,5 +1,5 @@ class Tree - include Utils::FileHelper + include Linguist::BlobHelper attr_accessor :path, :tree, :project, :ref delegate :contents, diff --git a/app/views/refs/_tree_file.html.haml b/app/views/refs/_tree_file.html.haml index 738dad9bd59..c5512f69b51 100644 --- a/app/views/refs/_tree_file.html.haml +++ b/app/views/refs/_tree_file.html.haml @@ -11,10 +11,10 @@ - if file.text? .view_file_content - unless file.empty? - %div{:class => current_user.dark_scheme ? "black" : "white"} - = preserve do - = raw file.colorize - - else + %div{:class => current_user.dark_scheme ? "black" : "white"} + = preserve do + = raw file.colorize(options: { linenos: 'True'}) + - else %h3 %center Empty file - elsif file.image? diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml index a7ccd44cc79..7af4d2498fd 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -13,8 +13,7 @@ .view_file_header %strong= @snippet.file_name .view_file_content - %div{:class => current_user.dark_scheme ? "black" : ""} - :erb - <%= raw @snippet.colorize %> + %div{:class => current_user.dark_scheme ? "black" : ""} + = raw @snippet.colorize(options: { linenos: 'True'}) = render "notes/notes", :tid => @snippet.id, :tt => "snippet" diff --git a/config/initializers/gitlabhq/20_grit_ext.rb b/config/initializers/gitlabhq/20_grit_ext.rb index 50b57d5e888..13e692cf20d 100644 --- a/config/initializers/gitlabhq/20_grit_ext.rb +++ b/config/initializers/gitlabhq/20_grit_ext.rb @@ -1,10 +1,8 @@ require 'grit' require 'pygments' -require "utils" Grit::Blob.class_eval do - include Utils::FileHelper - include Utils::Colorize + include Linguist::BlobHelper end #monkey patch raw_object from string @@ -15,7 +13,7 @@ Grit::GitRuby::Internal::RawObject.class_eval do end -Grit::Diff.class_eval do +Grit::Diff.class_eval do def old_path Gitlabhq::Encode.utf8 a_path end diff --git a/lib/utils.rb b/lib/utils.rb deleted file mode 100644 index 52f3ee2e195..00000000000 --- a/lib/utils.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Utils - module FileHelper - def binary?(string) - string.each_byte do |x| - x.nonzero? or return true - end - false - end - - def image? - mime_type =~ /image/ - end - - def text? - mime_type =~ /application|text/ && !binary?(data) - end - end - - module Colorize - def colorize - system_colorize(data, name) - end - - def system_colorize(data, file_name) - options = { :encoding => 'utf-8', :linenos => 'True' } - - # Try detect language with pygments - Pygments.highlight data, :filename => file_name, :options => options - rescue - # if it fails use manual detection - ft = handle_file_type(file_name) - Pygments.highlight(data, :lexer => ft, :options => options) - end - - def handle_file_type(file_name) - case file_name - when /(\.ru|Gemfile)$/ - :ruby - else - :text - end - end - end -end |