pjson-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -0
- data/Rakefile +14 -0
- data/bin/pjson +8 -0
- data/lib/pjson.rb +16 -0
- data/pjson.gemspec +31 -0
- data/test/test_pjson.rb +28 -0
- metadata +71 -0
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
task :default => :test
|
2
|
+
|
3
|
+
GEMSPEC = eval(File.read('pjson.gemspec'))
|
4
|
+
|
5
|
+
require 'rubygems/package_task'
|
6
|
+
Gem::PackageTask.new(GEMSPEC) do |pkg|
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake/testtask'
|
10
|
+
Rake::TestTask.new 'test' do |t|
|
11
|
+
t.test_files = FileList['test/test_*.rb']
|
12
|
+
t.ruby_opts = ['-rubygems']
|
13
|
+
end
|
14
|
+
task :test
|
data/bin/pjson
ADDED
data/lib/pjson.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pygments'
|
2
|
+
require 'json/pure'
|
3
|
+
|
4
|
+
class PJson
|
5
|
+
include Pygments
|
6
|
+
|
7
|
+
attr_accessor :json
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@json = JSON.pretty_generate(JSON.load(json))
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
Lexer.find_by_name('JSON').highlight(@json, { formatter: 'terminal' })
|
15
|
+
end
|
16
|
+
end
|
data/pjson.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'pjson-rb'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2012-09-18'
|
5
|
+
|
6
|
+
s.description = "pipe to pretty print json utility"
|
7
|
+
s.summary =
|
8
|
+
"Pipe json in the terminal and make it pretty."
|
9
|
+
|
10
|
+
s.authors = ["Mark Sands"]
|
11
|
+
s.email = "marksands07@gmail.com"
|
12
|
+
|
13
|
+
s.files = %w[
|
14
|
+
README.md
|
15
|
+
Rakefile
|
16
|
+
pjson.gemspec
|
17
|
+
bin/pjson
|
18
|
+
lib/pjson.rb
|
19
|
+
test/test_pjson.rb
|
20
|
+
]
|
21
|
+
|
22
|
+
s.default_executable = 'pjson'
|
23
|
+
s.executables = ['pjson']
|
24
|
+
|
25
|
+
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
26
|
+
s.add_dependency 'pygments.rb', '~> 0.2.13'
|
27
|
+
|
28
|
+
s.has_rdoc = false
|
29
|
+
s.homepage = "http://github.com/marksands/pjson-rb/"
|
30
|
+
s.require_paths = %w[lib]
|
31
|
+
end
|
data/test/test_pjson.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'pjson'
|
3
|
+
|
4
|
+
PRETTY_JSON = "{\e[39;49;00m\n \e[39;49;00m\e[34;01m\"json\"\e[39;49;00m:\e[39;49;00m \e[39;49;00m\e[33m\"obj\"\e[39;49;00m\n}\e[39;49;00m\n"
|
5
|
+
|
6
|
+
class PJsonPrettyPrintTest < Test::Unit::TestCase
|
7
|
+
def test_pjson_initialize_formatted
|
8
|
+
assert_equal "{\n \"json\": \"obj\"\n}", PJson.new("{\"json\":\"obj\"}").instance_variable_get(:@json)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_pjson_to_s
|
12
|
+
assert_equal PRETTY_JSON, PJson.new("{\"json\":\"obj\"}").to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ENV['PATH'] = [File.expand_path('bin'), ENV['PATH']].join(':')
|
17
|
+
|
18
|
+
class PJsonCommandTest < Test::Unit::TestCase
|
19
|
+
def test_piping_json
|
20
|
+
IO.popen("pjson", 'w+') do |io|
|
21
|
+
io.puts "{\"json\":\"obj\"}"
|
22
|
+
io.flush
|
23
|
+
assert_equal PRETTY_JSON, io.read
|
24
|
+
io.close_write
|
25
|
+
io.close
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pjson-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Sands
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-09-18 00:00:00 -07:00
|
14
|
+
default_executable: pjson
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: pygments.rb
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.2.13
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: pipe to pretty print json utility
|
28
|
+
email: marksands07@gmail.com
|
29
|
+
executables:
|
30
|
+
- pjson
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- pjson.gemspec
|
39
|
+
- bin/pjson
|
40
|
+
- lib/pjson.rb
|
41
|
+
- test/test_pjson.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/marksands/pjson-rb/
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.5.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Pipe json in the terminal and make it pretty.
|
70
|
+
test_files: []
|
71
|
+
|