gluby-tk 0.1.3 → 0.1.4

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: df814d914256418a1371666ceccd4e4df8fb5317
4
- data.tar.gz: 46f945053c302840b0ed4d3815ecf82712b4e733
3
+ metadata.gz: 7230842b7ddad5638110b30934fe18254ebac815
4
+ data.tar.gz: 4ecfb3baa8ad8596ff88ef6c0515bf5aaed5f502
5
5
  SHA512:
6
- metadata.gz: bff13c27d15fe3bbf8f35dd5a1fbf217e7083d76d009964c1e7c7a4ececf775ff1d263a2ca58616de41ca44c625550994086b5e615d31b0819fcc8fe913d757d
7
- data.tar.gz: 61b20596daf636c1c709d4a0d511cdb8bded7184bb88bac869388a256e9b05c9e9d6aff7b026d6576dd866a452987a1c24d8d920ff0e3fa08aafc5245f270af6
6
+ metadata.gz: 5849f6647db95aaa2b01bf4625627a6086477f0d6bae418e42d3a5f5a62dc44fab07974eeec2ef12f8bf17d30a8ebbfa976a990c181128f14e5cca321e5d7560
7
+ data.tar.gz: 3c50b955da1765736c518ffbbba0820aeffb846a5b0b1609c118b6abf0ba21cb273cc33da2cf186a8d3c23a79cdc225b4965cf0b100788d32dfd862f9d2ec22f
data/bin/gluby CHANGED
@@ -19,18 +19,27 @@ require "wannabe_bool"
19
19
  # GlubyTK.hi
20
20
  # end
21
21
 
22
- puts "No command specified - exiting now..." and exit(0) if ARGV.empty?
22
+ GlubyTK.gputs "No command specified - exiting now..." and exit(0) if ARGV.empty?
23
23
 
24
24
  if ARGV[0] == "new"
25
25
  if ARGV[1].nil? || ARGV[1].strip.empty?
26
- puts "No app name specified - exiting now..."
26
+ GlubyTK.gputs "No app name specified - exiting now..."
27
27
  exit(1)
28
28
  else
29
- puts "Creating #{ARGV[1]}..."
29
+ GlubyTK.gputs "Creating #{ARGV[1]}..."
30
30
  GlubyTK::Generator.create(ARGV[1])
31
31
  end
32
32
  elsif ARGV[0] == "rebuild"
33
- GlubyTK::Generator.rebuild(nil, !ARGV[1].nil? ? ARGV[1].to_b : false)
33
+ exit(1) unless GlubyTK::Generator.is_glubytk_directory?
34
+ GlubyTK.gputs "Rebuilding..."
35
+ GlubyTK::Generator.rebuild
36
+ elsif ARGV[0] == "start"
37
+ exit(1) unless GlubyTK::Generator.is_glubytk_directory?
38
+ GlubyTK.gputs "Starting #{GlubyTK::Generator.current_app_name}..."
39
+ system "ruby main.rb &"
40
+ elsif ARGV[0] == 'listen'
41
+ exit(1) unless GlubyTK::Generator.is_glubytk_directory?
42
+ GlubyTK::Listener.new
34
43
  end
35
44
 
36
45
  exit(0)
data/lib/gluby-tk.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require "core_ext/string"
1
2
  require "gluby-tk/version"
3
+ require "gluby-tk/logger"
2
4
  require "gluby-tk/generator"
3
- require "core_ext/string"
5
+ require "gluby-tk/listener"
4
6
 
5
7
  module GlubyTK
6
8
 
@@ -1,7 +1,7 @@
1
1
  require 'nokogiri'
2
- require 'pp'
3
2
 
4
3
  module GlubyTK
4
+
5
5
  class Generator
6
6
  DIRECTORIES = [
7
7
  "assets",
@@ -12,7 +12,8 @@ module GlubyTK
12
12
  ]
13
13
 
14
14
  TEMPLATES = [
15
- {:name => "main.rb", :path => ""},
15
+ {:name => "main.rb", :path => nil},
16
+ {:name => "Gemfile", :path => nil},
16
17
  {:name => "includes.rb", :path => "src"},
17
18
  {:name => "application.rb", :path => "src"},
18
19
  {:name => "ApplicationWindow.glade", :path => "interface"}
@@ -20,7 +21,7 @@ module GlubyTK
20
21
 
21
22
  def self.create app_name
22
23
  if File.exist?(app_name)
23
- puts "#{app_name} already exists!"
24
+ GlubyTK.gputs "#{app_name} already exists!"
24
25
  exit(1)
25
26
  end
26
27
 
@@ -28,9 +29,8 @@ module GlubyTK
28
29
 
29
30
  module_name = "#{app_name.underscore}"
30
31
 
31
- app_id = module_name.humanize.downcase
32
-
33
32
  # Create root directory
33
+ GlubyTK.gputs "Creating new project directory..."
34
34
  Dir.mkdir "#{Dir.pwd}/#{app_name}"
35
35
 
36
36
  # Create gluby-tkrc file
@@ -40,36 +40,40 @@ module GlubyTK
40
40
 
41
41
  # Create sub-directories
42
42
  DIRECTORIES.each do |dir|
43
+ GlubyTK.gputs "Creating directory: #{dir}..."
43
44
  Dir.mkdir "#{root}/#{dir}"
44
45
  end
45
46
 
46
47
  # Generate files from templates
47
48
  TEMPLATES.each do |template|
48
- File.open("#{root}/#{template[:path]}/#{template[:name]}", "w+") { |file|
49
- file.write(get_template_contents("#{template[:name]}.template").gsub("gluby-tk_app_id", app_id))
49
+ template_dest_file = "#{root}/#{template[:path].nil? ? "" : template[:path] + "/"}#{template[:name]}"
50
+ GlubyTK.gputs "Creating #{template_dest_file}"
51
+ File.open(template_dest_file, "w+") { |file|
52
+ file.write(get_template_contents("#{template[:name]}.template").gsub("gluby-tk_app_id", module_name))
50
53
  }
51
54
  end
52
55
 
53
- rebuild(root, true)
56
+ rebuild(root)
57
+ GlubyTK.gputs "Finished creating #{module_name}"
58
+ GlubyTK.gputs "Done!"
54
59
  end
55
60
 
56
- def self.rebuild(root = nil, generate_ruby_classes = false)
57
- unless is_glubytk_directory?(root)
58
- puts "No GlubyTK project detected. Please make sure you are in the right directory"
59
- exit(1)
60
- end
61
-
61
+ def self.rebuild(root = nil)
62
+ GlubyTK.gputs "Constructing gresource file..."
62
63
  root = root || Dir.pwd
63
64
 
64
65
  interface_files = Dir["#{root}/interface/*.glade"]
66
+
65
67
  gresource_file_contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
66
68
  gresource_file_contents += "<gresources>\n"
69
+
67
70
  interface_files.each { |filename|
68
71
  gresource_file_contents += "<gresource prefix=\"/app/#{current_app_name(root)}\">"
69
72
  gresource_file_contents += "<file preprocess=\"xml-stripblanks\">#{File.basename(filename)}</file>"
70
73
  gresource_file_contents += "</gresource>"
71
- generate_ruby_class_for_document(File.basename(filename), File.read(filename), root, generate_ruby_classes)
74
+ generate_ruby_class_for_document(File.basename(filename), File.read(filename), root)
72
75
  }
76
+
73
77
  gresource_file_contents += "</gresources>\n"
74
78
 
75
79
  File.open("#{root}/interface/interface.gresource.xml", "w+") { |file|
@@ -77,7 +81,7 @@ module GlubyTK
77
81
  }
78
82
  end
79
83
 
80
- def self.generate_ruby_class_for_document(file_name, file_contents, root, generate_ruby_classes)
84
+ def self.generate_ruby_class_for_document(file_name, file_contents, root)
81
85
  doc = Nokogiri::XML(file_contents)
82
86
 
83
87
  if doc.css("template").first.nil?
@@ -94,6 +98,8 @@ module GlubyTK
94
98
 
95
99
  base_file_name = "#{file_name.gsub(File.extname(file_name), "").underscore}"
96
100
 
101
+ GlubyTK.gputs "Constructing #{base_file_name} Ruby class..."
102
+
97
103
  gluby_file_dir = "#{root}/src/gluby"
98
104
  gluby_file_path = "#{gluby_file_dir}/gluby_#{base_file_name}.rb"
99
105
  gluby_class_file_contents = [
@@ -109,20 +115,24 @@ module GlubyTK
109
115
  ].join("\n")
110
116
 
111
117
  File.open(gluby_file_path, "w+") { |file|
118
+ GlubyTK.gputs "Writing #{gluby_file_path}..."
112
119
  file.write gluby_class_file_contents
113
120
  }
114
121
 
115
- if generate_ruby_classes
116
- file_path = "#{root}/src/#{base_file_name}.rb"
122
+ # TODO: Need to ensure that the user-facing class (not the gluby_class_name) reflects any updates such as root class name change etc.
123
+ file_path = "#{root}/src/#{base_file_name}.rb"
124
+ if !File.exist?(file_path)
125
+ GlubyTK.gputs "#{file_path} did not exist. Creating..."
117
126
  class_file_contents = [
118
127
  "class #{class_name.underscore.humanize}",
119
128
  "\tdef initialize(args = nil)",
120
129
  "\t\tsuper(args)",
121
130
  "\tend",
122
- "end",
131
+ "end"
123
132
  ].join("\n")
124
133
 
125
134
  File.open(file_path, "w+") { |file|
135
+ GlubyTK.gputs "Writing #{file_path}..."
126
136
  file.write class_file_contents
127
137
  }
128
138
  end
@@ -131,6 +141,8 @@ module GlubyTK
131
141
  contents = file.read
132
142
  g_req = "require 'gluby_#{base_file_name}'"
133
143
  req = "require '#{base_file_name}'"
144
+
145
+ GlubyTK.gputs "Checking require entries for #{base_file_name}..."
134
146
  file.write("#{g_req}\n") if contents.match(g_req).nil?
135
147
  file.write("#{req}\n") if contents.match(req).nil?
136
148
  }
@@ -138,8 +150,6 @@ module GlubyTK
138
150
 
139
151
  # Helpers
140
152
 
141
- private
142
-
143
153
  def self.get_template_contents(template_name)
144
154
  File.read("#{template_dir}#{template_name}")
145
155
  end
@@ -153,12 +163,15 @@ module GlubyTK
153
163
  end
154
164
 
155
165
  def self.is_glubytk_directory?(dir = nil)
156
- File.exist?(glubytk_rc_path(dir))
166
+ is_g_project = File.exist?(glubytk_rc_path(dir))
167
+
168
+ GlubyTK.gputs "No GlubyTK project detected. Please make sure you are in the right directory." if !is_g_project
169
+
170
+ return is_g_project
157
171
  end
158
172
 
159
173
  def self.glubytk_rc_path(dir = nil)
160
174
  "#{dir || Dir.pwd}/.gluby-tkrc"
161
175
  end
162
-
163
176
  end
164
177
  end
@@ -0,0 +1,15 @@
1
+ require 'listen'
2
+ module GlubyTK
3
+ class Listener
4
+ attr_accessor :listener
5
+
6
+ def initialize
7
+ GlubyTK.gputs "Starting listener..."
8
+ @listener = Listen.to(Dir.pwd) do |modified, added, removed|
9
+ GlubyTK::Generator.rebuild if (modified + added + removed).map{|path| File.extname(path)}.select{|extension| extension == '.glade'}.any?
10
+ end
11
+ @listener.start
12
+ sleep
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module GlubyTK
2
+ def self.gputs value, spaces = 4
3
+ puts "#{"\s" * spaces}[GlubyTK]: #{value}"
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module GlubyTK
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Listen for interface file changes
4
+ gem 'listen'
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2097i
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: listen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.5
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: gtk3
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,8 +120,11 @@ files:
106
120
  - lib/core_ext/string.rb
107
121
  - lib/gluby-tk.rb
108
122
  - lib/gluby-tk/generator.rb
123
+ - lib/gluby-tk/listener.rb
124
+ - lib/gluby-tk/logger.rb
109
125
  - lib/gluby-tk/version.rb
110
126
  - templates/ApplicationWindow.glade.template
127
+ - templates/Gemfile.template
111
128
  - templates/application.rb.template
112
129
  - templates/includes.rb.template
113
130
  - templates/main.rb.template