pizzazz 0.1.5 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 138168cc911964bb74660a9273a20e99d6760f1e
4
- data.tar.gz: fdb1837bba298c759319428b083cddfba5d5f253
3
+ metadata.gz: 911b76d39b0db46706802fa1e1d0ef2448d3eedb
4
+ data.tar.gz: 180cefc3ed5d5fabf486222e198b91ebb877c45f
5
5
  SHA512:
6
- metadata.gz: 0b29436243f29a1f9e7506c2cb6e3e280f54aeb325380c5172aa86c7cbc0de51e4cc25036bde4a0ba1b83536ccfaeac4ef50a08b4aa7dc84a0e001e0b25602d8
7
- data.tar.gz: e44e8d3a143237c4f72209b31b688f162be7c61e02d5121f129e1f42affa95dcded30baeddbe1d4349248c6008394fff1f3a3f097523257d0637bd6783b87e53
6
+ metadata.gz: 3ad86b100a133cdb265a492204c28f6bd50e7bd9b9f0fdb50bd6a6ad8cab2ce2617b7b27a14a6254641599522658461c3bd17fe8f5c3e7c1c573dc82ed92ab99
7
+ data.tar.gz: b9375ff39aa354c3c33e648fbf76e4ad9c43f73f4656ece4567f42c8ade06a80295a243dd0cbbe81dca38f77da9776344198e0386b49920fdf3886c0994a7afd
@@ -2,7 +2,7 @@ language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
4
  - 1.9.2
5
- - 1.9.3
6
5
  - 2.0.0
6
+ - 2.2.4
7
7
  - jruby-19mode
8
8
  - rbx-19mode
data/Gemfile CHANGED
@@ -2,10 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake', :group => [:development, :test]
5
+ gem 'rake', group: [:development, :test]
6
6
 
7
7
  group :test do
8
8
  gem 'minitest'
9
- gem 'simplecov', :require => false
10
- gem 'coveralls', :require => false
9
+ gem 'minitest-reporters', require: 'minitest/reporters'
10
+ gem 'simplecov'
11
+ gem 'codeclimate-test-reporter'
11
12
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2013 Sam Soffes
1
+ Copyright (c) 2012-2016 Sam Soffes
2
2
 
3
3
  MIT License
4
4
 
@@ -1,10 +1,9 @@
1
1
  # Pizzazz
2
2
 
3
- [![Build Status](https://travis-ci.org/soffes/pizzazz.png?branch=master)](https://travis-ci.org/soffes/pizzazz) [![Coverage Status](https://coveralls.io/repos/soffes/pizzazz/badge.png?branch=master)](https://coveralls.io/r/soffes/pizzazz) [![Code Climate](https://codeclimate.com/github/soffes/pizzazz.png)](https://codeclimate.com/github/soffes/pizzazz) [![Dependency Status](https://gemnasium.com/soffes/pizzazz.png)](https://gemnasium.com/soffes/pizzazz) [![Gem Version](https://badge.fury.io/rb/pizzazz.png)](http://badge.fury.io/rb/pizzazz)
3
+ [![Build Status](https://travis-ci.org/soffes/pizzazz.png?branch=master)](https://travis-ci.org/soffes/pizzazz) [![Test Coverage](https://codeclimate.com/github/soffes/pizzazz/badges/coverage.svg)](https://codeclimate.com/github/soffes/pizzazz/coverage) [![Code Climate](https://codeclimate.com/github/soffes/pizzazz.png)](https://codeclimate.com/github/soffes/pizzazz) [![Dependency Status](https://gemnasium.com/soffes/pizzazz.png)](https://gemnasium.com/soffes/pizzazz) [![Gem Version](https://badge.fury.io/rb/pizzazz.png)](http://badge.fury.io/rb/pizzazz)
4
4
 
5
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.
6
6
 
7
- [Cheddar](http://cheddarapp.com) uses this to show example output of it's API calls. [Check it out](https://cheddarapp.com/developer/lists).
8
7
 
9
8
  ## Installation
10
9
 
@@ -30,9 +29,9 @@ Simple as that.
30
29
  Pizzazzifing an object is simple:
31
30
 
32
31
  ``` ruby
33
- object = { name: 'Sam Soffes', website: 'http://samsoff.es' }
32
+ object = { name: 'Sam Soffes', website: 'http://soff.es' }
34
33
  Pizzazz.ify(object)
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}"
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}"
36
35
  ```
37
36
 
38
37
  You can optionally limit arrays or values as well:
@@ -47,6 +46,8 @@ This will add an ellipses after the first element and truncate values longer tha
47
46
  Pizzazz.ify(all_of_the_things, array_limit: 'etc', value_omission: '... (continued)')
48
47
  ```
49
48
 
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.
50
+
50
51
 
51
52
  ### HTML
52
53
 
@@ -72,7 +73,7 @@ If you're using the asset pipeline, you can simply require `pizzazz` to get my s
72
73
 
73
74
  ## Supported Ruby Versions
74
75
 
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).
76
+ Pizzazz is tested under 1.9.2, 2.0.0, 2.2.4, JRuby 1.7.2 (1.9 mode), and Rubinius 2.0.0 (1.9 mode).
76
77
 
77
78
 
78
79
  ## Contributing
@@ -1,19 +1,18 @@
1
1
  module Pizzazz
2
+ RAILS_AVAILABLE = begin
3
+ require 'rails'
4
+ require 'pizzazz/engine'
5
+ true
6
+ rescue LoadError
7
+ false
8
+ end
9
+
2
10
  def self.ify(object, options = nil)
3
11
  p = Colorer.new(object, options)
4
12
  p.ify
5
13
  end
6
14
  end
7
15
 
8
- # TODO: This is ugly. I'd love a better solution.
9
- begin
10
- require 'rails'
11
- require 'pizzazz/engine'
12
- Pizzazz::RAILS_AVAILABLE = true
13
- rescue LoadError
14
- Pizzazz::RAILS_AVAILABLE = false
15
- end
16
-
17
16
  require 'pizzazz/colorer'
18
17
  require 'pizzazz/html'
19
18
  require 'pizzazz/version'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+
2
3
  require 'erb'
3
4
 
4
5
  module Pizzazz
@@ -12,11 +13,20 @@ module Pizzazz
12
13
  @value_limit = options[:value_limit] || 0
13
14
  @value_omission = options[:value_omission] || '…'
14
15
  @tab = options[:tab] || ' '
16
+ @prefix = options[:prefix]
17
+ @omit_root_container = options[:omit_root_container] || false
15
18
  end
16
19
 
17
20
  def ify
18
21
  return '' unless @object
19
- node(@object)
22
+
23
+ # Parse
24
+ output = node(@object, true)
25
+ return output unless @prefix
26
+
27
+ # Add prefix
28
+ lines = output.split("\n")
29
+ @prefix + lines.join("\n#{@prefix}")
20
30
  end
21
31
 
22
32
  private
@@ -32,53 +42,79 @@ module Pizzazz
32
42
  (text.length > @value_limit ? text[0...stop] + @value_omission : text).to_s
33
43
  end
34
44
 
35
- def node(object)
45
+ def node(object, root = false)
46
+ omit_container = root && @omit_root_container
47
+
36
48
  case object
37
49
  when String
38
50
  %Q{<span class="string">"#{truncate(::ERB::Util.h(object))}"</span>}
51
+
39
52
  when Time
40
53
  %Q{<span class="string">#{object.to_json}</span>}
54
+
41
55
  when TrueClass
42
56
  %Q{<span class="constant">true</span>}
57
+
43
58
  when FalseClass
44
59
  %Q{<span class="constant">false</span>}
60
+
45
61
  when NilClass
46
62
  %Q{<span class="null">null</span>}
63
+
47
64
  when Numeric
48
65
  %Q{<span class="number">#{object}</span>}
66
+
49
67
  when Hash
50
- s = "{\n"
51
- @indent += 1
68
+ return omit_container ? '' : '{}' if object.length == 0
69
+
70
+ string = if omit_container
71
+ ''
72
+ else
73
+ @indent += 1
74
+ "{\n"
75
+ end
76
+
52
77
  rows = []
53
78
  object.keys.collect(&:to_s).sort.each do |key|
54
79
  value = (object[key] != nil ? object[key] : object[key.to_sym])
55
80
  rows << %Q{#{tab}<span class="string key">"#{key}"</span>: #{node(value)}}
56
81
  end
57
- s << rows.join(",\n") + "\n"
58
- @indent -= 1
59
- s << "#{tab}}"
60
- s
82
+ string << rows.join(",\n")
83
+
84
+ unless omit_container
85
+ @indent -= 1
86
+ string << "\n#{tab}}"
87
+ end
88
+
89
+ string
90
+
61
91
  when Array
62
- if object.length == 0
63
- "[]"
92
+ return omit_container ? '' : '[]' if object.length == 0
93
+ string = if omit_container
94
+ ''
64
95
  else
65
- s = "[\n"
66
96
  @indent += 1
67
- rows = []
68
- array = @array_limit > 0 ? object[0...@array_limit] : object
69
- array.each do |value|
70
- rows << tab + node(value)
71
- end
97
+ "[\n"
98
+ end
72
99
 
73
- if @array_limit > 0 and object.length > @array_limit
74
- rows << tab + (object[0].is_a?(Hash) ? "{ #{@array_omission} }" : @array_omission)
75
- end
100
+ rows = []
101
+ array = @array_limit > 0 ? object[0...@array_limit] : object
102
+ array.each do |value|
103
+ rows << tab + node(value)
104
+ end
105
+
106
+ if @array_limit > 0 and object.length > @array_limit
107
+ rows << tab + (object[0].is_a?(Hash) ? "{ #{@array_omission} }" : @array_omission)
108
+ end
109
+
110
+ string << rows.join(",\n")
76
111
 
77
- s << rows.join(",\n") + "\n"
112
+ unless omit_container
78
113
  @indent -= 1
79
- s << "#{tab}]"
80
- s
114
+ string << "\n#{tab}]"
81
115
  end
116
+
117
+ string
82
118
  end
83
119
  end
84
120
  end
@@ -1,3 +1,3 @@
1
1
  module Pizzazz
2
- VERSION = '0.1.5'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,12 +1,13 @@
1
1
  # encoding: UTF-8
2
+
2
3
  require File.expand_path('../lib/pizzazz/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
5
6
  gem.authors = ['Sam Soffes']
6
- gem.email = ['sam@samsoff.es']
7
+ gem.email = ['sam@soff.es']
7
8
  gem.description = %q{Add some pizzazz to your documentation}
8
9
  gem.summary = %q{A simple gem to code color documentation}
9
- gem.homepage = 'http://github.com/samsoffes/pizzazz'
10
+ gem.homepage = 'http://github.com/soffes/pizzazz'
10
11
  gem.license = 'MIT'
11
12
 
12
13
  gem.files = `git ls-files`.split($\)
@@ -2,12 +2,11 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.require :test
4
4
 
5
- require 'coveralls'
6
- Coveralls.wear!
7
-
8
- require 'simplecov'
5
+ CodeClimate::TestReporter.start
9
6
  SimpleCov.start
10
7
 
8
+ Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new
9
+
11
10
  require 'minitest/autorun'
12
11
  require 'pizzazz'
13
12
 
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class TestColorer < Pizzazz::TestCase
@@ -16,6 +17,21 @@ class TestColorer < Pizzazz::TestCase
16
17
  }}
17
18
  end
18
19
 
20
+ def test_prefix
21
+ colored = Pizzazz.ify({:foo => 'bar'}, prefix: '**')
22
+ assert_equal colored, %Q{**{
23
+ ** <span class="string key">"foo"</span>: <span class="string">"bar"</span>
24
+ **}}
25
+ end
26
+
27
+ def test_omit_root_container
28
+ colored = Pizzazz.ify({:foo => 'bar'}, omit_root_container: true)
29
+ assert_equal colored, %Q{<span class="string key">"foo"</span>: <span class="string">"bar"</span>}
30
+
31
+ colored = Pizzazz.ify([1, 2], omit_root_container: true)
32
+ assert_equal colored, %Q{<span class="number">1</span>,\n<span class="number">2</span>}
33
+ end
34
+
19
35
  def test_that_it_truncates_arrays
20
36
  colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 2)
21
37
  assert_equal colored, %Q{{
metadata CHANGED
@@ -1,25 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pizzazz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.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: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Add some pizzazz to your documentation
14
14
  email:
15
- - sam@samsoff.es
15
+ - sam@soff.es
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .coveralls.yml
21
- - .gitignore
22
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".travis.yml"
23
22
  - Contributing.markdown
24
23
  - Gemfile
25
24
  - LICENSE
@@ -34,7 +33,7 @@ files:
34
33
  - pizzazz.gemspec
35
34
  - test/test_helper.rb
36
35
  - test/units/colorer_test.rb
37
- homepage: http://github.com/samsoffes/pizzazz
36
+ homepage: http://github.com/soffes/pizzazz
38
37
  licenses:
39
38
  - MIT
40
39
  metadata: {}
@@ -44,17 +43,17 @@ require_paths:
44
43
  - lib
45
44
  required_ruby_version: !ruby/object:Gem::Requirement
46
45
  requirements:
47
- - - '>='
46
+ - - ">="
48
47
  - !ruby/object:Gem::Version
49
48
  version: 1.9.2
50
49
  required_rubygems_version: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - '>='
51
+ - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  requirements: []
56
55
  rubyforge_project:
57
- rubygems_version: 2.0.2
56
+ rubygems_version: 2.5.1
58
57
  signing_key:
59
58
  specification_version: 4
60
59
  summary: A simple gem to code color documentation
@@ -1 +0,0 @@
1
- service_name: travis-ci