jsonpretty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-02-20
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/jsonpretty
6
+ lib/jsonpretty.rb
@@ -0,0 +1,54 @@
1
+ = jsonpretty
2
+
3
+ * http://github.com/nicksieger/jsonpretty
4
+
5
+ == DESCRIPTION:
6
+
7
+ Command-line JSON pretty-printer, using the json gem.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ - Parse and pretty-print JSON either from stdin or from command-line
12
+ arguments.
13
+ - All arguments are concatenated together in a single string for
14
+ pretty-printing.
15
+ - Use '@filename' as an argument to include the contents of the file.
16
+ - Use '-' or '@-' as an argument (or use no arguments) to read stdin.
17
+ - Detects HTTP response/headers, prints them untouched, and skips to
18
+ the body (for use with `curl -i').
19
+
20
+ == SYNOPSIS:
21
+
22
+
23
+ == REQUIREMENTS:
24
+
25
+ json or json_pure
26
+
27
+ == INSTALL:
28
+
29
+ gem install jsonpretty
30
+
31
+ == LICENSE:
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2007-2009 Nick Sieger <nick@nicksieger.com>
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/jsonpretty.rb'
6
+
7
+ h = Hoe.new('jsonpretty', Jsonpretty::VERSION) do |p|
8
+ p.rubyforge_name = 'caldersphere'
9
+ p.developer('Nick Sieger', 'nick@nicksieger.com')
10
+ p.url = 'http://github.com/nicksieger/jsonpretty'
11
+ p.extra_deps << ['json', '> 0'] if ENV["VERSION"]
12
+ end
13
+ spec = h.spec
14
+ spec.dependencies.delete_if { |dep| dep.name == "hoe" }
15
+ def spec.to_ruby
16
+ additional_src = %{
17
+ if defined?(JRUBY_VERSION)
18
+ s.add_dependency('json_pure', '> 0')
19
+ else
20
+ s.add_dependency('json', '> 0')
21
+ end
22
+ }
23
+ super.sub(/end\n\Z/m, "#{additional_src}\nend\n")
24
+ end
25
+
26
+ task :gemspec do
27
+ File.open("jsonpretty.gemspec", "w") {|f| f << spec.to_ruby }
28
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'jsonpretty'
4
+ Jsonpretty.new.main
@@ -0,0 +1,57 @@
1
+ require 'json'
2
+
3
+ class Jsonpretty
4
+ VERSION = '1.0.0'
5
+
6
+ def file_value(filename)
7
+ file = if filename == '-'
8
+ $stdin
9
+ else
10
+ File.open(filename)
11
+ end
12
+ lines = file.readlines
13
+ if lines.first =~ /^HTTP\/1\./ # looks like an HTTP response; we just want the body
14
+ index = lines.index("\r\n") || lines.index("\n")
15
+ puts lines[0..index]
16
+ lines[(index+1)..-1].join('')
17
+ else
18
+ lines.join('')
19
+ end
20
+ ensure
21
+ file.close
22
+ end
23
+
24
+ def stdin_value
25
+ file_value('-')
26
+ end
27
+
28
+ def main
29
+ if ARGV.length == 0
30
+ ARGV.unshift stdin_value
31
+ else
32
+ ARGV.each_with_index do |v,i|
33
+ case v
34
+ when /^--?h/
35
+ puts("usage: #{File.basename($0)} [args|@filename|@- (stdin)]",
36
+ "Parse and pretty-print JSON, either from stdin or from arguments concatenated together")
37
+ exit 0
38
+ when /^--?v/
39
+ puts "jsonpretty version #{VERSION}"
40
+ exit 0
41
+ else
42
+ if v == '-'
43
+ ARGV[i] = stdin_value
44
+ elsif v =~ /^@/
45
+ ARGV[i] = file_value(v[1..-1])
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ puts JSON.pretty_generate(JSON.parse(ARGV.join(' ')))
52
+ rescue => e
53
+ $stderr.puts "jsonpretty failed: #{e.message}"
54
+ exit 1
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsonpretty
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Sieger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-20 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Command-line JSON pretty-printer, using the json gem.
26
+ email:
27
+ - nick@nicksieger.com
28
+ executables:
29
+ - jsonpretty
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - bin/jsonpretty
42
+ - lib/jsonpretty.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/nicksieger/jsonpretty
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: caldersphere
66
+ rubygems_version: 1.3.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Command-line JSON pretty-printer, using the json gem.
70
+ test_files: []
71
+