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 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 = Ansible::ansi_escaped(rawtext)
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
- Ansible::ansi_escaped(rawtext, 32768)
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
- ## Where's the name Ansible come from?
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.
@@ -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/, span(value))
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;)?\d+m/,span("none"))
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
- s += %Q{<span class="ansible_#{klass}">}
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
@@ -1,3 +1,3 @@
1
1
  module AnsibleVersion
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -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 text" =>
17
17
  %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
18
- "escaped text" =>
18
+ "escaped text" =>
19
19
  %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text</span>#{ANSIBLE_NONE}</span>},
20
- "escaped text other" =>
20
+ "escaped text other" =>
21
21
  %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>},
22
- "escaped text other" =>
22
+ "escaped text other" =>
23
23
  %Q{#{ANSIBLE_NONE}escaped </span>#{ANSIBLE_RED}text </span>#{ANSIBLE_GREEN}other</span>#{ANSIBLE_NONE}</span>#{ANSIBLE_NONE}</span>},
24
+ "escaped text" =>
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ansible
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Solano Labs