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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ad90cf42c1588d6db4fb155446f3a1b886e4e3f
4
- data.tar.gz: cc7d20313f3eb5d67ba937ab9e2609cf8427fd9e
3
+ metadata.gz: 88bdbec6a3b26aeaaedbef372b27927afbae8b4f
4
+ data.tar.gz: 2192394b9cefcc9e37d9528e7a97ba2ce89218bc
5
5
  SHA512:
6
- metadata.gz: 660e04649c0488660ff22af4f726f5ee9345e31eeb24d0cc2c759c6fa6e6e3617d236b1c686e8b159557e063ae5a9cc58f7277c97d57a395fd9404d34bf5828e
7
- data.tar.gz: b954a8701a12e455cda5fd7b431ec3bca205d50b67c05a164c739c6cf93302842c989f3ee9854cc6bae7f8e7e0f62e9645abe1b217d2c822312efe1fbc783118
6
+ metadata.gz: f026a3bee2456fb7e92ae94f22836d83264400b88f79c663c261617aed073bc1c7ada621e3d9c521e1cab624c1f2f65daa6678b608e22cad783f63a93e2fe51c
7
+ data.tar.gz: fce9719f976b68e9df469b248874ef173c0f84d7ec01fdf26692f439b61cdf5544365089762fb2a84313120e9f0a3ca76b84023b4723b5b7dd476c2ffcfc6fe3
@@ -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)
@@ -1,5 +1,18 @@
1
1
  class String
2
+ DISALLOWED_CHARACTERS = "[\-\s\.\,\?\'\"\:\;\\\/]"
3
+
2
4
  def humanize
3
- self.gsub("_", " ").gsub("-", " ").split(" ").map(&:capitalize).join("")
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
@@ -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
- puts "#{app_name} already exists!" and exit(1) if File.exist?(app_name)
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 base module
34
- module_name = "#{app_name.downcase}"
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
- file.write("class Application < Gtk::Application
46
- def initialize
47
- super('app.#{app_id}', :handles_open)
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
- # Create ApplicationWindow
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
- end
69
-
70
- def initialize(application: application)
71
- super(application: application)
72
- end
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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
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
- File.open("#{root}/interface/ApplicationWindow.glade", "w+") { |file|
87
- file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
88
- <!-- Generated with glade 3.20.0 -->
89
- <interface>
90
- <requires lib=\"gtk+\" version=\"3.20\"/>
91
- <template class=\"ApplicationWindow\" parent=\"GtkApplicationWindow\">
92
- <property name=\"can_focus\">False</property>
93
- <property name=\"window_position\">center</property>
94
- <property name=\"icon_name\">computer</property>
95
- <property name=\"gravity\">center</property>
96
- <property name=\"show_menubar\">False</property>
97
- <child>
98
- <object class=\"GtkBox\" id=\"main_box\">
99
- <property name=\"width_request\">300</property>
100
- <property name=\"height_request\">300</property>
101
- <property name=\"visible\">True</property>
102
- <property name=\"can_focus\">False</property>
103
- <property name=\"orientation\">vertical</property>
104
- <child>
105
- <object class=\"GtkLabel\" id=\"welcome_label\">
106
- <property name=\"visible\">True</property>
107
- <property name=\"can_focus\">False</property>
108
- <property name=\"label\" translatable=\"yes\">Welcome to #{module_name.humanize}!\n\nBuilt with RGTK</property>
109
- </object>
110
- <packing>
111
- <property name=\"expand\">False</property>
112
- <property name=\"fill\">True</property>
113
- <property name=\"position\">0</property>
114
- </packing>
115
- </child>
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
@@ -1,3 +1,3 @@
1
1
  module GlubyTK
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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>
@@ -0,0 +1,9 @@
1
+ class Application < Gtk::Application
2
+ def initialize
3
+ super('app.gluby-tk_app_id', :handles_open)
4
+ signal_connect 'activate' do |application|
5
+ @window = ApplicationWindow.new(:application => application)
6
+ @window.present
7
+ end
8
+ end
9
+ end
@@ -5,6 +5,7 @@ $: << 'src/controller/'
5
5
  $: << 'src/helpers/'
6
6
 
7
7
  # Dependencies
8
+ require 'fileutils'
8
9
  require 'gtk3'
9
10
  require 'application_window'
10
11
  require 'application'
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.0
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-28 00:00:00.000000000 Z
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-tk
87
+ - gluby
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
- - bin/gluby-tk
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