gluby-tk 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/bin/{gluby-tk → gluby} +3 -0
- data/lib/core_ext/string.rb +14 -1
- data/lib/gluby-tk/generator.rb +90 -77
- data/lib/gluby-tk/version.rb +1 -1
- data/templates/ApplicationWindow.glade.template +33 -0
- data/templates/application.rb.template +9 -0
- data/templates/includes.rb.template +1 -0
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88bdbec6a3b26aeaaedbef372b27927afbae8b4f
|
4
|
+
data.tar.gz: 2192394b9cefcc9e37d9528e7a97ba2ce89218bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f026a3bee2456fb7e92ae94f22836d83264400b88f79c663c261617aed073bc1c7ada621e3d9c521e1cab624c1f2f65daa6678b608e22cad783f63a93e2fe51c
|
7
|
+
data.tar.gz: fce9719f976b68e9df469b248874ef173c0f84d7ec01fdf26692f439b61cdf5544365089762fb2a84313120e9f0a3ca76b84023b4723b5b7dd476c2ffcfc6fe3
|
data/bin/{gluby-tk → gluby}
RENAMED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require "gluby-tk"
|
5
|
+
require "wannabe_bool"
|
5
6
|
|
6
7
|
# options = {}
|
7
8
|
|
@@ -28,6 +29,8 @@ if ARGV[0] == "new"
|
|
28
29
|
puts "Creating #{ARGV[1]}..."
|
29
30
|
GlubyTK::Generator.create(ARGV[1])
|
30
31
|
end
|
32
|
+
elsif ARGV[0] == "rebuild"
|
33
|
+
GlubyTK::Generator.rebuild(nil, !ARGV[1].nil? ? ARGV[1].to_b : false)
|
31
34
|
end
|
32
35
|
|
33
36
|
exit(0)
|
data/lib/core_ext/string.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
class String
|
2
|
+
DISALLOWED_CHARACTERS = "[\-\s\.\,\?\'\"\:\;\\\/]"
|
3
|
+
|
2
4
|
def humanize
|
3
|
-
|
5
|
+
gsub(DISALLOWED_CHARACTERS, " ").split(" ").map(&:capitalize).join("")
|
4
6
|
end
|
7
|
+
|
8
|
+
def underscore
|
9
|
+
u = ""
|
10
|
+
sanitize.split("").each_with_index do |c, i|; if i > 0 && c == c.upcase; u += " "; end; u += c.downcase; end;
|
11
|
+
u.gsub(" ", "_")
|
12
|
+
end
|
13
|
+
|
14
|
+
def sanitize
|
15
|
+
gsub(DISALLOWED_CHARACTERS, "_")
|
16
|
+
end
|
17
|
+
|
5
18
|
end
|
data/lib/gluby-tk/generator.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'pp'
|
3
|
+
|
1
4
|
module GlubyTK
|
2
5
|
class Generator
|
3
6
|
def self.create app_name
|
4
|
-
|
7
|
+
if File.exist?(app_name)
|
8
|
+
puts "#{app_name} already exists!"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
5
12
|
root = "#{Dir.pwd}/#{app_name}"
|
6
13
|
directories = [
|
7
14
|
"assets",
|
@@ -13,10 +20,6 @@ module GlubyTK
|
|
13
20
|
"src/controller"
|
14
21
|
]
|
15
22
|
|
16
|
-
templates = [
|
17
|
-
"src/application.rb",
|
18
|
-
]
|
19
|
-
|
20
23
|
# Create root directory
|
21
24
|
Dir.mkdir "#{Dir.pwd}/#{app_name}"
|
22
25
|
|
@@ -30,97 +33,94 @@ module GlubyTK
|
|
30
33
|
file.write(get_template_contents("includes.rb.template"))
|
31
34
|
}
|
32
35
|
|
33
|
-
# Create
|
34
|
-
module_name = "#{app_name.
|
36
|
+
# Create app entry point
|
37
|
+
module_name = "#{app_name.underscore}"
|
38
|
+
app_id = module_name.humanize.downcase
|
39
|
+
|
35
40
|
main_file = "#{root}/#{module_name}.rb"
|
36
41
|
File.open(main_file, "w+") { |file|
|
37
|
-
# file.write("module #{module_name.humanize}\n\nend\n")
|
38
42
|
file.write(get_template_contents("boot.rb.template"))
|
39
43
|
}
|
44
|
+
File.open("#{root}/.gluby-tkrc", "w+") { |file|
|
45
|
+
file.write(module_name)
|
46
|
+
}
|
40
47
|
|
41
|
-
app_id = module_name.humanize.downcase
|
42
48
|
# Create Application
|
43
49
|
File.open("#{root}/src/application.rb", "w+") { |file|
|
50
|
+
file.write(get_template_contents("application.rb.template").gsub("gluby-tk_app_id", app_id))
|
51
|
+
}
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# TODO: Go to login screen if user is not ready logged in
|
49
|
-
signal_connect 'activate' do |application|
|
50
|
-
@window = ApplicationWindow.new(:application => application)
|
51
|
-
@window.present
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
")
|
53
|
+
# Make initial application window
|
54
|
+
File.open("#{root}/interface/ApplicationWindow.glade", "w+") { |file|
|
55
|
+
file.write(get_template_contents("ApplicationWindow.glade.template"))
|
56
56
|
}
|
57
57
|
|
58
|
-
|
59
|
-
File.open("#{root}/src/view/application_window.rb", "w+") { |file|
|
60
|
-
file.write("class ApplicationWindow < Gtk::ApplicationWindow
|
61
|
-
type_register
|
62
|
-
class << self
|
63
|
-
def init
|
64
|
-
set_template(:resource => '/app/#{app_id}/ApplicationWindow.glade')
|
65
|
-
# Specify the any UI elements you need to reference in code using the glade ID
|
66
|
-
[\"main_box\", \"welcome_label\"].each{|child_id| bind_template_child(child_id)}
|
58
|
+
rebuild(root, true)
|
67
59
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
60
|
+
|
61
|
+
def self.rebuild(root = nil, generate_ruby_classes = false)
|
62
|
+
unless is_glubytk_directory?(root)
|
63
|
+
puts "No GlubyTK project detected. Please make sure you are in the right directory"
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
root = root || Dir.pwd
|
68
|
+
|
69
|
+
interface_files = Dir["#{root}/interface/*.glade"]
|
70
|
+
gresource_file_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
71
|
+
gresource_file_contents += "<gresources>\n"
|
72
|
+
interface_files.each { |filename|
|
73
|
+
gresource_file_contents += "<gresource prefix=\"/app/#{current_app_name(root)}\">"
|
74
|
+
gresource_file_contents += "<file preprocess=\"xml-stripblanks\">#{File.basename(filename)}</file>"
|
75
|
+
gresource_file_contents += "</gresource>"
|
76
|
+
if generate_ruby_classes
|
77
|
+
generate_ruby_class_for_document(File.basename(filename), File.read(filename), root)
|
78
|
+
end
|
74
79
|
}
|
80
|
+
gresource_file_contents += "</gresources>\n"
|
75
81
|
|
76
82
|
File.open("#{root}/interface/interface.gresource.xml", "w+") { |file|
|
77
|
-
file.write(
|
78
|
-
<gresources>
|
79
|
-
<gresource prefix=\"/app/#{app_id}\">
|
80
|
-
<file preprocess=\"xml-stripblanks\">ApplicationWindow.glade</file>
|
81
|
-
</gresource>
|
82
|
-
</gresources>
|
83
|
-
")
|
83
|
+
file.write(Nokogiri::XML(gresource_file_contents, &:noblanks))
|
84
84
|
}
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
<
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
</object>
|
117
|
-
</child>
|
118
|
-
</template>
|
119
|
-
</interface>
|
120
|
-
")
|
87
|
+
def self.generate_ruby_class_for_document(file_name, file_contents, root)
|
88
|
+
doc = Nokogiri::XML(file_contents)
|
89
|
+
|
90
|
+
if doc.css("template").first.nil?
|
91
|
+
main_template = doc.css("object").first
|
92
|
+
class_name = main_template["id"]
|
93
|
+
parent = main_template["class"]
|
94
|
+
else
|
95
|
+
main_template = doc.css("template").first
|
96
|
+
class_name = main_template["class"]
|
97
|
+
parent = main_template["parent"]
|
98
|
+
end
|
99
|
+
|
100
|
+
parent = parent.gsub("Gtk","")
|
101
|
+
|
102
|
+
class_file_contents = [
|
103
|
+
"class #{class_name} < Gtk::#{parent}",
|
104
|
+
"\ttype_register",
|
105
|
+
"\tclass << self",
|
106
|
+
"\t\tdef init",
|
107
|
+
"\t\t\tset_template(:resource => '/app/#{current_app_name(root)}/#{file_name}')",
|
108
|
+
"\t\t\t#{doc.css("[id]").map{|e| e.attributes["id"].value }.to_s}.each{|child_id| bind_template_child(child_id)}",
|
109
|
+
"\t\tend",
|
110
|
+
"\tend",
|
111
|
+
"end"
|
112
|
+
].join("\n")
|
113
|
+
|
114
|
+
new_file_path = "#{root}/src/view/#{file_name.gsub(File.extname(file_name), "").underscore}.rb"
|
115
|
+
File.open(new_file_path, "w+") { |file|
|
116
|
+
file.write class_file_contents
|
121
117
|
}
|
122
118
|
end
|
123
119
|
|
120
|
+
# Helpers
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
124
|
def self.get_template_contents(template_name)
|
125
125
|
File.read("#{template_dir}#{template_name}")
|
126
126
|
end
|
@@ -128,5 +128,18 @@ end")
|
|
128
128
|
def self.template_dir
|
129
129
|
"#{File.dirname(File.dirname(File.dirname(__FILE__)))}/templates/"
|
130
130
|
end
|
131
|
+
|
132
|
+
def self.current_app_name(dir = nil)
|
133
|
+
File.read(glubytk_rc_path(dir)).strip
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.is_glubytk_directory?(dir = nil)
|
137
|
+
File.exist?(glubytk_rc_path(dir))
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.glubytk_rc_path(dir = nil)
|
141
|
+
"#{dir || Dir.pwd}/.gluby-tkrc"
|
142
|
+
end
|
143
|
+
|
131
144
|
end
|
132
145
|
end
|
data/lib/gluby-tk/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!-- Generated with glade 3.20.0 -->
|
3
|
+
<interface>
|
4
|
+
<requires lib="gtk+" version="3.20"/>
|
5
|
+
<template class="ApplicationWindow" parent="GtkApplicationWindow">
|
6
|
+
<property name="can_focus">False</property>
|
7
|
+
<property name="window_position">center</property>
|
8
|
+
<property name="icon_name">computer</property>
|
9
|
+
<property name="gravity">center</property>
|
10
|
+
<property name="show_menubar">False</property>
|
11
|
+
<child>
|
12
|
+
<object class="GtkBox" id="main_box">
|
13
|
+
<property name="width_request">300</property>
|
14
|
+
<property name="height_request">300</property>
|
15
|
+
<property name="visible">True</property>
|
16
|
+
<property name="can_focus">False</property>
|
17
|
+
<property name="orientation">vertical</property>
|
18
|
+
<child>
|
19
|
+
<object class="GtkLabel" id="welcome_label">
|
20
|
+
<property name="visible">True</property>
|
21
|
+
<property name="can_focus">False</property>
|
22
|
+
<property name="label" translatable="yes">Built with Gluby-TK</property>
|
23
|
+
</object>
|
24
|
+
<packing>
|
25
|
+
<property name="expand">False</property>
|
26
|
+
<property name="fill">True</property>
|
27
|
+
<property name="position">0</property>
|
28
|
+
</packing>
|
29
|
+
</child>
|
30
|
+
</object>
|
31
|
+
</child>
|
32
|
+
</template>
|
33
|
+
</interface>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gluby-tk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2097i
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,19 +52,49 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.1.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: wannabe_bool
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.0
|
55
83
|
description: A tool for creating GTK applications using Ruby and Glade
|
56
84
|
email:
|
57
85
|
- i2097i@hotmail.com
|
58
86
|
executables:
|
59
|
-
- gluby
|
87
|
+
- gluby
|
60
88
|
extensions: []
|
61
89
|
extra_rdoc_files: []
|
62
90
|
files:
|
63
|
-
- bin/gluby
|
91
|
+
- bin/gluby
|
64
92
|
- lib/core_ext/string.rb
|
65
93
|
- lib/gluby-tk.rb
|
66
94
|
- lib/gluby-tk/generator.rb
|
67
95
|
- lib/gluby-tk/version.rb
|
96
|
+
- templates/ApplicationWindow.glade.template
|
97
|
+
- templates/application.rb.template
|
68
98
|
- templates/boot.rb.template
|
69
99
|
- templates/includes.rb.template
|
70
100
|
homepage: https://github.com/i2097i/gluby-tk
|