glimmer-dsl-swt 4.17.1.1 → 4.17.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +320 -111
- data/VERSION +1 -1
- data/bin/glimmer +0 -4
- data/glimmer-dsl-swt.gemspec +14 -14
- data/lib/ext/glimmer/config.rb +1 -0
- data/lib/glimmer-dsl-swt.rb +6 -0
- data/lib/glimmer/data_binding/table_items_binding.rb +1 -0
- data/lib/glimmer/launcher.rb +15 -6
- data/lib/glimmer/rake_task.rb +56 -18
- data/lib/glimmer/rake_task/list.rb +4 -1
- data/lib/glimmer/rake_task/package.rb +132 -0
- data/lib/glimmer/rake_task/scaffold.rb +669 -0
- data/lib/glimmer/swt/image_proxy.rb +34 -11
- data/lib/glimmer/swt/shell_proxy.rb +1 -0
- data/lib/glimmer/swt/style_constantizable.rb +2 -1
- data/lib/glimmer/swt/widget_proxy.rb +45 -33
- data/lib/glimmer/ui/custom_widget.rb +7 -4
- data/lib/glimmer/util/proc_tracker.rb +2 -0
- data/samples/elaborate/contact_manager/contact_repository.rb +3 -99
- data/samples/hello/hello_combo.rb +10 -6
- data/samples/hello/hello_custom_shell.rb +155 -0
- data/samples/hello/hello_custom_widget.rb +86 -0
- data/samples/hello/hello_tab.rb +10 -5
- data/samples/hello/hello_world.rb +2 -2
- metadata +25 -43
- data/lib/glimmer/package.rb +0 -112
- data/lib/glimmer/scaffold.rb +0 -652
@@ -0,0 +1,669 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'fileutils'
|
23
|
+
require 'os'
|
24
|
+
require 'facets'
|
25
|
+
|
26
|
+
# TODO refactor to nest under RakeTask namespace
|
27
|
+
|
28
|
+
MAIN_OBJECT = self
|
29
|
+
|
30
|
+
module Glimmer
|
31
|
+
module RakeTask
|
32
|
+
class Scaffold
|
33
|
+
class << self
|
34
|
+
include FileUtils
|
35
|
+
|
36
|
+
VERSION = File.read(File.expand_path('../../../../VERSION', __FILE__)).strip
|
37
|
+
RUBY_VERSION = File.read(File.expand_path('../../../../RUBY_VERSION', __FILE__)).strip
|
38
|
+
|
39
|
+
# TODO externalize all constants into scaffold/files
|
40
|
+
|
41
|
+
GITIGNORE = <<~MULTI_LINE_STRING
|
42
|
+
*.gem
|
43
|
+
*.rbc
|
44
|
+
/.config
|
45
|
+
/coverage/
|
46
|
+
/InstalledFiles
|
47
|
+
/pkg/
|
48
|
+
/spec/reports/
|
49
|
+
/spec/examples.txt
|
50
|
+
/test/tmp/
|
51
|
+
/test/version_tmp/
|
52
|
+
/tmp/
|
53
|
+
|
54
|
+
# Used by dotenv library to load environment variables.
|
55
|
+
# .env
|
56
|
+
|
57
|
+
## Specific to RubyMotion:
|
58
|
+
.dat*
|
59
|
+
.repl_history
|
60
|
+
build/
|
61
|
+
*.bridgesupport
|
62
|
+
build-iPhoneOS/
|
63
|
+
build-iPhoneSimulator/
|
64
|
+
|
65
|
+
## Specific to RubyMotion (use of CocoaPods):
|
66
|
+
#
|
67
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
68
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
69
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
70
|
+
#
|
71
|
+
# vendor/Pods/
|
72
|
+
|
73
|
+
## Documentation cache and generated files:
|
74
|
+
/.yardoc/
|
75
|
+
/_yardoc/
|
76
|
+
/doc/
|
77
|
+
/rdoc/
|
78
|
+
|
79
|
+
## Environment normalization:
|
80
|
+
/.bundle/
|
81
|
+
/vendor/bundle
|
82
|
+
/lib/bundler/man/
|
83
|
+
|
84
|
+
# for a library or gem, you might want to ignore these files since the code is
|
85
|
+
# intended to run in multiple environments; otherwise, check them in:
|
86
|
+
# Gemfile.lock
|
87
|
+
# .ruby-version
|
88
|
+
# .ruby-gemset
|
89
|
+
|
90
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
91
|
+
.rvmrc
|
92
|
+
|
93
|
+
# Mac
|
94
|
+
.DS_Store
|
95
|
+
|
96
|
+
# Gladiator (Glimmer Editor)
|
97
|
+
.gladiator
|
98
|
+
|
99
|
+
# Glimmer
|
100
|
+
dist
|
101
|
+
packages
|
102
|
+
vendor/jars
|
103
|
+
MULTI_LINE_STRING
|
104
|
+
|
105
|
+
GEMFILE = <<~MULTI_LINE_STRING
|
106
|
+
# frozen_string_literal: true
|
107
|
+
|
108
|
+
source 'https://rubygems.org'
|
109
|
+
|
110
|
+
git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
|
111
|
+
|
112
|
+
gem 'glimmer-dsl-swt', '~> #{VERSION}'
|
113
|
+
|
114
|
+
group :development do
|
115
|
+
gem 'rspec', '~> 3.5.0'
|
116
|
+
gem 'git-glimmer', '1.7.0'
|
117
|
+
gem 'juwelier', '2.4.9'
|
118
|
+
gem 'warbler', '2.0.5'
|
119
|
+
gem 'simplecov', '>= 0'
|
120
|
+
end
|
121
|
+
MULTI_LINE_STRING
|
122
|
+
|
123
|
+
def app(app_name)
|
124
|
+
gem_name = file_name(app_name)
|
125
|
+
gem_summary = human_name(app_name)
|
126
|
+
return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
|
127
|
+
system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
|
128
|
+
system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
129
|
+
return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
|
130
|
+
cd gem_name
|
131
|
+
rm_rf 'lib'
|
132
|
+
write '.gitignore', GITIGNORE
|
133
|
+
write '.ruby-version', RUBY_VERSION
|
134
|
+
write '.ruby-gemset', app_name
|
135
|
+
write 'VERSION', '1.0.0'
|
136
|
+
write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
|
137
|
+
write 'Gemfile', GEMFILE
|
138
|
+
write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
|
139
|
+
mkdir 'app'
|
140
|
+
write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
|
141
|
+
mkdir 'app/models'
|
142
|
+
mkdir 'app/views'
|
143
|
+
custom_shell('AppView', current_dir_name, :app)
|
144
|
+
|
145
|
+
mkdir_p 'package/windows'
|
146
|
+
icon_file = "package/windows/#{human_name(app_name)}.ico"
|
147
|
+
cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
|
148
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
149
|
+
|
150
|
+
mkdir_p 'package/macosx'
|
151
|
+
icon_file = "package/macosx/#{human_name(app_name)}.icns"
|
152
|
+
cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
|
153
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
154
|
+
|
155
|
+
mkdir_p 'package/linux'
|
156
|
+
icon_file = "package/linux/#{human_name(app_name)}.png"
|
157
|
+
cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
|
158
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
159
|
+
|
160
|
+
mkdir 'bin'
|
161
|
+
write "bin/#{file_name(app_name)}", app_bin_file(app_name)
|
162
|
+
if OS.windows?
|
163
|
+
system "bundle"
|
164
|
+
system "rspec --init"
|
165
|
+
else
|
166
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
|
167
|
+
end
|
168
|
+
write 'spec/spec_helper.rb', spec_helper_file
|
169
|
+
if OS.windows?
|
170
|
+
system "glimmer package[image]"
|
171
|
+
system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
|
172
|
+
else
|
173
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
|
174
|
+
if OS.mac?
|
175
|
+
system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
|
176
|
+
else
|
177
|
+
system "glimmer bin/#{file_name(app_name)}"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def custom_shell(custom_shell_name, namespace, shell_type = nil)
|
183
|
+
namespace ||= current_dir_name
|
184
|
+
root_dir = File.exists?('app') ? 'app' : 'lib'
|
185
|
+
parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
|
186
|
+
return puts("The file '#{parent_dir}/#{file_name(custom_shell_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_shell_name)}.rb")
|
187
|
+
mkdir_p parent_dir unless File.exists?(parent_dir)
|
188
|
+
write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
|
189
|
+
end
|
190
|
+
|
191
|
+
def custom_widget(custom_widget_name, namespace)
|
192
|
+
namespace ||= current_dir_name
|
193
|
+
root_dir = File.exists?('app') ? 'app' : 'lib'
|
194
|
+
parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
|
195
|
+
return puts("The file '#{parent_dir}/#{file_name(custom_widget_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_widget_name)}.rb")
|
196
|
+
mkdir_p parent_dir unless File.exists?(parent_dir)
|
197
|
+
write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
|
198
|
+
end
|
199
|
+
|
200
|
+
def custom_shell_gem(custom_shell_name, namespace)
|
201
|
+
gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
|
202
|
+
gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
|
203
|
+
begin
|
204
|
+
custom_shell_keyword = dsl_widget_name(custom_shell_name)
|
205
|
+
MAIN_OBJECT.method(custom_shell_keyword)
|
206
|
+
return puts("CustomShell keyword `#{custom_shell_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
|
207
|
+
rescue NameError
|
208
|
+
# No Op (keyword is not taken by a built in Ruby method)
|
209
|
+
end
|
210
|
+
if namespace
|
211
|
+
gem_name += "-#{compact_name(namespace)}"
|
212
|
+
gem_summary += " (#{human_name(namespace)})"
|
213
|
+
else
|
214
|
+
return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
|
215
|
+
namespace = 'glimmer'
|
216
|
+
end
|
217
|
+
return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
|
218
|
+
system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
|
219
|
+
system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
220
|
+
return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
|
221
|
+
cd gem_name
|
222
|
+
write '.gitignore', GITIGNORE
|
223
|
+
write '.ruby-version', RUBY_VERSION
|
224
|
+
write '.ruby-gemset', gem_name
|
225
|
+
write 'VERSION', '1.0.0'
|
226
|
+
write 'Gemfile', GEMFILE
|
227
|
+
write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
|
228
|
+
append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
|
229
|
+
mkdir 'lib/views'
|
230
|
+
custom_shell(custom_shell_name, namespace, :gem)
|
231
|
+
mkdir 'bin'
|
232
|
+
write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
|
233
|
+
write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
|
234
|
+
FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
|
235
|
+
if OS.windows?
|
236
|
+
system "bundle"
|
237
|
+
system "rspec --init"
|
238
|
+
else
|
239
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
|
240
|
+
end
|
241
|
+
write 'spec/spec_helper.rb', spec_helper_file
|
242
|
+
|
243
|
+
mkdir_p 'package/windows'
|
244
|
+
icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
|
245
|
+
cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
|
246
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
247
|
+
|
248
|
+
mkdir_p 'package/macosx'
|
249
|
+
icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
|
250
|
+
cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
|
251
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
252
|
+
|
253
|
+
mkdir_p 'package/linux'
|
254
|
+
icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
|
255
|
+
cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
|
256
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
257
|
+
|
258
|
+
if OS.windows?
|
259
|
+
system "glimmer package[image]"
|
260
|
+
system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
|
261
|
+
else
|
262
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
|
263
|
+
if OS.mac?
|
264
|
+
system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
|
265
|
+
else
|
266
|
+
system "bin/#{file_name(custom_shell_name)}"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
puts "Finished creating #{gem_name} Ruby gem."
|
270
|
+
puts 'Edit Rakefile to configure gem details.'
|
271
|
+
puts 'Run `rake` to execute specs.'
|
272
|
+
puts 'Run `rake build` to build gem.'
|
273
|
+
puts 'Run `rake release` to release into rubygems.org once ready.'
|
274
|
+
end
|
275
|
+
|
276
|
+
def custom_widget_gem(custom_widget_name, namespace)
|
277
|
+
return puts('Namespace is required! Usage: glimmer scaffold:custom_widget_gem[custom_widget_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
|
278
|
+
gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
|
279
|
+
gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
|
280
|
+
if namespace
|
281
|
+
gem_name += "-#{compact_name(namespace)}"
|
282
|
+
gem_summary += " (#{human_name(namespace)})"
|
283
|
+
else
|
284
|
+
namespace = 'glimmer'
|
285
|
+
end
|
286
|
+
|
287
|
+
return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
|
288
|
+
system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
|
289
|
+
system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
290
|
+
return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
|
291
|
+
cd gem_name
|
292
|
+
write '.gitignore', GITIGNORE
|
293
|
+
write '.ruby-version', RUBY_VERSION
|
294
|
+
write '.ruby-gemset', gem_name
|
295
|
+
write 'VERSION', '1.0.0'
|
296
|
+
write 'Gemfile', GEMFILE
|
297
|
+
write 'Rakefile', gem_rakefile
|
298
|
+
append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
|
299
|
+
mkdir 'lib/views'
|
300
|
+
custom_widget(custom_widget_name, namespace)
|
301
|
+
if OS.windows?
|
302
|
+
system "bundle"
|
303
|
+
system "rspec --init"
|
304
|
+
else
|
305
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
|
306
|
+
end
|
307
|
+
write 'spec/spec_helper.rb', spec_helper_file
|
308
|
+
puts "Finished creating #{gem_name} Ruby gem."
|
309
|
+
puts 'Edit Rakefile to configure gem details.'
|
310
|
+
puts 'Run `rake` to execute specs.'
|
311
|
+
puts 'Run `rake build` to build gem.'
|
312
|
+
puts 'Run `rake release` to release into rubygems.org once ready.'
|
313
|
+
end
|
314
|
+
|
315
|
+
private
|
316
|
+
|
317
|
+
def juwelier_exists?
|
318
|
+
OS.windows? ? system('where juwelier') : system('which juwelier')
|
319
|
+
end
|
320
|
+
|
321
|
+
def write(file, content)
|
322
|
+
File.write file, content
|
323
|
+
file_path = File.expand_path(file)
|
324
|
+
puts "Created #{current_dir_name}/#{file}"
|
325
|
+
end
|
326
|
+
|
327
|
+
def append(file, content)
|
328
|
+
File.open(file, 'a') do |f|
|
329
|
+
f.write(content)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def current_dir_name
|
334
|
+
File.basename(File.expand_path('.'))
|
335
|
+
end
|
336
|
+
|
337
|
+
def class_name(app_name)
|
338
|
+
app_name.underscore.camelcase(:upper)
|
339
|
+
end
|
340
|
+
|
341
|
+
def file_name(app_name)
|
342
|
+
app_name.underscore
|
343
|
+
end
|
344
|
+
alias dsl_widget_name file_name
|
345
|
+
|
346
|
+
def human_name(app_name)
|
347
|
+
app_name.underscore.titlecase
|
348
|
+
end
|
349
|
+
|
350
|
+
def compact_name(gem_name)
|
351
|
+
gem_name.underscore.camelcase.downcase
|
352
|
+
end
|
353
|
+
|
354
|
+
def app_main_file(app_name)
|
355
|
+
<<~MULTI_LINE_STRING
|
356
|
+
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
357
|
+
|
358
|
+
require 'bundler/setup'
|
359
|
+
Bundler.require(:default)
|
360
|
+
require 'views/#{file_name(app_name)}/app_view'
|
361
|
+
|
362
|
+
class #{class_name(app_name)}
|
363
|
+
include Glimmer
|
364
|
+
|
365
|
+
APP_ROOT = File.expand_path('../..', __FILE__)
|
366
|
+
VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
|
367
|
+
LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
|
368
|
+
|
369
|
+
def open
|
370
|
+
app_view.open
|
371
|
+
end
|
372
|
+
end
|
373
|
+
MULTI_LINE_STRING
|
374
|
+
end
|
375
|
+
|
376
|
+
def gem_main_file(custom_widget_name, namespace = nil)
|
377
|
+
custom_widget_file_path = "views"
|
378
|
+
custom_widget_file_path += "/#{file_name(namespace)}" if namespace
|
379
|
+
custom_widget_file_path += "/#{file_name(custom_widget_name)}"
|
380
|
+
|
381
|
+
<<~MULTI_LINE_STRING
|
382
|
+
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
383
|
+
|
384
|
+
require 'glimmer-dsl-swt'
|
385
|
+
require '#{custom_widget_file_path}'
|
386
|
+
MULTI_LINE_STRING
|
387
|
+
end
|
388
|
+
|
389
|
+
def app_bin_file(app_name)
|
390
|
+
<<~MULTI_LINE_STRING
|
391
|
+
require_relative '../app/#{file_name(app_name)}'
|
392
|
+
|
393
|
+
#{class_name(app_name)}.new.open
|
394
|
+
MULTI_LINE_STRING
|
395
|
+
end
|
396
|
+
|
397
|
+
def gem_bin_file(gem_name, custom_shell_name, namespace)
|
398
|
+
# TODO change this so that it does not mix Glimmer unto the main object
|
399
|
+
<<~MULTI_LINE_STRING
|
400
|
+
require_relative '../lib/#{gem_name}'
|
401
|
+
|
402
|
+
class #{class_name(custom_shell_name)}App
|
403
|
+
include Glimmer
|
404
|
+
|
405
|
+
def open
|
406
|
+
#{dsl_widget_name(custom_shell_name)}.open
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
#{class_name(custom_shell_name)}App.new.open
|
411
|
+
MULTI_LINE_STRING
|
412
|
+
end
|
413
|
+
|
414
|
+
def gem_bin_command_file(gem_name)
|
415
|
+
<<~MULTI_LINE_STRING
|
416
|
+
#!/usr/bin/env jruby
|
417
|
+
|
418
|
+
require 'glimmer/launcher'
|
419
|
+
|
420
|
+
runner = File.expand_path("../#{gem_name}", __FILE__)
|
421
|
+
launcher = Glimmer::Launcher.new([runner] + ARGV)
|
422
|
+
launcher.launch
|
423
|
+
MULTI_LINE_STRING
|
424
|
+
end
|
425
|
+
|
426
|
+
def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
|
427
|
+
rakefile_content = File.read('Rakefile')
|
428
|
+
lines = rakefile_content.split("\n")
|
429
|
+
require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
|
430
|
+
lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
|
431
|
+
gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
|
432
|
+
if custom_shell_name
|
433
|
+
lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
|
434
|
+
lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
|
435
|
+
lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
|
436
|
+
else
|
437
|
+
lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
|
438
|
+
end
|
439
|
+
spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
|
440
|
+
lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_os_specific_options]")
|
441
|
+
lines << "\nrequire 'glimmer/rake_task'\n"
|
442
|
+
file_content = lines.join("\n")
|
443
|
+
if custom_shell_name
|
444
|
+
file_content << <<~MULTI_LINE_STRING
|
445
|
+
Glimmer::RakeTask::Package.javapackager_extra_args =
|
446
|
+
" -name '#{human_name(custom_shell_name)}'" +
|
447
|
+
" -title '#{human_name(custom_shell_name)}'" +
|
448
|
+
" -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
|
449
|
+
" -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).capitalize}'"
|
450
|
+
# " -BlicenseType=" +
|
451
|
+
# " -Bmac.category=" +
|
452
|
+
# " -Bmac.signing-key-developer-id-app="
|
453
|
+
MULTI_LINE_STRING
|
454
|
+
end
|
455
|
+
file_content
|
456
|
+
end
|
457
|
+
|
458
|
+
def spec_helper_file
|
459
|
+
content = File.read('spec/spec_helper.rb')
|
460
|
+
lines = content.split("\n")
|
461
|
+
require_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') })
|
462
|
+
lines[require_line_index...require_line_index] = [
|
463
|
+
"require 'bundler/setup'",
|
464
|
+
'Bundler.require(:default, :development)',
|
465
|
+
]
|
466
|
+
configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
|
467
|
+
lines[configure_block_line_index...configure_block_line_index] = [
|
468
|
+
' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
|
469
|
+
' config.after do',
|
470
|
+
' @target.dispose if @target && @target.respond_to?(:dispose)',
|
471
|
+
' Glimmer::DSL::Engine.reset',
|
472
|
+
' end',
|
473
|
+
]
|
474
|
+
|
475
|
+
lines << "\nrequire 'glimmer/rake_task'\n"
|
476
|
+
lines.join("\n")
|
477
|
+
end
|
478
|
+
|
479
|
+
def custom_shell_file(custom_shell_name, namespace, shell_type)
|
480
|
+
namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
|
481
|
+
|
482
|
+
custom_shell_file_content = <<-MULTI_LINE_STRING
|
483
|
+
#{namespace_type} #{class_name(namespace)}
|
484
|
+
class #{class_name(custom_shell_name)}
|
485
|
+
include Glimmer::UI::CustomShell
|
486
|
+
|
487
|
+
MULTI_LINE_STRING
|
488
|
+
|
489
|
+
if shell_type == :gem
|
490
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
491
|
+
APP_ROOT = File.expand_path('../../../..', __FILE__)
|
492
|
+
VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
|
493
|
+
LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
|
494
|
+
|
495
|
+
MULTI_LINE_STRING
|
496
|
+
end
|
497
|
+
|
498
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
499
|
+
## Add options like the following to configure CustomShell by outside consumers
|
500
|
+
#
|
501
|
+
# options :title, :background_color
|
502
|
+
# option :width, default: 320
|
503
|
+
# option :height, default: 240
|
504
|
+
option :greeting, default: 'Hello, World!'
|
505
|
+
|
506
|
+
## Use before_body block to pre-initialize variables to use in body
|
507
|
+
#
|
508
|
+
#
|
509
|
+
MULTI_LINE_STRING
|
510
|
+
|
511
|
+
if %i[gem app].include?(shell_type)
|
512
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
513
|
+
before_body {
|
514
|
+
Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
|
515
|
+
Display.setAppVersion(VERSION)
|
516
|
+
@display = display {
|
517
|
+
on_about {
|
518
|
+
display_about_dialog
|
519
|
+
}
|
520
|
+
on_preferences {
|
521
|
+
display_preferences_dialog
|
522
|
+
}
|
523
|
+
}
|
524
|
+
}
|
525
|
+
MULTI_LINE_STRING
|
526
|
+
else
|
527
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
528
|
+
# before_body {
|
529
|
+
#
|
530
|
+
# }
|
531
|
+
MULTI_LINE_STRING
|
532
|
+
end
|
533
|
+
|
534
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
535
|
+
|
536
|
+
## Use after_body block to setup observers for widgets in body
|
537
|
+
#
|
538
|
+
# after_body {
|
539
|
+
#
|
540
|
+
# }
|
541
|
+
|
542
|
+
## Add widget content inside custom shell body
|
543
|
+
## Top-most widget must be a shell or another custom shell
|
544
|
+
#
|
545
|
+
body {
|
546
|
+
shell {
|
547
|
+
# Replace example content below with custom shell content
|
548
|
+
minimum_size 320, 240
|
549
|
+
image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
|
550
|
+
text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
|
551
|
+
grid_layout
|
552
|
+
label(:center) {
|
553
|
+
text bind(self, :greeting)
|
554
|
+
font height: 40
|
555
|
+
layout_data :fill, :center, true, true
|
556
|
+
}
|
557
|
+
menu_bar {
|
558
|
+
menu {
|
559
|
+
text '&File'
|
560
|
+
menu_item {
|
561
|
+
text '&Preferences...'
|
562
|
+
on_widget_selected {
|
563
|
+
display_preferences_dialog
|
564
|
+
}
|
565
|
+
}
|
566
|
+
}
|
567
|
+
}
|
568
|
+
}
|
569
|
+
}
|
570
|
+
MULTI_LINE_STRING
|
571
|
+
|
572
|
+
if %i[gem app].include?(shell_type)
|
573
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
574
|
+
|
575
|
+
def display_about_dialog
|
576
|
+
message_box(body_root) {
|
577
|
+
text 'About'
|
578
|
+
message "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\\n\\n\#{LICENSE}"
|
579
|
+
}.open
|
580
|
+
end
|
581
|
+
|
582
|
+
def display_preferences_dialog
|
583
|
+
dialog(swt_widget) {
|
584
|
+
text 'Preferences'
|
585
|
+
grid_layout {
|
586
|
+
margin_height 5
|
587
|
+
margin_width 5
|
588
|
+
}
|
589
|
+
group {
|
590
|
+
row_layout {
|
591
|
+
type :vertical
|
592
|
+
spacing 10
|
593
|
+
}
|
594
|
+
text 'Greeting'
|
595
|
+
font style: :bold
|
596
|
+
[
|
597
|
+
'Hello, World!',
|
598
|
+
'Howdy, Partner!'
|
599
|
+
].each do |greeting_text|
|
600
|
+
button(:radio) {
|
601
|
+
text greeting_text
|
602
|
+
selection bind(self, :greeting) { |g| g == greeting_text }
|
603
|
+
layout_data {
|
604
|
+
width 160
|
605
|
+
}
|
606
|
+
on_widget_selected { |event|
|
607
|
+
self.greeting = event.widget.getText
|
608
|
+
}
|
609
|
+
}
|
610
|
+
end
|
611
|
+
}
|
612
|
+
}.open
|
613
|
+
end
|
614
|
+
MULTI_LINE_STRING
|
615
|
+
end
|
616
|
+
|
617
|
+
custom_shell_file_content += <<-MULTI_LINE_STRING
|
618
|
+
end
|
619
|
+
end
|
620
|
+
MULTI_LINE_STRING
|
621
|
+
end
|
622
|
+
|
623
|
+
def custom_widget_file(custom_widget_name, namespace)
|
624
|
+
namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
|
625
|
+
|
626
|
+
<<~MULTI_LINE_STRING
|
627
|
+
#{namespace_type} #{class_name(namespace)}
|
628
|
+
class #{class_name(custom_widget_name)}
|
629
|
+
include Glimmer::UI::CustomWidget
|
630
|
+
|
631
|
+
## Add options like the following to configure CustomWidget by outside consumers
|
632
|
+
#
|
633
|
+
# options :custom_text, :background_color
|
634
|
+
# option :foreground_color, default: :red
|
635
|
+
|
636
|
+
## Use before_body block to pre-initialize variables to use in body
|
637
|
+
#
|
638
|
+
#
|
639
|
+
# before_body {
|
640
|
+
#
|
641
|
+
# }
|
642
|
+
|
643
|
+
## Use after_body block to setup observers for widgets in body
|
644
|
+
#
|
645
|
+
# after_body {
|
646
|
+
#
|
647
|
+
# }
|
648
|
+
|
649
|
+
## Add widget content under custom widget body
|
650
|
+
##
|
651
|
+
## If you want to add a shell as the top-most widget,
|
652
|
+
## consider creating a custom shell instead
|
653
|
+
## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
|
654
|
+
#
|
655
|
+
body {
|
656
|
+
# Replace example content below with custom widget content
|
657
|
+
label {
|
658
|
+
background :red
|
659
|
+
}
|
660
|
+
}
|
661
|
+
|
662
|
+
end
|
663
|
+
end
|
664
|
+
MULTI_LINE_STRING
|
665
|
+
end
|
666
|
+
end
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|