ansible 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -3
- data/lib/ansible.rb +12 -5
- data/lib/ansible/version.rb +1 -1
- data/spec/ansible_spec.rb +6 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -20,9 +20,10 @@ Here's an example of using Ansible in a rails controller:
|
|
20
20
|
require 'ansible'
|
21
21
|
|
22
22
|
class TextController << ApplicationController
|
23
|
+
include Ansible
|
23
24
|
def show
|
24
25
|
rawtext = Text.find(params[:id])
|
25
|
-
@text =
|
26
|
+
@text = ansi_escaped(rawtext)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -35,16 +36,29 @@ classes that correspond to ANSI escape directives, like:
|
|
35
36
|
|
36
37
|
You can control the display of these with CSS however you please.
|
37
38
|
|
39
|
+
See [the sample
|
40
|
+
stylesheet](https://github.com/tddium/ansible/blob/master/stylesheets/ansible.css).
|
41
|
+
|
38
42
|
### Long input
|
39
43
|
|
40
44
|
For input beyond a certain size (default 65535 characters), Ansible will
|
41
45
|
automatically fall back to simply stripping escapes entirely. You can control
|
42
46
|
this threshold when you call ansi_escaped:
|
43
47
|
|
44
|
-
|
48
|
+
class Helper
|
49
|
+
include Ansible
|
50
|
+
|
51
|
+
def handle_escaped(rawtext)
|
52
|
+
ansi_escaped(h(rawtext), 32768).html_safe
|
53
|
+
end
|
54
|
+
end
|
45
55
|
|
46
56
|
|
47
|
-
##
|
57
|
+
## What's with the name Ansible?
|
48
58
|
|
49
59
|
An [ansible](http://en.wikipedia.org/wiki/Ansible) is a fictional faster than light
|
50
60
|
communication device.
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
We welcome fixes and enhancements. Feel free to fork on github and submit a pull request.
|
data/lib/ansible.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ansible
|
2
2
|
def escape_to_html(data)
|
3
|
-
data = span("none", true) + data
|
3
|
+
data = span("none", 0, true) + data
|
4
4
|
|
5
5
|
{ 30 => :black,
|
6
6
|
31 => :red,
|
@@ -12,11 +12,15 @@ module Ansible
|
|
12
12
|
37 => :white,
|
13
13
|
90 => :gray
|
14
14
|
}.each do |key, value|
|
15
|
-
data.gsub!(/\e\[(\d;)?#{key}m
|
15
|
+
data.gsub!(/\e\[(\d;)?#{key}m/) { |match|
|
16
|
+
span(value, $1)
|
17
|
+
}
|
16
18
|
end
|
17
19
|
|
18
20
|
data.gsub!(/\e\[0?m/, span("none"))
|
19
|
-
data.gsub!(/\e\[(\d;)
|
21
|
+
data.gsub!(/\e\[(\d;)?(\d+)m/) { |match|
|
22
|
+
span($2, $1)
|
23
|
+
}
|
20
24
|
data + "</span>"
|
21
25
|
end
|
22
26
|
|
@@ -36,9 +40,12 @@ module Ansible
|
|
36
40
|
end
|
37
41
|
|
38
42
|
private
|
39
|
-
def span(klass, first=false)
|
43
|
+
def span(klass, level=0, first=false)
|
40
44
|
s = first ? "" : "</span>"
|
41
|
-
|
45
|
+
|
46
|
+
classes = ["ansible_#{klass}"]
|
47
|
+
classes << "ansible_bold" if level.to_i == 1
|
48
|
+
s += %Q{<span class="#{classes.join(" ")}">}
|
42
49
|
s
|
43
50
|
end
|
44
51
|
end
|
data/lib/ansible/version.rb
CHANGED
data/spec/ansible_spec.rb
CHANGED
@@ -7,7 +7,7 @@ end
|
|
7
7
|
describe Ansible do
|
8
8
|
ANSIBLE_NONE = %Q{<span class="ansible_none">}
|
9
9
|
ANSIBLE_RED = %Q{<span class="ansible_red">}
|
10
|
-
ANSIBLE_GREEN = %Q{<span class="ansible_green">}
|
10
|
+
ANSIBLE_GREEN = %Q{<span class="ansible_green ansible_bold">}
|
11
11
|
subject { Helper.new }
|
12
12
|
describe "#ansi_escaped" do
|
13
13
|
SAMPLE_TEXT = {
|
@@ -15,12 +15,14 @@ describe Ansible do
|
|
15
15
|
%Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
|
16
16
|
"escaped [0;31mtext[0m" =>
|
17
17
|
%Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
|
18
|
-
"escaped [
|
18
|
+
"escaped [0;31mtext[0m" =>
|
19
19
|
%Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
|
20
|
-
"escaped [
|
20
|
+
"escaped [0;31mtext [1;32mother[0m" =>
|
21
21
|
%Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>},
|
22
|
-
"escaped [
|
22
|
+
"escaped [0;31mtext [1;32mother[0m[m" =>
|
23
23
|
%Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>#{ANSIBLE_NONE}</span>},
|
24
|
+
"escaped [1;95mtext[0m" =>
|
25
|
+
%Q{#{ANSIBLE_NONE}escaped </span><span class="ansible_95 ansible_bold">text</span>#{ANSIBLE_NONE}</span>},
|
24
26
|
}
|
25
27
|
|
26
28
|
it "should render the text as html" do
|