json_viewer_gtk3 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 701ed09b04f65c91c410735723439f5a72f7e1e97dc219d6ea0778fbe1fa379f
4
+ data.tar.gz: c6497b134d94ea1618ffb1afc34163a1589501ee2bb4db5013fde02dafb45fb0
5
+ SHA512:
6
+ metadata.gz: 5f79978c160ea41c5cd0df0251f1e415618e4f4147ac4988612bae0314d6c37dfea1bb04fa5cfd80696f9800dfe19902ac07ea9be6a4a9555facbd980ed3ae3d
7
+ data.tar.gz: a893ef73596352bd31e1b988e073357aa9542e859a5a29effd1b2a329951b391e208427caa3ca8adb89ef5553615ed4af468ed1ea4fbd1e570d1d9318df005e0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ *.lock
11
+ *.ui~
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # JsonView
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/json_viewer_gtk3.svg)](https://badge.fury.io/rb/json_viewer_gtk3)
4
+
5
+ Simple GUI Json Viewer written in [Ruby/GTK3](https://github.com/ruby-gnome/ruby-gnome).
6
+
7
+ ## Installation
8
+
9
+ $ gem install json_viewer_gtk3
10
+
11
+ ## Usage
12
+
13
+ $ jsonview
14
+
15
+ ![Screenshot](/resources/jsonview_screenshot.png?raw=true "screenshot")
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :test
data/exe/jsonview ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optparse'
5
+ require 'jsonview'
6
+ require 'fileutils'
7
+
8
+ opt = OptionParser.new
9
+ opt.program_name = 'JsonViewer'
10
+ opt.version = JsonView::VERSION
11
+ # opt.on('-p', '--port VAL', Integer) { |v| port_num = v }
12
+ opt.parse!(ARGV)
13
+
14
+ resource_xml = File.expand_path('../resources/gresources.xml', __dir__)
15
+ resource_bin = File.expand_path('../gresource.bin', __dir__)
16
+
17
+ system('glib-compile-resources',
18
+ '--target', resource_bin,
19
+ '--sourcedir', File.dirname(resource_xml),
20
+ resource_xml)
21
+
22
+ at_exit do
23
+ FileUtils.rm_f(resource_bin)
24
+ end
25
+
26
+ app = JsonView.application
27
+
28
+ resource = Gio::Resource.load(resource_bin)
29
+ Gio::Resources.register(resource)
30
+
31
+ app.signal_connect :activate do |application|
32
+ window = JsonView::ApplicationWindow.new application
33
+ window.present
34
+ end
35
+
36
+ app.run
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'jsonview/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'json_viewer_gtk3'
9
+ spec.version = JsonView::VERSION
10
+ spec.authors = ['kojix2']
11
+ spec.email = ['2xijok@gmail.com']
12
+
13
+ spec.summary = 'Simple GUI Json viewer'
14
+ spec.description = 'Simple GUI Json Viewer'
15
+ spec.homepage = 'https://github.com/kojix2/json_viewer_gtk3'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'gtk3'
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gtk3'
4
+
5
+ module JsonView
6
+ class << self
7
+ def application
8
+ @@application ||= Gtk::Application.new('com.github.kojix2.jsonview', :flags_none)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gtk3'
4
+ require 'json'
5
+
6
+ module JsonView
7
+ class ApplicationWindow < Gtk::ApplicationWindow
8
+ type_register
9
+
10
+ def self.init
11
+ set_template resource: '/com/github/kojix2/jsonview/jsonview.ui'
12
+ bind_template_child 'treeview'
13
+ set_connect_func do |handler_name|
14
+ lambda do
15
+ JsonView.application.active_window.__send__(handler_name)
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(application)
21
+ super application: application
22
+ set_title 'JsonView'
23
+ set_icon GdkPixbuf::Pixbuf.new(
24
+ resource: '/com/github/kojix2/jsonview/ruby.png'
25
+ )
26
+ end
27
+
28
+ def on_open_clicked
29
+ dialog = Gtk::FileChooserDialog.new(
30
+ title: 'Gtk::FileChooser sample',
31
+ action: :open,
32
+ flags: :modal,
33
+ buttons: [[Gtk::Stock::OPEN, :accept],
34
+ [Gtk::Stock::CANCEL, :cancel]]
35
+ )
36
+ Gtk::FileFilter.new.tap do |f|
37
+ f.name = 'Json'
38
+ f.add_pattern('*.json')
39
+ dialog.add_filter f
40
+ end
41
+ Gtk::FileFilter.new.tap do |f|
42
+ f.name = 'All'
43
+ f.add_pattern('*')
44
+ dialog.add_filter f
45
+ end
46
+
47
+ case dialog.run
48
+ when Gtk::ResponseType::ACCEPT
49
+ open_json(dialog.filename)
50
+ dialog.destroy
51
+ when Gtk::ResponseType::CANCEL
52
+ dialog.destroy
53
+ end
54
+ end
55
+
56
+ def open_json(filename)
57
+ data = File.open(filename) do |file|
58
+ JSON.load(file)
59
+ end
60
+ @model&.destroy
61
+ @model = Gtk::TreeStore.new(String, Float)
62
+ create_model(data)
63
+ treeview.model = @model
64
+
65
+ column = Gtk::TreeViewColumn.new(
66
+ File.basename(filename),
67
+ Gtk::CellRendererText.new,
68
+ {
69
+ text: 0,
70
+ scale: 1
71
+ }
72
+ )
73
+ treeview.append_column(column)
74
+ end
75
+
76
+ def create_model(data, parent = nil, size = 1.0)
77
+ parent ||= @model.append(nil)
78
+ case data
79
+ when Hash
80
+ data.each do |key, value|
81
+ i = @model.append(parent)
82
+ i[0] = key.to_s
83
+ i[1] = size
84
+ create_model(value, i, size * 0.9)
85
+ end
86
+ when Array
87
+ data.each do |value|
88
+ i = @model.append(parent)
89
+ i[0] = ''
90
+ i[1] = size
91
+ create_model(value, i, size * 0.9)
92
+ end
93
+ when String, Numeric, Integer
94
+ @model.append(parent).tap do |j|
95
+ j[0] = data.to_s
96
+ j[1] = size * 0.9
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonView
4
+ VERSION = '0.0.2'
5
+ end
data/lib/jsonview.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jsonview/version'
4
+ require 'jsonview/application'
5
+ require 'jsonview/application_window'
6
+
7
+ module JsonView
8
+ end
data/resources/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. It is licensed
2
+ under the terms of the Creative Commons Attribution-ShareAlike 2.5
3
+ agreement:
4
+
5
+ http://creativecommons.org/licenses/by-sa/2.5/
6
+
7
+ We ask that you do not use the logo to represent something other than
8
+ the Ruby Programming language. If you have questions about the logo,
9
+ please join the VIT-Discuss mailing list and ask your questions there:
10
+
11
+ http://rubyforge.org/mailman/listinfo/vit-discuss/
12
+
13
+ Thank you,
14
+
15
+ The Ruby Visual Identity Team
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <gresources>
3
+ <gresource prefix="/com/github/kojix2/jsonview">
4
+ <file preprocess="xml-stripblanks">jsonview.ui</file>
5
+ <file>ruby.png</file>
6
+ </gresource>
7
+ </gresources>
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Generated with glade 3.22.2 -->
3
+ <interface>
4
+ <requires lib="gtk+" version="3.20"/>
5
+ <template class="JsonViewApplicationWindow" parent="GtkApplicationWindow">
6
+ <property name="can_focus">False</property>
7
+ <property name="opacity">0.90000000000000002</property>
8
+ <property name="type">popup</property>
9
+ <property name="default_width">500</property>
10
+ <property name="default_height">500</property>
11
+ <property name="show_menubar">False</property>
12
+ <child type="titlebar">
13
+ <object class="GtkHeaderBar">
14
+ <property name="visible">True</property>
15
+ <property name="can_focus">False</property>
16
+ <property name="show_close_button">True</property>
17
+ <child>
18
+ <object class="GtkButtonBox">
19
+ <property name="visible">True</property>
20
+ <property name="can_focus">False</property>
21
+ <property name="layout_style">expand</property>
22
+ <child>
23
+ <object class="GtkToolButton">
24
+ <property name="visible">True</property>
25
+ <property name="can_focus">False</property>
26
+ <property name="halign">start</property>
27
+ <property name="margin_left">3</property>
28
+ <property name="margin_right">3</property>
29
+ <property name="label" translatable="yes">open</property>
30
+ <property name="use_underline">True</property>
31
+ <property name="stock_id">gtk-open</property>
32
+ <signal name="clicked" handler="on_open_clicked" swapped="no"/>
33
+ </object>
34
+ <packing>
35
+ <property name="expand">True</property>
36
+ <property name="fill">True</property>
37
+ <property name="position">0</property>
38
+ </packing>
39
+ </child>
40
+ </object>
41
+ </child>
42
+ </object>
43
+ </child>
44
+ <child>
45
+ <object class="GtkScrolledWindow">
46
+ <property name="visible">True</property>
47
+ <property name="can_focus">True</property>
48
+ <property name="shadow_type">in</property>
49
+ <child>
50
+ <object class="GtkTreeView" id="treeview">
51
+ <property name="visible">True</property>
52
+ <property name="can_focus">True</property>
53
+ <child internal-child="selection">
54
+ <object class="GtkTreeSelection"/>
55
+ </child>
56
+ </object>
57
+ </child>
58
+ </object>
59
+ </child>
60
+ </template>
61
+ </interface>
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_viewer_gtk3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - kojix2
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gtk3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simple GUI Json Viewer
56
+ email:
57
+ - 2xijok@gmail.com
58
+ executables:
59
+ - jsonview
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - exe/jsonview
69
+ - json_viewer_gtk3.gemspec
70
+ - lib/jsonview.rb
71
+ - lib/jsonview/application.rb
72
+ - lib/jsonview/application_window.rb
73
+ - lib/jsonview/version.rb
74
+ - resources/LICENSE
75
+ - resources/gresources.xml
76
+ - resources/jsonview.ui
77
+ - resources/jsonview_screenshot.png
78
+ - resources/ruby.png
79
+ homepage: https://github.com/kojix2/json_viewer_gtk3
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.2.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Simple GUI Json viewer
102
+ test_files: []