ricojson 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ricojson +21 -0
- data/lib/ricojson.rb +37 -0
- metadata +82 -0
data/bin/ricojson
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'rico_json'
|
4
|
+
|
5
|
+
args = ARGV.dup
|
6
|
+
|
7
|
+
# TODO: Validate args
|
8
|
+
case args.size
|
9
|
+
when 0
|
10
|
+
RicoJSON.read_string(STDIN.read)
|
11
|
+
when 1
|
12
|
+
if args[0] != '-o'
|
13
|
+
RicoJSON.read_file(args[0])
|
14
|
+
else
|
15
|
+
RicoJSON.read_string(STDIN.read, true)
|
16
|
+
end
|
17
|
+
when 2
|
18
|
+
RicoJSON.read_file(args[1], true)
|
19
|
+
else
|
20
|
+
puts 'Usage: json-rico [-o] [file]'
|
21
|
+
end
|
data/lib/ricojson.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'json'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module RicoJSON
|
6
|
+
if RUBY_PLATFORM =~ /linux/
|
7
|
+
def self.open(json)
|
8
|
+
`xdg-open #{json.path}`
|
9
|
+
end
|
10
|
+
elsif RUBY_PLATFORM =~ /macos|darwin/
|
11
|
+
def self.open(json)
|
12
|
+
`open -t #{json.path}`
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.read_file(filename, open = false)
|
17
|
+
read_string(File.read(filename), open)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.read_string(json_string, open = false)
|
21
|
+
body = JSON.pretty_generate(JSON.parse(json_string))
|
22
|
+
if open
|
23
|
+
open_in_file(body)
|
24
|
+
else
|
25
|
+
puts body
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.open_in_file(body)
|
30
|
+
fork do
|
31
|
+
json = Tempfile.new(['json', '.json'])
|
32
|
+
json.write(body)
|
33
|
+
json.close
|
34
|
+
open(json)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ricojson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fernando Briano
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '5.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubocop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.19'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.19'
|
46
|
+
description: Uses Ruby's JSON to parse and format json files and opens them in the
|
47
|
+
system's default application.
|
48
|
+
email: fernando@picandocodigo.net
|
49
|
+
executables:
|
50
|
+
- ricojson
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/ricojson.rb
|
55
|
+
- bin/ricojson
|
56
|
+
homepage: https://github.com/picandocodigo/json-pretty
|
57
|
+
licenses:
|
58
|
+
- GPL-3
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.23
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: A gem to prettify JSON files and open them in default app
|
81
|
+
test_files: []
|
82
|
+
has_rdoc:
|