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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e02cd57798e3c118c87002a9752f03997178b32
4
- data.tar.gz: 50b693e72a290357a01276a67b35963d84b9c8d9
3
+ metadata.gz: 78ba9b2f27bf01cd6e8ca21e219c36ee83779c89
4
+ data.tar.gz: 28b1c4445d13227011d80a91ab0be3d5829ad5b8
5
5
  SHA512:
6
- metadata.gz: c8dc4e76f1867e50470ba4574932b21757fc980f33524e95073e4db140290c4981d7f580c33ed073b7e5fd1df7290617c4d95c9de52c5b8c3ea696779d11b56b
7
- data.tar.gz: 990143e7286b36a6498ad5890af316d002476aed00bb796eff640aec3ed4f1349b0399f5f517f30470be606147ef2d50b83e3a9b85b5d31274174208fe18d3fd
6
+ metadata.gz: 0aa2ff88e3a96caee02b7050a1db9410bbf9d6ab9a585531716de9163a9e5d0e4335e24287e301b72d169026b9ee1220676ef68169a5c5b49df4f5905ec541a7
7
+ data.tar.gz: 89b52e03781a8a4e436da67c40b582238f8b1a892d3e0679e04040cc3ada346de5fc00d36a27f1b929cdd8ae16200dd6e45c1ff55ef66fa79712bc2e13801692
data/Rakefile CHANGED
@@ -6,4 +6,4 @@ Rake::TestTask.new(:test) do |t|
6
6
  t.libs << 'test'
7
7
  t.pattern = 'test/**/*_test.rb'
8
8
  end
9
- task :default => :test
9
+ task default: :test
@@ -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
- #=> "{\n <span class=\"string key\">\"name\"</span>: <span class=\"string\">\"Sam Soffes\"</span>,\n <span class=\"string key\">\"website\"</span>: <span class=\"string\">\"http://soff.es\"</span>\n}"
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 `omit_root_container` and `prefix`, a string that's added to the beginning of each line of the output, is really nice for doing custom things. Both options can be used independently as well.
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:
@@ -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
- @omit_root_container = options[:omit_root_container] || false
19
- @detect_links = options[:detect_links] == nil ? true : options[:detect_links]
20
- @sort_keys = options[:sort_keys] == nil ? true : options[:sort_keys]
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, true)
28
+ output = node(@object)
28
29
  return output unless @prefix
29
30
 
30
31
  # Add prefix
31
- prefix = %Q{<span class="prefix">#{@prefix}</span>}
32
+ prefix = span(@prefix, 'prefix')
32
33
  lines = output.split("\n")
33
34
  prefix + lines.join("\n#{prefix}")
34
35
  end
35
36
 
36
- private
37
+ private
37
38
 
38
- URL_PATTERN = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,})([\/\w \.-]*)*\/?$/i
39
+ URL_PATTERN = %r{^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,})([/\w \.-]*)*/?$}i
39
40
 
40
41
  def tab
41
- %Q{<span class="control tab">#{@tab * @indent}</span>}
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, root = false)
52
- omit_container = root && @omit_root_container
53
-
52
+ def node(object)
54
53
  case object
55
54
  when String
56
- if @detect_links && is_link?(object)
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
- %Q{<span class="string">#{object.to_json}</span>}
64
-
57
+ span object.to_json, 'string time'
65
58
  when TrueClass
66
- %Q{<span class="constant">true</span>}
67
-
59
+ span 'true', 'boolean true'
68
60
  when FalseClass
69
- %Q{<span class="constant">false</span>}
70
-
61
+ span 'false', 'boolean false'
71
62
  when NilClass
72
- %Q{<span class="null">null</span>}
73
-
63
+ span 'null', 'null'
74
64
  when Numeric
75
- %Q{<span class="number">#{object}</span>}
76
-
65
+ span object, 'number'
77
66
  when Hash
78
- return omit_container ? '' : '<span class="control curly-bracket opening">{</span><span class="control curly-bracket closing">}</span>' if object.length == 0
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
- string = if omit_container
81
- ''
82
- else
83
- @indent += 1
84
- %Q[<span class="control curly-bracket opening">{</span>\n]
85
- end
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
- rows = []
88
- keys = object.keys.collect(&:to_s)
102
+ def string(object)
103
+ span text(object, true), 'string'
104
+ end
89
105
 
90
- keys.sort! if @sort_keys
106
+ def link(object)
107
+ a = %(<a href="#{object}" rel="external">#{text(object)}</a>)
108
+ span a, 'string link'
109
+ end
91
110
 
92
- keys.each do |key|
93
- value = (object[key] != nil ? object[key] : object[key.to_sym])
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
- # Hopefully most keys will be sane since there are probably JSON
97
- row = %Q{<span class="key-#{key}">#{row}</span>}
114
+ @indent += 1
115
+ string = opening_curly + "\n"
98
116
 
99
- rows << tab + row
100
- end
101
- string << rows.join(%Q{<span class="control comma">,</span>\n})
117
+ rows = []
118
+ keys = object.keys.collect(&:to_s)
102
119
 
103
- unless omit_container
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
- string
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
- when Array
111
- return omit_container ? '' : '<span class="control square-bracket opening">[</span><span class="control square-bracket closing">]</span>' if object.length == 0
112
- string = if omit_container
113
- ''
114
- else
115
- @indent += 1
116
- %Q{<span class="control square-bracket opening">[</span>\n}
117
- end
118
-
119
- rows = []
120
- array = @array_limit > 0 ? object[0...@array_limit] : object
121
- array.each do |value|
122
- rows << tab + node(value)
123
- end
124
-
125
- if @array_limit > 0 and object.length > @array_limit
126
- rows << tab + (object[0].is_a?(Hash) ? %Q[<span class="control curley-bracket opening">{</span> <span class="array-omission">#{@array_omission}</span> <span class="control curley-bracket closing">}</span>] : %Q{<span class="array-omission">#{@array_omission}</span>})
127
- end
128
-
129
- string << rows.join(%Q{<span class="control comma">,</span>\n})
130
-
131
- unless omit_container
132
- @indent -= 1
133
- string << %Q{\n#{tab}<span class="control square-bracket closing">]</span>}
134
- end
135
-
136
- string
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 is_link?(string)
141
- scheme = URI.parse(string).scheme
142
- scheme == 'http' || scheme == 'https'
143
- rescue
144
- false
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
@@ -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
- html = %Q{<pre class="pizzazz">#{p.ify}</pre>}
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
@@ -1,3 +1,3 @@
1
1
  module Pizzazz
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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 = %q{Add some pizzazz to your documentation}
9
- gem.summary = %q{A simple gem to code color documentation}
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']
@@ -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({:foo => 'bar'})
8
- assert_equal colored, %q{<span class="control curly-bracket opening">{</span>
9
- <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>
10
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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({:message => "hello\nworld"})
15
- assert_equal colored, %q{<span class="control curly-bracket opening">{</span>
16
- <span class="control tab"> </span><span class="key-message"><span class="string key"><span class="control quote opening">"</span>message<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>hello\nworld<span class="quote closing">"</span></span></span>
17
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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({:foo => 'bar'}, tab: '||||')
22
- assert_equal colored, %q{<span class="control curly-bracket opening">{</span>
23
- <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>
24
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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({:foo => 'bar'}, prefix: '**')
29
- assert_equal colored, %q{<span class="prefix">**</span><span class="control curly-bracket opening">{</span>
30
- <span class="prefix">**</span><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>
31
- <span class="prefix">**</span><span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
46
- <span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span>numbers<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="control square-bracket opening">[</span>
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-omission">…</span>
50
- <span class="control tab"> </span><span class="control square-bracket closing">]</span></span>
51
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
55
- <span class="control tab"> </span><span class="key-numbers"><span class="string key"><span class="control quote opening">"</span>numbers<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="control square-bracket opening">[</span>
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-omission">hello</span>
58
- <span class="control tab"> </span><span class="control square-bracket closing">]</span></span>
59
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
65
- <span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span>wooden<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>base…<span class="quote closing">"</span></span></span>
66
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
70
- <span class="control tab"> </span><span class="key-wooden"><span class="string key"><span class="control quote opening">"</span>wooden<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>baseball!<span class="quote closing">"</span></span></span>
71
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
77
- <span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span>website<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="quote opening">"</span><span class="text">http://soff.es</span><span class="quote closing">"</span></a></span></span>
78
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
82
- <span class="control tab"> </span><span class="key-website"><span class="string key"><span class="control quote opening">"</span>website<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>http://soff.es<span class="quote closing">"</span></span></span>
83
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
89
- <span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span>a<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><span class="control comma">,</span>
90
- <span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span>b<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>foo<span class="quote closing">"</span></span></span>
91
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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, %q{<span class="control curly-bracket opening">{</span>
95
- <span class="control tab"> </span><span class="key-b"><span class="string key"><span class="control quote opening">"</span>b<span class="control quote closing">"</span></span><span class="control colon">:</span> <span class="string"><span class="quote opening">"</span>foo<span class="quote closing">"</span></span></span><span class="control comma">,</span>
96
- <span class="control tab"> </span><span class="key-a"><span class="string key"><span class="control quote opening">"</span>a<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>
97
- <span class="control tab"></span><span class="control curley-bracket closing">}</span>}
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.3.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-15 00:00:00.000000000 Z
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: