pizzazz 0.1.3 → 0.1.5
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.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +8 -0
- data/Contributing.markdown +19 -0
- data/Gemfile +1 -1
- data/Readme.markdown +33 -15
- data/lib/pizzazz.rb +0 -2
- data/lib/pizzazz/colorer.rb +27 -16
- data/lib/pizzazz/version.rb +1 -1
- data/pizzazz.gemspec +1 -1
- data/test/test_helper.rb +4 -1
- data/test/units/colorer_test.rb +42 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 138168cc911964bb74660a9273a20e99d6760f1e
|
4
|
+
data.tar.gz: fdb1837bba298c759319428b083cddfba5d5f253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b29436243f29a1f9e7506c2cb6e3e280f54aeb325380c5172aa86c7cbc0de51e4cc25036bde4a0ba1b83536ccfaeac4ef50a08b4aa7dc84a0e001e0b25602d8
|
7
|
+
data.tar.gz: e44e8d3a143237c4f72209b31b688f162be7c61e02d5121f129e1f42affa95dcded30baeddbe1d4349248c6008394fff1f3a3f097523257d0637bd6783b87e53
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## Submitting a Pull Request
|
2
|
+
|
3
|
+
1. [Fork the repository.][fork]
|
4
|
+
2. [Create a topic branch.][branch]
|
5
|
+
3. Add tests for your unimplemented feature or bug fix.
|
6
|
+
4. Run `bundle exec rake`. If your tests pass, return to step 3.
|
7
|
+
5. Implement your feature or bug fix.
|
8
|
+
6. Run `bundle exec rake`. If your tests fail, return to step 5.
|
9
|
+
7. Run `open coverage/index.html`. If your changes are not completely covered
|
10
|
+
by your tests, return to step 3.
|
11
|
+
8. Add documentation for your feature or bug fix.
|
12
|
+
9. Run `bundle exec rake doc`. If your changes are not 100% documented, go
|
13
|
+
back to step 8.
|
14
|
+
10. Add, commit, and push your changes.
|
15
|
+
11. [Submit a pull request.][pr]
|
16
|
+
|
17
|
+
[fork]: http://help.github.com/fork-a-repo/
|
18
|
+
[branch]: http://learn.github.com/p/branching.html
|
19
|
+
[pr]: http://help.github.com/send-pull-requests/
|
data/Gemfile
CHANGED
data/Readme.markdown
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
# Pizzazz
|
2
2
|
|
3
|
+
[](https://travis-ci.org/soffes/pizzazz) [](https://coveralls.io/r/soffes/pizzazz) [](https://codeclimate.com/github/soffes/pizzazz) [](https://gemnasium.com/soffes/pizzazz) [](http://badge.fury.io/rb/pizzazz)
|
4
|
+
|
3
5
|
Pizzazz is a simple pure Ruby implementation of code coloring, but just for JSON. Basically, if you have a ruby object and want to show it converted to JSON and add HTML around it so you can color it.
|
4
6
|
|
5
7
|
[Cheddar](http://cheddarapp.com) uses this to show example output of it's API calls. [Check it out](https://cheddarapp.com/developer/lists).
|
6
8
|
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
gem 'pizzazz'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install pizzazz
|
24
|
+
|
25
|
+
Simple as that.
|
26
|
+
|
27
|
+
|
7
28
|
## Usage
|
8
29
|
|
9
30
|
Pizzazzifing an object is simple:
|
@@ -14,13 +35,18 @@ Pizzazz.ify(object)
|
|
14
35
|
#=> "{\n <span class=\"string\">\"name\"</span>: <span class=\"string\">\"Sam Soffes\"</span>,\n <span class=\"string\">\"website\"</span>: <span class=\"string\">\"http://samsoff.es\"</span>\n}"
|
15
36
|
```
|
16
37
|
|
17
|
-
You can optionally limit arrays as well:
|
38
|
+
You can optionally limit arrays or values as well:
|
18
39
|
|
19
40
|
``` ruby
|
20
|
-
Pizzazz.ify(all_of_the_things,
|
41
|
+
Pizzazz.ify(all_of_the_things, array_limit: 1, value_limit: 100)
|
42
|
+
```
|
43
|
+
|
44
|
+
This will add an ellipses after the first element and truncate values longer than 100 characters. You can replace the ellipses by setting the `array_omission` and then `value_omission` options:
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
Pizzazz.ify(all_of_the_things, array_limit: 'etc', value_omission: '... (continued)')
|
21
48
|
```
|
22
49
|
|
23
|
-
This will add an ellipses after the first element.
|
24
50
|
|
25
51
|
### HTML
|
26
52
|
|
@@ -43,20 +69,12 @@ Pizzazz.ify_html(object)
|
|
43
69
|
|
44
70
|
If you're using the asset pipeline, you can simply require `pizzazz` to get my stylesheet. Be sure your `<pre>` has the `pizzazz` class. If you use `ify_html` it will automatically do this.
|
45
71
|
|
46
|
-
## Installation
|
47
72
|
|
48
|
-
|
73
|
+
## Supported Ruby Versions
|
49
74
|
|
50
|
-
|
51
|
-
gem 'pizzazz'
|
52
|
-
```
|
53
|
-
|
54
|
-
And then execute:
|
75
|
+
Pizzazz is tested under 1.9.2, 1.9.3, 2.0.0, JRuby 1.7.2 (1.9 mode), and Rubinius 2.0.0 (1.9 mode).
|
55
76
|
|
56
|
-
$ bundle
|
57
|
-
|
58
|
-
Or install it yourself as:
|
59
77
|
|
60
|
-
|
78
|
+
## Contributing
|
61
79
|
|
62
|
-
|
80
|
+
See the [contributing guide](Contributing.markdown).
|
data/lib/pizzazz.rb
CHANGED
data/lib/pizzazz/colorer.rb
CHANGED
@@ -7,24 +7,35 @@ module Pizzazz
|
|
7
7
|
options ||= {}
|
8
8
|
@object = object
|
9
9
|
@indent = 0
|
10
|
-
@
|
10
|
+
@array_limit = options[:array_limit] || options[:limit] || 0
|
11
|
+
@array_omission = options[:array_omission] || '…'
|
12
|
+
@value_limit = options[:value_limit] || 0
|
13
|
+
@value_omission = options[:value_omission] || '…'
|
14
|
+
@tab = options[:tab] || ' '
|
11
15
|
end
|
12
|
-
|
16
|
+
|
13
17
|
def ify
|
14
18
|
return '' unless @object
|
15
|
-
node(@object
|
19
|
+
node(@object)
|
16
20
|
end
|
17
|
-
|
21
|
+
|
18
22
|
private
|
19
|
-
|
23
|
+
|
20
24
|
def tab
|
21
|
-
|
25
|
+
@tab * @indent
|
26
|
+
end
|
27
|
+
|
28
|
+
def truncate(string)
|
29
|
+
return string if @value_limit < 1
|
30
|
+
text = string.dup
|
31
|
+
stop = @value_limit - @value_omission.length
|
32
|
+
(text.length > @value_limit ? text[0...stop] + @value_omission : text).to_s
|
22
33
|
end
|
23
|
-
|
24
|
-
def node(object
|
34
|
+
|
35
|
+
def node(object)
|
25
36
|
case object
|
26
37
|
when String
|
27
|
-
%Q{<span class="string">"#{::ERB::Util.h(object)}"</span>}
|
38
|
+
%Q{<span class="string">"#{truncate(::ERB::Util.h(object))}"</span>}
|
28
39
|
when Time
|
29
40
|
%Q{<span class="string">#{object.to_json}</span>}
|
30
41
|
when TrueClass
|
@@ -41,11 +52,11 @@ module Pizzazz
|
|
41
52
|
rows = []
|
42
53
|
object.keys.collect(&:to_s).sort.each do |key|
|
43
54
|
value = (object[key] != nil ? object[key] : object[key.to_sym])
|
44
|
-
rows << %Q{#{tab}<span class="string">"#{key}"</span>: #{node(value)}}
|
55
|
+
rows << %Q{#{tab}<span class="string key">"#{key}"</span>: #{node(value)}}
|
45
56
|
end
|
46
57
|
s << rows.join(",\n") + "\n"
|
47
58
|
@indent -= 1
|
48
|
-
s << "#{tab}}"
|
59
|
+
s << "#{tab}}"
|
49
60
|
s
|
50
61
|
when Array
|
51
62
|
if object.length == 0
|
@@ -54,15 +65,15 @@ module Pizzazz
|
|
54
65
|
s = "[\n"
|
55
66
|
@indent += 1
|
56
67
|
rows = []
|
57
|
-
array = @
|
68
|
+
array = @array_limit > 0 ? object[0...@array_limit] : object
|
58
69
|
array.each do |value|
|
59
70
|
rows << tab + node(value)
|
60
71
|
end
|
61
|
-
|
62
|
-
if
|
63
|
-
rows << tab + (object[0].is_a?(Hash) ?
|
72
|
+
|
73
|
+
if @array_limit > 0 and object.length > @array_limit
|
74
|
+
rows << tab + (object[0].is_a?(Hash) ? "{ #{@array_omission} }" : @array_omission)
|
64
75
|
end
|
65
|
-
|
76
|
+
|
66
77
|
s << rows.join(",\n") + "\n"
|
67
78
|
@indent -= 1
|
68
79
|
s << "#{tab}]"
|
data/lib/pizzazz/version.rb
CHANGED
data/pizzazz.gemspec
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,6 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'bundler'
|
3
3
|
Bundler.require :test
|
4
4
|
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
5
8
|
require 'simplecov'
|
6
9
|
SimpleCov.start
|
7
10
|
|
@@ -13,5 +16,5 @@ Dir["#{File.expand_path(File.dirname(__FILE__))}/support/*.rb"].each do |file|
|
|
13
16
|
require file
|
14
17
|
end
|
15
18
|
|
16
|
-
class Pizzazz::TestCase <
|
19
|
+
class Pizzazz::TestCase < Minitest::Test
|
17
20
|
end
|
data/test/units/colorer_test.rb
CHANGED
@@ -1,9 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class TestColorer < Pizzazz::TestCase
|
4
5
|
def test_that_it_colors_hashes
|
5
|
-
|
6
|
+
colored = Pizzazz.ify({:foo => 'bar'})
|
7
|
+
assert_equal colored, %Q{{
|
8
|
+
<span class="string key">"foo"</span>: <span class="string">"bar"</span>
|
9
|
+
}}
|
6
10
|
end
|
7
11
|
|
8
|
-
|
12
|
+
def test_tabs
|
13
|
+
colored = Pizzazz.ify({:foo => 'bar'}, tab: '||||')
|
14
|
+
assert_equal colored, %Q{{
|
15
|
+
||||<span class="string key">"foo"</span>: <span class="string">"bar"</span>
|
16
|
+
}}
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_it_truncates_arrays
|
20
|
+
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 2)
|
21
|
+
assert_equal colored, %Q{{
|
22
|
+
<span class=\"string key\">\"numbers\"</span>: [
|
23
|
+
<span class=\"number\">1</span>,
|
24
|
+
<span class=\"number\">2</span>,
|
25
|
+
…
|
26
|
+
]
|
27
|
+
}}
|
28
|
+
|
29
|
+
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 1, :array_omission => 'hello')
|
30
|
+
assert_equal colored, %Q{{
|
31
|
+
<span class=\"string key\">\"numbers\"</span>: [
|
32
|
+
<span class=\"number\">1</span>,
|
33
|
+
hello
|
34
|
+
]
|
35
|
+
}}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_that_it_truncates_values
|
39
|
+
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 5)
|
40
|
+
assert_equal colored, %Q{{
|
41
|
+
<span class="string key">"wooden"</span>: <span class="string">"base…"</span>
|
42
|
+
}}
|
43
|
+
|
44
|
+
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 9, :value_omission => '!')
|
45
|
+
assert_equal colored, %Q{{
|
46
|
+
<span class="string key">"wooden"</span>: <span class="string">"baseball!"</span>
|
47
|
+
}}
|
48
|
+
end
|
9
49
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Add some pizzazz to your documentation
|
14
14
|
email:
|
@@ -17,7 +17,10 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- .coveralls.yml
|
20
21
|
- .gitignore
|
22
|
+
- .travis.yml
|
23
|
+
- Contributing.markdown
|
21
24
|
- Gemfile
|
22
25
|
- LICENSE
|
23
26
|
- Rakefile
|
@@ -43,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
46
|
requirements:
|
44
47
|
- - '>='
|
45
48
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
49
|
+
version: 1.9.2
|
47
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
51
|
requirements:
|
49
52
|
- - '>='
|
@@ -51,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
54
|
version: '0'
|
52
55
|
requirements: []
|
53
56
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.0.
|
57
|
+
rubygems_version: 2.0.2
|
55
58
|
signing_key:
|
56
59
|
specification_version: 4
|
57
60
|
summary: A simple gem to code color documentation
|