pizzazz 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.markdown +11 -28
- data/app/assets/stylesheets/pizzazz.css +22 -0
- data/lib/pizzazz.rb +3 -1
- data/lib/pizzazz/colorer.rb +60 -58
- data/lib/pizzazz/engine.rb +4 -0
- data/lib/pizzazz/html.rb +8 -0
- data/lib/pizzazz/version.rb +1 -1
- metadata +6 -3
data/Readme.markdown
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
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
4
|
|
5
|
+
[Cheddar](http://cheddarapp.com) uses this to show example output of it's API calls. [Check it out](https://cheddarapp.com/developer/lists).
|
6
|
+
|
5
7
|
## Usage
|
6
8
|
|
7
9
|
Pizzazzifing an object is simple:
|
@@ -25,41 +27,22 @@ This will add an ellipses after the first element.
|
|
25
27
|
Spans are added around various elements. Here's the classes:
|
26
28
|
|
27
29
|
* `string`
|
28
|
-
* `constant` (
|
30
|
+
* `constant` (`true` or `false`)
|
29
31
|
* `null`
|
30
32
|
* `number`
|
31
33
|
|
32
|
-
Everything else is left alone.
|
34
|
+
Everything else is left alone.
|
33
35
|
|
34
|
-
|
35
|
-
<pre><%= Pizzazz.ify(object).html_safe %></pre>
|
36
|
-
```
|
36
|
+
If you want it wrapped in `<pre class="pizzazz">` (and call `html_safe` if possible), do the following:
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
``` css
|
41
|
-
pre {
|
42
|
-
border-radius: 5px;
|
43
|
-
background: #f7f7f7;
|
44
|
-
padding: 0.5em;
|
45
|
-
margin-bottom: 2em;
|
46
|
-
border: 1px solid #ddd;
|
47
|
-
}
|
48
|
-
|
49
|
-
.string {
|
50
|
-
color: #ee6132;
|
51
|
-
}
|
52
|
-
|
53
|
-
.null, .number, .constant {
|
54
|
-
color: #8e75c3;
|
55
|
-
}
|
56
|
-
|
57
|
-
.comment {
|
58
|
-
color: #999;
|
59
|
-
font-style: italic;
|
60
|
-
}
|
38
|
+
``` ruby
|
39
|
+
Pizzazz.ify_html(object)
|
61
40
|
```
|
62
41
|
|
42
|
+
### Stylesheet
|
43
|
+
|
44
|
+
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
|
+
|
63
46
|
## Installation
|
64
47
|
|
65
48
|
Add this line to your application's Gemfile:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
pre.pizzazz {
|
2
|
+
border-radius: 5px;
|
3
|
+
background: #f7f7f7;
|
4
|
+
padding: 0.5em;
|
5
|
+
margin-bottom: 2em;
|
6
|
+
border: 1px solid #ddd;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre.pizzazz span.string {
|
10
|
+
color: #ee6132;
|
11
|
+
}
|
12
|
+
|
13
|
+
pre.pizzazz span.null,
|
14
|
+
pre.pizzazz span.number,
|
15
|
+
pre.pizzazz span.constant {
|
16
|
+
color: #8e75c3;
|
17
|
+
}
|
18
|
+
|
19
|
+
pre.pizzazz span.comment {
|
20
|
+
color: #999;
|
21
|
+
font-style: italic;
|
22
|
+
}
|
data/lib/pizzazz.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'pizzazz/colorer'
|
2
|
+
require 'pizzazz/html'
|
3
|
+
require 'pizzazz/engine'
|
2
4
|
require 'pizzazz/version'
|
3
5
|
|
4
6
|
module Pizzazz
|
5
7
|
TAB_SIZE = 2
|
6
8
|
|
7
9
|
def self.ify(object, options = nil)
|
8
|
-
p =
|
10
|
+
p = Colorer.new(object, options)
|
9
11
|
p.ify
|
10
12
|
end
|
11
13
|
end
|
data/lib/pizzazz/colorer.rb
CHANGED
@@ -1,70 +1,72 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'erb'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
options
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
rows = []
|
40
|
-
object.keys.collect(&:to_s).sort.each do |key|
|
41
|
-
value = (object[key] != nil ? object[key] : object[key.to_sym])
|
42
|
-
rows << %Q{#{tab}<span class="string">"#{key}"</span>: #{node(value)}}
|
43
|
-
end
|
44
|
-
s << rows.join(",\n") + "\n"
|
45
|
-
@indent -= 1
|
46
|
-
s << "#{tab}}"
|
47
|
-
s
|
48
|
-
when Array
|
49
|
-
if object.length == 0
|
50
|
-
"[]"
|
51
|
-
else
|
52
|
-
s = "[\n"
|
4
|
+
module Pizzazz
|
5
|
+
class Colorer
|
6
|
+
def initialize(object, options = nil)
|
7
|
+
options ||= {}
|
8
|
+
@object = object
|
9
|
+
@indent = 0
|
10
|
+
@limit = (options[:limit] or 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def ify
|
14
|
+
node(@object, @limit)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def tab
|
20
|
+
" " * @indent * Pizzazz::TAB_SIZE
|
21
|
+
end
|
22
|
+
|
23
|
+
def node(object, limit = 0)
|
24
|
+
case object
|
25
|
+
when String
|
26
|
+
%Q{<span class="string">"#{::ERB::Util.h(object)}"</span>}
|
27
|
+
when Time
|
28
|
+
%Q{<span class="string">#{object.to_json}</span>}
|
29
|
+
when TrueClass
|
30
|
+
%Q{<span class="constant">true</span>}
|
31
|
+
when FalseClass
|
32
|
+
%Q{<span class="constant">false</span>}
|
33
|
+
when NilClass
|
34
|
+
%Q{<span class="null">null</span>}
|
35
|
+
when Numeric
|
36
|
+
%Q{<span class="number">#{object}</span>}
|
37
|
+
when Hash
|
38
|
+
s = "{\n"
|
53
39
|
@indent += 1
|
54
40
|
rows = []
|
55
|
-
|
56
|
-
|
57
|
-
rows << tab
|
41
|
+
object.keys.collect(&:to_s).sort.each do |key|
|
42
|
+
value = (object[key] != nil ? object[key] : object[key.to_sym])
|
43
|
+
rows << %Q{#{tab}<span class="string">"#{key}"</span>: #{node(value)}}
|
58
44
|
end
|
59
|
-
|
60
|
-
if limit > 0 and object.length > limit
|
61
|
-
rows << tab + (object[0].is_a?(Hash) ? '{ … }' : '…')
|
62
|
-
end
|
63
|
-
|
64
45
|
s << rows.join(",\n") + "\n"
|
65
46
|
@indent -= 1
|
66
|
-
s << "#{tab}
|
47
|
+
s << "#{tab}}"
|
67
48
|
s
|
49
|
+
when Array
|
50
|
+
if object.length == 0
|
51
|
+
"[]"
|
52
|
+
else
|
53
|
+
s = "[\n"
|
54
|
+
@indent += 1
|
55
|
+
rows = []
|
56
|
+
array = @limit > 0 ? object[0...limit] : object
|
57
|
+
array.each do |value|
|
58
|
+
rows << tab + node(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
if limit > 0 and object.length > limit
|
62
|
+
rows << tab + (object[0].is_a?(Hash) ? '{ … }' : '…')
|
63
|
+
end
|
64
|
+
|
65
|
+
s << rows.join(",\n") + "\n"
|
66
|
+
@indent -= 1
|
67
|
+
s << "#{tab}]"
|
68
|
+
s
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
data/lib/pizzazz/html.rb
ADDED
data/lib/pizzazz/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,8 +23,11 @@ files:
|
|
23
23
|
- LICENSE
|
24
24
|
- Rakefile
|
25
25
|
- Readme.markdown
|
26
|
+
- app/assets/stylesheets/pizzazz.css
|
26
27
|
- lib/pizzazz.rb
|
27
28
|
- lib/pizzazz/colorer.rb
|
29
|
+
- lib/pizzazz/engine.rb
|
30
|
+
- lib/pizzazz/html.rb
|
28
31
|
- lib/pizzazz/version.rb
|
29
32
|
- pizzazz.gemspec
|
30
33
|
- test/test_helper.rb
|
@@ -43,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
46
|
version: '0'
|
44
47
|
segments:
|
45
48
|
- 0
|
46
|
-
hash:
|
49
|
+
hash: 3758001213674931689
|
47
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
51
|
none: false
|
49
52
|
requirements:
|
@@ -52,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
55
|
version: '0'
|
53
56
|
segments:
|
54
57
|
- 0
|
55
|
-
hash:
|
58
|
+
hash: 3758001213674931689
|
56
59
|
requirements: []
|
57
60
|
rubyforge_project:
|
58
61
|
rubygems_version: 1.8.23
|