ansible 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tddium.gemspec
4
+ gemspec
5
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2011 Solano Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # Ansible
2
+
3
+ ## Overview
4
+
5
+ Ansible is an attempt at an ANSI-escape to HTML conversion tool that's fast
6
+ enough to use on large input. Particularly, it's meant to be significantly
7
+ faster than the [ansi-sys](http://ansi-sys.rubyforge.org/) gem for large input
8
+ text.
9
+
10
+ ## Installation
11
+
12
+ Install the gem:
13
+
14
+ gem install ansible
15
+
16
+ ## Usage
17
+
18
+ Here's an example of using Ansible in a rails controller:
19
+
20
+ require 'ansible'
21
+
22
+ class TextController << ApplicationController
23
+ def show
24
+ rawtext = Text.find(params[:id])
25
+ @text = Ansible::ansi_escaped(rawtext)
26
+ end
27
+ end
28
+
29
+ Ansible will convert escapes into HTML `<span>` tags that apply sensible
30
+ classes that correspond to ANSI escape directives, like:
31
+
32
+ * ansible_green
33
+ * ansible_blue
34
+ * ansible_magenta
35
+
36
+ You can control the display of these with CSS however you please.
37
+
38
+ ### Long input
39
+
40
+ For input beyond a certain size (default 65535 characters), Ansible will
41
+ automatically fall back to simply stripping escapes entirely. You can control
42
+ this threshold when you call ansi_escaped:
43
+
44
+ Ansible::ansi_escaped(rawtext, 32768)
45
+
46
+
47
+ ## Where's the name Ansible come from?
48
+
49
+ An [ansible](http://en.wikipedia.org/wiki/Ansible) is a fictional faster than light
50
+ communication device.
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = "--color"
8
+ end
9
+ task :default => :spec
10
+
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "ansible/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ansible"
6
+ s.version = AnsibleVersion::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Solano Labs"]
9
+ s.email = ["info@tddium.com"]
10
+ s.homepage = "http://www.tddium.com/"
11
+ s.summary = %q{Fast ANSI->HTML conversion}
12
+ s.description = <<-EOF
13
+ Ansible is a fast (somewhat rough) conversion tool that takes a string with ANSI
14
+ escapes and produces HTML.
15
+ EOF
16
+
17
+ s.rubyforge_project = "tddium"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency("bundler")
25
+ s.add_development_dependency("rspec")
26
+ s.add_development_dependency("rake")
27
+ end
@@ -0,0 +1,44 @@
1
+ module Ansible
2
+ def escape_to_html(data)
3
+ data = span("none", true) + data
4
+
5
+ { 30 => :black,
6
+ 31 => :red,
7
+ 32 => :green,
8
+ 33 => :yellow,
9
+ 34 => :blue,
10
+ 35 => :magenta,
11
+ 36 => :cyan,
12
+ 37 => :white,
13
+ 90 => :gray
14
+ }.each do |key, value|
15
+ data.gsub!(/\e\[(\d;)?#{key}m/, span(value))
16
+ end
17
+
18
+ data.gsub!(/\e\[0?m/, span("none"))
19
+ data.gsub!(/\e\[(\d;)?\d+m/,span("none"))
20
+ data + "</span>"
21
+ end
22
+
23
+ def strip_escapes(string)
24
+ string.gsub!(/\e\[(\d;)?\d*m/, "")
25
+ string
26
+ end
27
+
28
+ def ansi_escaped(string, maxlen=65535)
29
+ return '' unless string
30
+ if string.size < maxlen
31
+ z = escape_to_html(string)
32
+ else
33
+ z = strip_escapes(string.to_s)
34
+ end
35
+ z
36
+ end
37
+
38
+ private
39
+ def span(klass, first=false)
40
+ s = first ? "" : "</span>"
41
+ s += %Q{<span class="ansible_#{klass}">}
42
+ s
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module AnsibleVersion
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ class Helper
4
+ include Ansible
5
+ end
6
+
7
+ describe Ansible do
8
+ ANSIBLE_NONE = %Q{<span class="ansible_none">}
9
+ ANSIBLE_RED = %Q{<span class="ansible_red">}
10
+ ANSIBLE_GREEN = %Q{<span class="ansible_green">}
11
+ subject { Helper.new }
12
+ describe "#ansi_escaped" do
13
+ SAMPLE_TEXT = {
14
+ "escaped text" =>
15
+ %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
16
+ "escaped text" =>
17
+ %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
18
+ "escaped text" =>
19
+ %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
20
+ "escaped text other" =>
21
+ %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>},
22
+ "escaped text other" =>
23
+ %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>#{ANSIBLE_NONE}</span>},
24
+ }
25
+
26
+ it "should render the text as html" do
27
+ SAMPLE_TEXT.each do |t, v|
28
+ subject.ansi_escaped(t).should_not =~ /\e/
29
+ end
30
+ end
31
+
32
+ it "should inject span tags" do
33
+ SAMPLE_TEXT.each do |t,v|
34
+ subject.ansi_escaped(t).should == v
35
+ end
36
+ end
37
+
38
+ it "should handle long input" do
39
+ long_input = "abcd" * 41000
40
+ subject.ansi_escaped(long_input).should_not =~ /\e/
41
+ end
42
+
43
+ context "(nil)" do
44
+ it "should echo an empty string" do
45
+ subject.ansi_escaped(nil).should == ''
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'ansible'
3
+
@@ -0,0 +1,8 @@
1
+ .ansible_black { color: black; }
2
+ .ansible_green { color: limegreen; }
3
+ .ansible_yellow { color: yellow;}
4
+ .ansible_magenta { color: magenta; }
5
+ .ansible_cyan { color: cyan; }
6
+ .ansible_white { color: white; }
7
+ .ansible_gray { color: dimgray; }
8
+ .ansible_none { color: none; }
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Solano Labs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-04 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: |
50
+ Ansible is a fast (somewhat rough) conversion tool that takes a string with ANSI
51
+ escapes and produces HTML.
52
+
53
+ email:
54
+ - info@tddium.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - ansible.gemspec
68
+ - lib/ansible.rb
69
+ - lib/ansible/version.rb
70
+ - spec/ansible_spec.rb
71
+ - spec/spec_helper.rb
72
+ - stylesheets/ansible.css
73
+ has_rdoc: true
74
+ homepage: http://www.tddium.com/
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project: tddium
97
+ rubygems_version: 1.6.2
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Fast ANSI->HTML conversion
101
+ test_files: []
102
+