json-prettyprint 0.0.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in json-prettyprint.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michal Orman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # JSON PrettyPrint
2
+
3
+ The only reason for creating this gem was to provide me some tool that will allow me formatting
4
+ and highlighting JSON API responses fetched using `curl` command.
5
+
6
+ The **JSON PrettyPrint** is a simple tool that let you format any json output (like one received
7
+ from some API using `curl`). It will format the JSON response and apply syntax highlighting.
8
+
9
+ ## Installation
10
+
11
+ The best way to install this tool is to manually execute:
12
+
13
+ $ gem install json-prettyprint
14
+
15
+ You can also add it to the Gemfile if you want:
16
+
17
+ ```ruby
18
+ gem 'json-prettyprint'
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ The **JSON PrettyPrint** provides command line tool `jj` which can be piped to any other command
24
+ like this:
25
+
26
+ $ curl https://github.com/michalorman.json | jj
27
+
28
+ If you, for some weird reason, want to use it in some code, you can generate pretty
29
+ json like this:
30
+
31
+ ```ruby
32
+ require 'json-prettyprint'
33
+
34
+ json = STDIN.gets
35
+ pretty_json = JSON::PrettyPrint.prettify json
36
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/jj ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json-prettyprint'
4
+
5
+ pretty_json = JSON::PrettyPrint.prettify STDIN.gets
6
+ puts pretty_json
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'json-prettyprint/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "json-prettyprint"
8
+ gem.version = JSON::PrettyPrint::VERSION
9
+ gem.authors = ["Michal Orman"]
10
+ gem.email = ["michal.orman@gmail.com"]
11
+ gem.description = %q{Pretty print any Jsoun output with syntax highlight.}
12
+ gem.summary = %q{Pretty print Json output.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'coderay', '~> 1.0'
21
+ end
@@ -0,0 +1,29 @@
1
+ if RUBY_VERSION < "1.9"
2
+ begin
3
+ require 'rubygems'
4
+ unless Gem.available? 'json'
5
+ puts "\n\nPlease install 'json' gem using 'gem install json' command.\n"
6
+ Process.exit
7
+ end
8
+ rescue Gem::LoadError
9
+ puts "\n\nThe program requires either Ruby 1.9 or lower with 'rubygems' and 'json' gem installed.\n"
10
+ end
11
+ end
12
+
13
+ require 'json'
14
+ require 'coderay'
15
+ require "json-prettyprint/version"
16
+
17
+ module JSON
18
+ module PrettyPrint
19
+
20
+ def self.prettify input
21
+ json = JSON.parse input
22
+ pretty_json = JSON::pretty_generate json, allow_nan: true, max_nesting: false
23
+
24
+ encoder = CodeRay.encoder :term
25
+ encoder.encode pretty_json, :json
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module JSON
2
+ module PrettyPrint
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json-prettyprint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michal Orman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coderay
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description: Pretty print any Jsoun output with syntax highlight.
31
+ email:
32
+ - michal.orman@gmail.com
33
+ executables:
34
+ - jj
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/jj
44
+ - json-prettyprint.gemspec
45
+ - lib/json-prettyprint.rb
46
+ - lib/json-prettyprint/version.rb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Pretty print Json output.
71
+ test_files: []
72
+ has_rdoc: