pizzazz 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/Readme.markdown +8 -3
- data/lib/pizzazz/colorer.rb +131 -83
- data/lib/pizzazz/html.rb +7 -1
- data/lib/pizzazz/version.rb +1 -1
- data/pizzazz.gemspec +4 -4
- data/test/units/colorer_test.rb +49 -55
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ba9b2f27bf01cd6e8ca21e219c36ee83779c89
|
4
|
+
data.tar.gz: 28b1c4445d13227011d80a91ab0be3d5829ad5b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa2ff88e3a96caee02b7050a1db9410bbf9d6ab9a585531716de9163a9e5d0e4335e24287e301b72d169026b9ee1220676ef68169a5c5b49df4f5905ec541a7
|
7
|
+
data.tar.gz: 89b52e03781a8a4e436da67c40b582238f8b1a892d3e0679e04040cc3ada346de5fc00d36a27f1b929cdd8ae16200dd6e45c1ff55ef66fa79712bc2e13801692
|
data/Rakefile
CHANGED
data/Readme.markdown
CHANGED
@@ -31,7 +31,13 @@ Pizzazzifing an object is simple:
|
|
31
31
|
``` ruby
|
32
32
|
object = { name: 'Sam Soffes', website: 'http://soff.es' }
|
33
33
|
Pizzazz.ify(object)
|
34
|
-
|
34
|
+
```
|
35
|
+
|
36
|
+
``` html
|
37
|
+
<span class="dictionary"><span class="control bracket curly opening">{</span>
|
38
|
+
<span class="control tab"> </span><span class="key-name"><span class="string key"><span class="control quote opening">"</span><span class="text">name</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">Sam Soffes</span><span class="control quote closing">"</span></span></span><span class="control comma">,</span>
|
39
|
+
<span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span><span class="text">website</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string link"><a href="http://soff.es" rel="external"><span class="control quote opening">"</span><span class="text">http://soff.es</span><span class="control quote closing">"</span></a></span></span>
|
40
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>
|
35
41
|
```
|
36
42
|
|
37
43
|
You can optionally limit arrays or values as well:
|
@@ -46,11 +52,10 @@ This will add an ellipses after the first element and truncate values longer tha
|
|
46
52
|
Pizzazz.ify(all_of_the_things, array_limit: 'etc', value_omission: '... (continued)')
|
47
53
|
```
|
48
54
|
|
49
|
-
You can also supply `
|
55
|
+
You can also supply `prefix` to add a string to the beginning of each line of the output. You can also supply `class_name_prefix` to prefix the classes that are generated.
|
50
56
|
|
51
57
|
By defauly, hash keys are sorted alphabetically. You can disable this with `sort_keys: false`.
|
52
58
|
|
53
|
-
|
54
59
|
### HTML
|
55
60
|
|
56
61
|
Spans are added around various elements. Here's the classes:
|
data/lib/pizzazz/colorer.rb
CHANGED
@@ -4,6 +4,7 @@ require 'erb'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module Pizzazz
|
7
|
+
# A class for turning JSON into HTML.
|
7
8
|
class Colorer
|
8
9
|
def initialize(object, options = nil)
|
9
10
|
options ||= {}
|
@@ -15,133 +16,180 @@ module Pizzazz
|
|
15
16
|
@value_omission = options[:value_omission] || '…'
|
16
17
|
@tab = options[:tab] || ' '
|
17
18
|
@prefix = options[:prefix]
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
19
|
+
@detect_links = options[:detect_links].nil? ? true : options[:detect_links]
|
20
|
+
@sort_keys = options[:sort_keys].nil? ? true : options[:sort_keys]
|
21
|
+
@class_name_prefix = options[:class_name_prefix] || ''
|
21
22
|
end
|
22
23
|
|
23
24
|
def ify
|
24
25
|
return '' unless @object
|
25
26
|
|
26
27
|
# Parse
|
27
|
-
output = node(@object
|
28
|
+
output = node(@object)
|
28
29
|
return output unless @prefix
|
29
30
|
|
30
31
|
# Add prefix
|
31
|
-
prefix =
|
32
|
+
prefix = span(@prefix, 'prefix')
|
32
33
|
lines = output.split("\n")
|
33
34
|
prefix + lines.join("\n#{prefix}")
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
+
private
|
37
38
|
|
38
|
-
URL_PATTERN =
|
39
|
+
URL_PATTERN = %r{^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,})([/\w \.-]*)*/?$}i
|
39
40
|
|
40
41
|
def tab
|
41
|
-
|
42
|
+
span @tab * @indent, 'control tab'
|
42
43
|
end
|
43
44
|
|
44
45
|
def truncate(string)
|
45
46
|
return string if @value_limit < 1
|
46
47
|
text = string.dup
|
47
48
|
stop = @value_limit - @value_omission.length
|
48
|
-
(text.length > @value_limit ? text[0...stop] + @value_omission : text).to_s
|
49
|
+
(text.length > @value_limit ? text[0...stop] + span(@value_omission, 'omission') : text).to_s
|
49
50
|
end
|
50
51
|
|
51
|
-
def node(object
|
52
|
-
omit_container = root && @omit_root_container
|
53
|
-
|
52
|
+
def node(object)
|
54
53
|
case object
|
55
54
|
when String
|
56
|
-
|
57
|
-
%Q{<span class="string link"><a href="#{object}" rel="external"><span class="quote opening">"</span><span class="text">#{truncate(::ERB::Util.h(object.gsub("\n", '\n')))}</span><span class="quote closing">"</span></a></span>}
|
58
|
-
else
|
59
|
-
%Q{<span class="string"><span class="quote opening">"</span>#{truncate(::ERB::Util.h(object.gsub("\n", '\n')))}<span class="quote closing">"</span></span>}
|
60
|
-
end
|
61
|
-
|
55
|
+
@detect_links && link?(object) ? link(object) : string(object)
|
62
56
|
when Time
|
63
|
-
|
64
|
-
|
57
|
+
span object.to_json, 'string time'
|
65
58
|
when TrueClass
|
66
|
-
|
67
|
-
|
59
|
+
span 'true', 'boolean true'
|
68
60
|
when FalseClass
|
69
|
-
|
70
|
-
|
61
|
+
span 'false', 'boolean false'
|
71
62
|
when NilClass
|
72
|
-
|
73
|
-
|
63
|
+
span 'null', 'null'
|
74
64
|
when Numeric
|
75
|
-
|
76
|
-
|
65
|
+
span object, 'number'
|
77
66
|
when Hash
|
78
|
-
|
67
|
+
hash object
|
68
|
+
when Array
|
69
|
+
array object
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def link?(string)
|
74
|
+
scheme = URI.parse(string).scheme
|
75
|
+
scheme == 'http' || scheme == 'https'
|
76
|
+
rescue
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def span(content, class_names = nil)
|
81
|
+
class_names = class_names.split(' ') if class_names.is_a?(String)
|
82
|
+
class_names = if class_names.empty?
|
83
|
+
''
|
84
|
+
else
|
85
|
+
%( class="#{class_names.map { |name| @class_name_prefix + name }.join(' ')}")
|
86
|
+
end
|
87
|
+
|
88
|
+
%(<span#{class_names}>#{content}</span>)
|
89
|
+
end
|
90
|
+
|
91
|
+
def array_omission
|
92
|
+
span @array_omission, 'omission array'
|
93
|
+
end
|
79
94
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
95
|
+
def text(object, should_truncate = false)
|
96
|
+
object = object.gsub("\n", '\n')
|
97
|
+
object = ::ERB::Util.h(object)
|
98
|
+
object = truncate(object) if should_truncate
|
99
|
+
opening_quote + span(object, 'text') + closing_quote
|
100
|
+
end
|
86
101
|
|
87
|
-
|
88
|
-
|
102
|
+
def string(object)
|
103
|
+
span text(object, true), 'string'
|
104
|
+
end
|
89
105
|
|
90
|
-
|
106
|
+
def link(object)
|
107
|
+
a = %(<a href="#{object}" rel="external">#{text(object)}</a>)
|
108
|
+
span a, 'string link'
|
109
|
+
end
|
91
110
|
|
92
|
-
|
93
|
-
|
94
|
-
row = %Q{<span class="string key"><span class="control quote opening">"</span>#{key}<span class="control quote closing">"</span></span><span class="control colon">:</span> #{node(value)}}
|
111
|
+
def hash(object)
|
112
|
+
return span(opening_curly + closing_curly, 'dictionary') if object.empty?
|
95
113
|
|
96
|
-
|
97
|
-
|
114
|
+
@indent += 1
|
115
|
+
string = opening_curly + "\n"
|
98
116
|
|
99
|
-
|
100
|
-
|
101
|
-
string << rows.join(%Q{<span class="control comma">,</span>\n})
|
117
|
+
rows = []
|
118
|
+
keys = object.keys.collect(&:to_s)
|
102
119
|
|
103
|
-
|
104
|
-
@indent -= 1
|
105
|
-
string << %Q[\n#{tab}<span class="control curley-bracket closing">}</span>]
|
106
|
-
end
|
120
|
+
keys.sort! if @sort_keys
|
107
121
|
|
108
|
-
|
122
|
+
keys.each do |key|
|
123
|
+
value = (!object[key].nil? ? object[key] : object[key.to_sym])
|
124
|
+
row = %(#{span(text(key), 'string key') + colon} #{node(value)})
|
109
125
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
126
|
+
# Wrap row in with class for key.
|
127
|
+
# Hopefully most keys will be sane since it's probably JSON.
|
128
|
+
row = tab + span(row, "key-#{key}")
|
129
|
+
rows << row
|
130
|
+
end
|
131
|
+
string << rows.join(comma + "\n")
|
132
|
+
|
133
|
+
@indent -= 1
|
134
|
+
string << "\n" + tab + closing_curly
|
135
|
+
|
136
|
+
span string, 'dictionary'
|
137
|
+
end
|
138
|
+
|
139
|
+
def array(object)
|
140
|
+
return span(opening_square + closing_square, 'array') if object.empty?
|
141
|
+
|
142
|
+
@indent += 1
|
143
|
+
string = opening_square + "\n"
|
144
|
+
|
145
|
+
rows = []
|
146
|
+
array = @array_limit > 0 ? object[0...@array_limit] : object
|
147
|
+
array.each do |value|
|
148
|
+
rows << tab + node(value)
|
149
|
+
end
|
150
|
+
|
151
|
+
if @array_limit > 0 && object.length > @array_limit
|
152
|
+
rows << tab + (object[0].is_a?(Hash) ? %(#{opening_curly} #{array_omission} #{closing_curly}) : array_omission)
|
137
153
|
end
|
154
|
+
|
155
|
+
string << rows.join(comma + "\n")
|
156
|
+
|
157
|
+
@indent -= 1
|
158
|
+
string << "\n" + tab + closing_square
|
159
|
+
|
160
|
+
span string, 'array'
|
138
161
|
end
|
139
162
|
|
140
|
-
def
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
163
|
+
def opening_quote
|
164
|
+
span '"', 'control quote opening'
|
165
|
+
end
|
166
|
+
|
167
|
+
def closing_quote
|
168
|
+
span '"', 'control quote closing'
|
169
|
+
end
|
170
|
+
|
171
|
+
def opening_curly
|
172
|
+
span '{', 'control bracket curly opening'
|
173
|
+
end
|
174
|
+
|
175
|
+
def closing_curly
|
176
|
+
span '}', 'control bracket curly closing'
|
177
|
+
end
|
178
|
+
|
179
|
+
def opening_square
|
180
|
+
span '[', 'control bracket square opening'
|
181
|
+
end
|
182
|
+
|
183
|
+
def closing_square
|
184
|
+
span ']', 'control bracket square closing'
|
185
|
+
end
|
186
|
+
|
187
|
+
def comma
|
188
|
+
span ',', 'control comma'
|
189
|
+
end
|
190
|
+
|
191
|
+
def colon
|
192
|
+
span ':', 'control colon'
|
145
193
|
end
|
146
194
|
end
|
147
195
|
end
|
data/lib/pizzazz/html.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module Pizzazz
|
2
2
|
def self.ify_html(object, options = nil)
|
3
3
|
p = Colorer.new(object, options)
|
4
|
-
|
4
|
+
|
5
|
+
class_name = 'pizzazz'
|
6
|
+
if class_name_prefix = options[:class_name_prefix]
|
7
|
+
class_name = class_name_prefix + class_name
|
8
|
+
end
|
9
|
+
|
10
|
+
html = %(<pre class="#{class_name}">#{p.ify}</pre>)
|
5
11
|
html = html.html_safe if Pizzazz::RAILS_AVAILABLE
|
6
12
|
html
|
7
13
|
end
|
data/lib/pizzazz/version.rb
CHANGED
data/pizzazz.gemspec
CHANGED
@@ -5,13 +5,13 @@ require File.expand_path('../lib/pizzazz/version', __FILE__)
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.authors = ['Sam Soffes']
|
7
7
|
gem.email = ['sam@soff.es']
|
8
|
-
gem.description =
|
9
|
-
gem.summary =
|
8
|
+
gem.description = 'Add some pizzazz to your documentation'
|
9
|
+
gem.summary = 'A simple gem to code color documentation'
|
10
10
|
gem.homepage = 'http://github.com/soffes/pizzazz'
|
11
11
|
gem.license = 'MIT'
|
12
12
|
|
13
|
-
gem.files = `git ls-files`.split(
|
14
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
15
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
16
|
gem.name = 'pizzazz'
|
17
17
|
gem.require_paths = ['lib']
|
data/test/units/colorer_test.rb
CHANGED
@@ -4,96 +4,90 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
class TestColorer < Pizzazz::TestCase
|
6
6
|
def test_that_it_colors_hashes
|
7
|
-
colored = Pizzazz.ify({
|
8
|
-
assert_equal colored,
|
9
|
-
|
10
|
-
|
7
|
+
colored = Pizzazz.ify({})
|
8
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span><span class="control bracket curly closing">}</span></span>'
|
9
|
+
|
10
|
+
colored = Pizzazz.ify({hello: 'World'})
|
11
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
12
|
+
<span class="control tab"> </span><span class="key-hello"><span class="string key"><span class="control quote opening">"</span><span class="text">hello</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">World</span><span class="control quote closing">"</span></span></span>
|
13
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
11
14
|
end
|
12
15
|
|
13
16
|
def test_new_lines
|
14
|
-
colored = Pizzazz.ify({:
|
15
|
-
assert_equal colored,
|
16
|
-
<span class="control tab"> </span><span class="key-message"><span class="string key"><span class="control quote opening">"</span>message
|
17
|
-
<span class="control tab"></span><span class="control
|
17
|
+
colored = Pizzazz.ify({message: "Hello\nWorld"})
|
18
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
19
|
+
<span class="control tab"> </span><span class="key-message"><span class="string key"><span class="control quote opening">"</span><span class="text">message</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">Hello\nWorld</span><span class="control quote closing">"</span></span></span>
|
20
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_tabs
|
21
|
-
colored = Pizzazz.ify({:
|
22
|
-
assert_equal colored,
|
23
|
-
<span class="control tab">||||</span><span class="key-
|
24
|
-
<span class="control tab"></span><span class="control
|
24
|
+
colored = Pizzazz.ify({message: "Hello"}, tab: '||||')
|
25
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
26
|
+
<span class="control tab">||||</span><span class="key-message"><span class="string key"><span class="control quote opening">"</span><span class="text">message</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">Hello</span><span class="control quote closing">"</span></span></span>
|
27
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
25
28
|
end
|
26
29
|
|
27
30
|
def test_prefix
|
28
|
-
colored = Pizzazz.ify({:
|
29
|
-
assert_equal colored,
|
30
|
-
<span class="prefix"
|
31
|
-
<span class="prefix"
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_omit_root_container
|
35
|
-
colored = Pizzazz.ify({:foo => 'bar'}, omit_root_container: true)
|
36
|
-
assert_equal colored, %q{<span class="control tab"></span><span class="key-foo"><span class="string key"><span class="control quote opening">"</span>foo<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>bar<span class="quote closing">"</span></span></span>}
|
37
|
-
|
38
|
-
colored = Pizzazz.ify([1, 2], omit_root_container: true)
|
39
|
-
assert_equal colored, %q{<span class="control tab"></span><span class="number">1</span><span class="control comma">,</span>
|
40
|
-
<span class="control tab"></span><span class="number">2</span>}
|
31
|
+
colored = Pizzazz.ify({message: "Hello"}, prefix: '*')
|
32
|
+
assert_equal colored, '<span class="prefix">*</span><span class="dictionary"><span class="control bracket curly opening">{</span>
|
33
|
+
<span class="prefix">*</span><span class="control tab"> </span><span class="key-message"><span class="string key"><span class="control quote opening">"</span><span class="text">message</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">Hello</span><span class="control quote closing">"</span></span></span>
|
34
|
+
<span class="prefix">*</span><span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
41
35
|
end
|
42
36
|
|
43
37
|
def test_that_it_truncates_arrays
|
44
38
|
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 2)
|
45
|
-
assert_equal colored,
|
46
|
-
<span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span>numbers
|
39
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
40
|
+
<span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span><span class="text">numbers</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="array"><span class="control bracket square opening">[</span>
|
47
41
|
<span class="control tab"> </span><span class="number">1</span><span class="control comma">,</span>
|
48
42
|
<span class="control tab"> </span><span class="number">2</span><span class="control comma">,</span>
|
49
|
-
<span class="control tab"> </span><span class="array
|
50
|
-
<span class="control tab"> </span><span class="control
|
51
|
-
<span class="control tab"></span><span class="control
|
43
|
+
<span class="control tab"> </span><span class="omission array">…</span>
|
44
|
+
<span class="control tab"> </span><span class="control bracket square closing">]</span></span></span>
|
45
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
52
46
|
|
53
47
|
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 1, :array_omission => 'hello')
|
54
|
-
assert_equal colored,
|
55
|
-
<span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span>numbers
|
48
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
49
|
+
<span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span><span class="text">numbers</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="array"><span class="control bracket square opening">[</span>
|
56
50
|
<span class="control tab"> </span><span class="number">1</span><span class="control comma">,</span>
|
57
|
-
<span class="control tab"> </span><span class="array
|
58
|
-
<span class="control tab"> </span><span class="control
|
59
|
-
<span class="control tab"></span><span class="control
|
51
|
+
<span class="control tab"> </span><span class="omission array">hello</span>
|
52
|
+
<span class="control tab"> </span><span class="control bracket square closing">]</span></span></span>
|
53
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
60
54
|
end
|
61
55
|
|
62
56
|
def test_that_it_truncates_values
|
63
57
|
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 5)
|
64
|
-
assert_equal colored,
|
65
|
-
<span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span>wooden
|
66
|
-
<span class="control tab"></span><span class="control
|
58
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
59
|
+
<span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span><span class="text">wooden</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">base<span class="omission">…</span></span><span class="control quote closing">"</span></span></span>
|
60
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
67
61
|
|
68
62
|
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 9, :value_omission => '!')
|
69
|
-
assert_equal colored,
|
70
|
-
<span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span>wooden
|
71
|
-
<span class="control tab"></span><span class="control
|
63
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
64
|
+
<span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span><span class="text">wooden</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">baseball<span class="omission">!</span></span><span class="control quote closing">"</span></span></span>
|
65
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
72
66
|
end
|
73
67
|
|
74
68
|
def test_link
|
75
69
|
colored = Pizzazz.ify({:website => 'http://soff.es'})
|
76
|
-
assert_equal colored,
|
77
|
-
<span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span>website
|
78
|
-
<span class="control tab"></span><span class="control
|
70
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
71
|
+
<span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span><span class="text">website</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string link"><a href="http://soff.es" rel="external"><span class="control quote opening">"</span><span class="text">http://soff.es</span><span class="control quote closing">"</span></a></span></span>
|
72
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
79
73
|
|
80
74
|
colored = Pizzazz.ify({:website => 'http://soff.es'}, :detect_links => false)
|
81
|
-
assert_equal colored,
|
82
|
-
<span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span>website
|
83
|
-
<span class="control tab"></span><span class="control
|
75
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
76
|
+
<span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span><span class="text">website</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">http://soff.es</span><span class="control quote closing">"</span></span></span>
|
77
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
84
78
|
end
|
85
79
|
|
86
80
|
def test_sort_keys
|
87
81
|
colored = Pizzazz.ify({:b => 'foo', :a => 'bar'})
|
88
|
-
assert_equal colored,
|
89
|
-
<span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span>a
|
90
|
-
<span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span>b
|
91
|
-
<span class="control tab"></span><span class="control
|
82
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
83
|
+
<span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span><span class="text">a</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">bar</span><span class="control quote closing">"</span></span></span><span class="control comma">,</span>
|
84
|
+
<span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span><span class="text">b</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">foo</span><span class="control quote closing">"</span></span></span>
|
85
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
92
86
|
|
93
87
|
colored = Pizzazz.ify({:b => 'foo', :a => 'bar'}, :sort_keys => false)
|
94
|
-
assert_equal colored,
|
95
|
-
<span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span>b
|
96
|
-
<span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span>a
|
97
|
-
<span class="control tab"></span><span class="control
|
88
|
+
assert_equal colored, '<span class="dictionary"><span class="control bracket curly opening">{</span>
|
89
|
+
<span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span><span class="text">b</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">foo</span><span class="control quote closing">"</span></span></span><span class="control comma">,</span>
|
90
|
+
<span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span><span class="text">a</span><span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="control quote opening">"</span><span class="text">bar</span><span class="control quote closing">"</span></span></span>
|
91
|
+
<span class="control tab"></span><span class="control bracket curly closing">}</span></span>'
|
98
92
|
end
|
99
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pizzazz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Add some pizzazz to your documentation
|
14
14
|
email:
|