jsonview 0.0.1 → 0.0.2
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 +7 -0
- data/lib/jsonview/middleware.rb +51 -12
- data/lib/jsonview/version.rb +1 -1
- metadata +23 -44
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5d70eaa39c68d70ff38df05bc71e5ac54c40bf5
|
4
|
+
data.tar.gz: 2a6c13399bbec46acfbc375ac3efa1403891fd76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccf1c8a77fea409e7af381f6acd9a89a1909a6a8a880b69d44966d8756675f6aa27759bd692f19bd941c7356e83c2d1911cc27cc98548b4eb2130d1729112d17
|
7
|
+
data.tar.gz: f91792869a9f32bc402eed86af68dd5f66cbc880851494f499177939c87579b6605ce1bb7aa91dcb334a9bc51696a591e1d6635cfe1d6e8059939bb3af96fe23
|
data/lib/jsonview/middleware.rb
CHANGED
@@ -26,18 +26,20 @@ module Jsonview
|
|
26
26
|
|
27
27
|
def html_document(value)
|
28
28
|
<<-HTML
|
29
|
+
<!DOCTYPE html>
|
29
30
|
<html>
|
30
31
|
<head>
|
31
32
|
<style>
|
32
33
|
null { color: red }
|
33
34
|
string { color: green }
|
34
35
|
number, boolean { color: blue }
|
35
|
-
|
36
|
+
unknown { color: gray }
|
37
|
+
hash, array { display: block; margin-left: 2em }
|
36
38
|
key { font-weight: bold }
|
37
39
|
</style>
|
38
40
|
</head>
|
39
41
|
<body>
|
40
|
-
#{represent(value)}
|
42
|
+
#{represent(value).join}
|
41
43
|
</body>
|
42
44
|
</html>
|
43
45
|
HTML
|
@@ -46,24 +48,61 @@ module Jsonview
|
|
46
48
|
def represent(value)
|
47
49
|
case value
|
48
50
|
when nil
|
49
|
-
"<null>
|
50
|
-
when
|
51
|
-
"<
|
52
|
-
when Fixnum
|
53
|
-
"<number>#{value.to_s}</number>"
|
51
|
+
"<null>null</null>"
|
52
|
+
when Numeric
|
53
|
+
"<number>#{value}</number>"
|
54
54
|
when TrueClass, FalseClass
|
55
|
-
"<boolean>#{value
|
55
|
+
"<boolean>#{value}</boolean>"
|
56
56
|
when Array
|
57
|
-
|
57
|
+
[
|
58
|
+
"[<array>\n",
|
59
|
+
value.each_with_index.map do |v, i|
|
60
|
+
[
|
61
|
+
(",<br/>\n" if i > 0),
|
62
|
+
represent(v),
|
63
|
+
]
|
64
|
+
end,
|
65
|
+
"\n</array>]",
|
66
|
+
]
|
58
67
|
when Hash
|
59
|
-
|
68
|
+
[
|
69
|
+
"{<hash>\n",
|
70
|
+
value.each_with_index.map do |(k, v), i|
|
71
|
+
[
|
72
|
+
(",<br/>\n" if i > 0),
|
73
|
+
"<key>"",
|
74
|
+
encode(k.to_s),
|
75
|
+
""</key>: ",
|
76
|
+
represent(v),
|
77
|
+
]
|
78
|
+
end,
|
79
|
+
"\n</hash>}",
|
80
|
+
]
|
81
|
+
when URI.regexp(%w[http https])
|
82
|
+
[
|
83
|
+
""<a href=\"",
|
84
|
+
encode(value),
|
85
|
+
"\">",
|
86
|
+
encode(value),
|
87
|
+
"</a>"",
|
88
|
+
]
|
89
|
+
when String
|
90
|
+
[
|
91
|
+
"<string>"",
|
92
|
+
encode(value),
|
93
|
+
""</string>",
|
94
|
+
]
|
60
95
|
else
|
61
|
-
|
96
|
+
[
|
97
|
+
"<unknown>"",
|
98
|
+
encode(value.inspect),
|
99
|
+
""</unknown>",
|
100
|
+
]
|
62
101
|
end
|
63
102
|
end
|
64
103
|
|
65
104
|
def encode(string)
|
66
|
-
string.gsub /[<>&"]/, '<' => '<', '>' => '>', '&' => '&', '"' => '
|
105
|
+
string.gsub /[<>&"]/, '<' => '<', '>' => '>', '&' => '&', '"' => '\"'
|
67
106
|
end
|
68
107
|
end
|
69
108
|
end
|
data/lib/jsonview/version.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonview
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Preston Guillory
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-12-10 00:00:00 Z
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description: JSONView for Rack
|
22
|
-
email:
|
14
|
+
email:
|
23
15
|
- pguillory@gmail.com
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
18
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
19
|
+
files:
|
31
20
|
- Gemfile
|
32
21
|
- LICENSE
|
33
22
|
- README.md
|
@@ -39,36 +28,26 @@ files:
|
|
39
28
|
- lib/jsonview/version.rb
|
40
29
|
homepage: https://github.com/pguillory/jsonview
|
41
30
|
licenses: []
|
42
|
-
|
31
|
+
metadata: {}
|
43
32
|
post_install_message:
|
44
33
|
rdoc_options: []
|
45
|
-
|
46
|
-
require_paths:
|
34
|
+
require_paths:
|
47
35
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 3
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
version: "0"
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
66
46
|
requirements: []
|
67
|
-
|
68
47
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
48
|
+
rubygems_version: 2.0.3
|
70
49
|
signing_key:
|
71
|
-
specification_version:
|
72
|
-
summary: Rack middleware to convert JSON responses into attractive HTML representations.
|
50
|
+
specification_version: 4
|
51
|
+
summary: Rack middleware to convert JSON responses into attractive HTML representations.
|
52
|
+
Mimics the JSONView browser plugin.
|
73
53
|
test_files: []
|
74
|
-
|