summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock7
-rw-r--r--app/models/build.rb2
-rw-r--r--config/application.rb2
-rw-r--r--lib/ansi2html.rb32
-rw-r--r--spec/lib/ansi2html_spec.rb27
6 files changed, 61 insertions, 12 deletions
diff --git a/Gemfile b/Gemfile
index 8937a82..511de1a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -34,9 +34,6 @@ gem 'stamp'
# Git support
gem 'grit'
-# ANSI color
-gem 'ansi2html', git: "git://github.com/vsizov/ansi2html.git"
-
# Pagination
gem 'will_paginate', '~> 3.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index df279f0..d66d03b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,9 +1,3 @@
-GIT
- remote: git://github.com/vsizov/ansi2html.git
- revision: 09c1544848940c2887da1908e7530e3983d6f499
- specs:
- ansi2html (0.9.0)
-
GEM
remote: https://rubygems.org/
specs:
@@ -226,7 +220,6 @@ PLATFORMS
DEPENDENCIES
annotate
- ansi2html!
bootstrap-sass
capybara
childprocess
diff --git a/app/models/build.rb b/app/models/build.rb
index 1458f15..2f425ce 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -49,7 +49,7 @@ class Build < ActiveRecord::Base
end
def ansi_color_codes(string)
- ANSI2HTML::convert(string)
+ Ansi2html::convert(string)
end
def to_param
diff --git a/config/application.rb b/config/application.rb
index 37fcf66..3e5c811 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -16,7 +16,7 @@ module GitlabCi
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
+ config.autoload_paths += %W(#{config.root}/lib)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
diff --git a/lib/ansi2html.rb b/lib/ansi2html.rb
new file mode 100644
index 0000000..5650d81
--- /dev/null
+++ b/lib/ansi2html.rb
@@ -0,0 +1,32 @@
+# ANSI color library
+module Ansi2html
+ COLOR = {
+ '1' => 'bold',
+ '30' => 'black',
+ '31' => 'red',
+ '32' => 'green',
+ '33' => 'yellow',
+ '34' => 'blue',
+ '35' => 'magenta',
+ '36' => 'cyan',
+ '37' => 'white',
+ '90' => 'grey'
+ }
+
+ def self.convert(ansi)
+ out = ""
+ s = StringScanner.new(ansi.gsub("<", "&lt;"))
+ while(!s.eos?)
+ if s.scan(/\e\[(3[0-7]|90|1)m/)
+ out << %{<span class="#{COLOR[s[1]]}">}
+ else
+ if s.scan(/\e\[0m/)
+ out << %{</span>}
+ else
+ out << s.scan(/./m)
+ end
+ end
+ end
+ out
+ end
+end
diff --git a/spec/lib/ansi2html_spec.rb b/spec/lib/ansi2html_spec.rb
new file mode 100644
index 0000000..73700c1
--- /dev/null
+++ b/spec/lib/ansi2html_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Ansi2html do
+ it "prints non-ansi as-is" do
+ Ansi2html::convert("Hello").should == 'Hello'
+ end
+
+ it "prints simply red" do
+ Ansi2html::convert("\e[31mHello\e[0m").should == '<span class="red">Hello</span>'
+ end
+
+ it "prints simply yellow" do
+ Ansi2html::convert("\e[33mHello\e[0m").should == '<span class="yellow">Hello</span>'
+ end
+
+ it "prints simply blue" do
+ Ansi2html::convert("\e[34mHello\e[0m").should == '<span class="blue">Hello</span>'
+ end
+
+ it "prints simply grey" do
+ Ansi2html::convert("\e[90mHello\e[0m").should == '<span class="grey">Hello</span>'
+ end
+
+ it "white bold boys have more fun" do
+ Ansi2html::convert("\e[37m\e[1mHello\e[0m\e[0m").should == '<span class="white"><span class="bold">Hello</span></span>'
+ end
+end