glimmer-dsl-swt 4.17.1.1 → 4.17.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,8 +71,11 @@ module Glimmer
71
71
 
72
72
  def tablify(gem_prefix, gems)
73
73
  array_of_arrays = gems.map do |gem|
74
+ name, namespace = gem[:name].sub(gem_prefix, '').underscore.titlecase.split
75
+ human_name = name
76
+ human_name += " (#{namespace})" unless namespace.nil?
74
77
  [
75
- gem[:name].sub(gem_prefix, '').underscore.titlecase,
78
+ human_name,
76
79
  gem[:name],
77
80
  gem[:version],
78
81
  gem[:author].sub('Author: ', ''),
@@ -0,0 +1,128 @@
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 'os'
23
+
24
+ # TODO refactor to nest under RakeTask namespace
25
+ module Glimmer
26
+ module RakeTask
27
+ module Package
28
+ class << self
29
+ attr_accessor :javapackager_extra_args
30
+ alias jpackage_extra_args :javapackager_extra_args
31
+
32
+ def clean
33
+ require 'fileutils'
34
+ FileUtils.rm_rf('dist')
35
+ FileUtils.rm_rf('packages')
36
+ end
37
+
38
+ def config
39
+ project_name = File.basename(File.expand_path('.'))
40
+ if !File.exists?('config/warble.rb')
41
+ puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
42
+ FileUtils.mkdir_p('config')
43
+ if OS.windows?
44
+ system "jruby -S gem install warbler -v2.0.5 --no-document" unless warbler_exists?
45
+ else
46
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n jruby -S gem install warbler -v2.0.5 --no-document\n'" unless warbler_exists?
47
+ end
48
+ if system('warble config')
49
+ new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
50
+ if line.include?('config.dirs =')
51
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app bin config db docs fonts icons images lib package script sounds vendor videos)')
52
+ end
53
+ if line.include?('config.includes =')
54
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
55
+ end
56
+ if line.include?('config.autodeploy_dir =')
57
+ line = line.sub('# ', '')
58
+ end
59
+ output + "\n" + line
60
+ end
61
+ File.write('config/warble.rb', new_config)
62
+ else
63
+ puts 'Warbler executable "warble" is missing!'
64
+ end
65
+ end
66
+ end
67
+
68
+ def jar
69
+ FileUtils.mkdir_p('dist')
70
+ puts "Generating JAR with Warbler..."
71
+ system "jruby -S gem install warbler -v2.0.5 --no-document" unless warbler_exists?
72
+ system('warble')
73
+ end
74
+
75
+ def lock_jars
76
+ puts 'Locking gem jar-dependencies by downloading & storing in vendor/jars...'
77
+ FileUtils.mkdir_p('vendor/jars')
78
+ command = "lock_jars --vendor-dir vendor/jars"
79
+ puts command
80
+ system command
81
+ end
82
+
83
+ def native(native_type=nil, native_extra_args)
84
+ puts "Generating native executable with javapackager/jpackage..."
85
+ require 'facets/string/titlecase'
86
+ require 'facets/string/underscore'
87
+ project_name = File.basename(File.expand_path('.'))
88
+ version_file = File.expand_path('./VERSION')
89
+ version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
90
+ license_file = File.expand_path('./LICENSE.txt')
91
+ license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
92
+ copyright = license.split("\n").first
93
+ human_name = project_name.underscore.titlecase
94
+ icon = "package/#{OS.mac? ? 'macosx' : 'windows'}/#{human_name}.#{OS.mac? ? 'icns' : 'ico'}"
95
+ if (`javapackager`.to_s.include?('Usage: javapackager') rescue nil)
96
+ command = "javapackager -deploy -native #{native_type} -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" "
97
+ command += " -BsystemWide=false " if OS.windows?
98
+ command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
99
+ command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
100
+ command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
101
+ command += " -Bcopyright=\"#{copyright}\" " if copyright
102
+ elsif (`jpackage`.to_s.include?('Usage: jpackage') rescue nil)
103
+ command = "jpackage --type #{native_type} --dest 'packages/bundles' --input 'dist' --main-class JarMain --main-jar '#{project_name}.jar' --name '#{human_name}' --vendor '#{human_name}' --icon '#{icon}' "
104
+ command += " --win-per-user-install --win-dir-chooser --win-menu --win-menu-group '#{human_name}' " if OS.windows?
105
+ command += " --java-options '-XstartOnFirstThread' --mac-package-name '#{human_name}' --mac-package-identifier 'org.#{project_name}.application.#{project_name}' " if OS.mac?
106
+ command += " --app-version \"#{version}\" " if version
107
+ command += " --license-file LICENSE.txt " if license
108
+ command += " --copyright \"#{copyright}\" " if copyright
109
+ else
110
+ puts "Neither javapackager nor jpackage exist in your Java installation. Please ensure javapackager or jpackage is available in PATH environment variable."
111
+ return
112
+ end
113
+ command += " #{javapackager_extra_args} " if javapackager_extra_args
114
+ command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
115
+ command += " #{native_extra_args} " if native_extra_args
116
+ puts command
117
+ system command
118
+ end
119
+
120
+ private
121
+
122
+ def warbler_exists?
123
+ OS.windows? ? system('where warble') : system('which warble')
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,661 @@
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
+ system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
127
+ system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
128
+ cd gem_name
129
+ rm_rf 'lib'
130
+ write '.gitignore', GITIGNORE
131
+ write '.ruby-version', RUBY_VERSION
132
+ write '.ruby-gemset', app_name
133
+ write 'VERSION', '1.0.0'
134
+ write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
135
+ write 'Gemfile', GEMFILE
136
+ write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
137
+ mkdir 'app'
138
+ write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
139
+ mkdir 'app/models'
140
+ mkdir 'app/views'
141
+ custom_shell('AppView', current_dir_name, :app)
142
+
143
+ mkdir_p 'package/windows'
144
+ icon_file = "package/windows/#{human_name(app_name)}.ico"
145
+ cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
146
+ puts "Created #{current_dir_name}/#{icon_file}"
147
+
148
+ mkdir_p 'package/macosx'
149
+ icon_file = "package/macosx/#{human_name(app_name)}.icns"
150
+ cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
151
+ puts "Created #{current_dir_name}/#{icon_file}"
152
+
153
+ mkdir_p 'package/linux'
154
+ icon_file = "package/linux/#{human_name(app_name)}.png"
155
+ cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
156
+ puts "Created #{current_dir_name}/#{icon_file}"
157
+
158
+ mkdir 'bin'
159
+ write "bin/#{file_name(app_name)}", app_bin_file(app_name)
160
+ if OS.windows?
161
+ system "bundle"
162
+ system "rspec --init"
163
+ else
164
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
165
+ end
166
+ write 'spec/spec_helper.rb', spec_helper_file
167
+ if OS.windows?
168
+ system "glimmer package[image]"
169
+ system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
170
+ else
171
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
172
+ if OS.mac?
173
+ system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
174
+ else
175
+ system "glimmer bin/#{file_name(app_name)}"
176
+ end
177
+ end
178
+ end
179
+
180
+ def custom_shell(custom_shell_name, namespace, shell_type = nil)
181
+ namespace ||= current_dir_name
182
+ root_dir = File.exists?('app') ? 'app' : 'lib'
183
+ parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
184
+ mkdir_p parent_dir unless File.exists?(parent_dir)
185
+ write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
186
+ end
187
+
188
+ def custom_widget(custom_widget_name, namespace)
189
+ namespace ||= current_dir_name
190
+ root_dir = File.exists?('app') ? 'app' : 'lib'
191
+ parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
192
+ mkdir_p parent_dir unless File.exists?(parent_dir)
193
+ write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
194
+ end
195
+
196
+ def custom_shell_gem(custom_shell_name, namespace)
197
+ gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
198
+ gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
199
+ begin
200
+ custom_shell_keyword = dsl_widget_name(custom_shell_name)
201
+ MAIN_OBJECT.method(custom_shell_keyword)
202
+ return puts("CustomShell keyword `#{custom_shell_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
203
+ rescue NameError
204
+ # No Op (keyword is not taken by a built in Ruby method)
205
+ end
206
+ if namespace
207
+ gem_name += "-#{compact_name(namespace)}"
208
+ gem_summary += " (#{human_name(namespace)})"
209
+ else
210
+ return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
211
+ namespace = 'glimmer'
212
+ end
213
+ system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
214
+ system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
215
+ cd gem_name
216
+ write '.gitignore', GITIGNORE
217
+ write '.ruby-version', RUBY_VERSION
218
+ write '.ruby-gemset', gem_name
219
+ write 'VERSION', '1.0.0'
220
+ write 'Gemfile', GEMFILE
221
+ write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
222
+ append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
223
+ mkdir 'lib/views'
224
+ custom_shell(custom_shell_name, namespace, :gem)
225
+ mkdir 'bin'
226
+ write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
227
+ write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
228
+ FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
229
+ if OS.windows?
230
+ system "bundle"
231
+ system "rspec --init"
232
+ else
233
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
234
+ end
235
+ write 'spec/spec_helper.rb', spec_helper_file
236
+
237
+ mkdir_p 'package/windows'
238
+ icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
239
+ cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
240
+ puts "Created #{current_dir_name}/#{icon_file}"
241
+
242
+ mkdir_p 'package/macosx'
243
+ icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
244
+ cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
245
+ puts "Created #{current_dir_name}/#{icon_file}"
246
+
247
+ mkdir_p 'package/linux'
248
+ icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
249
+ cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
250
+ puts "Created #{current_dir_name}/#{icon_file}"
251
+
252
+ if OS.windows?
253
+ system "glimmer package[image]"
254
+ system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
255
+ else
256
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
257
+ if OS.mac?
258
+ system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
259
+ else
260
+ system "bin/#{file_name(custom_shell_name)}"
261
+ end
262
+ end
263
+ puts "Finished creating #{gem_name} Ruby gem."
264
+ puts 'Edit Rakefile to configure gem details.'
265
+ puts 'Run `rake` to execute specs.'
266
+ puts 'Run `rake build` to build gem.'
267
+ puts 'Run `rake release` to release into rubygems.org once ready.'
268
+ end
269
+
270
+ def custom_widget_gem(custom_widget_name, namespace)
271
+ 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'
272
+ gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
273
+ gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
274
+ if namespace
275
+ gem_name += "-#{compact_name(namespace)}"
276
+ gem_summary += " (#{human_name(namespace)})"
277
+ else
278
+ namespace = 'glimmer'
279
+ end
280
+
281
+ system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
282
+ system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
283
+ cd gem_name
284
+ write '.gitignore', GITIGNORE
285
+ write '.ruby-version', RUBY_VERSION
286
+ write '.ruby-gemset', gem_name
287
+ write 'VERSION', '1.0.0'
288
+ write 'Gemfile', GEMFILE
289
+ write 'Rakefile', gem_rakefile
290
+ append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
291
+ mkdir 'lib/views'
292
+ custom_widget(custom_widget_name, namespace)
293
+ if OS.windows?
294
+ system "bundle"
295
+ system "rspec --init"
296
+ else
297
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
298
+ end
299
+ write 'spec/spec_helper.rb', spec_helper_file
300
+ puts "Finished creating #{gem_name} Ruby gem."
301
+ puts 'Edit Rakefile to configure gem details.'
302
+ puts 'Run `rake` to execute specs.'
303
+ puts 'Run `rake build` to build gem.'
304
+ puts 'Run `rake release` to release into rubygems.org once ready.'
305
+ end
306
+
307
+ private
308
+
309
+ def juwelier_exists?
310
+ OS.windows? ? system('where juwelier') : system('which juwelier')
311
+ end
312
+
313
+ def write(file, content)
314
+ File.write file, content
315
+ file_path = File.expand_path(file)
316
+ puts "Created #{current_dir_name}/#{file}"
317
+ end
318
+
319
+ def append(file, content)
320
+ File.open(file, 'a') do |f|
321
+ f.write(content)
322
+ end
323
+ end
324
+
325
+ def current_dir_name
326
+ File.basename(File.expand_path('.'))
327
+ end
328
+
329
+ def class_name(app_name)
330
+ app_name.underscore.camelcase(:upper)
331
+ end
332
+
333
+ def file_name(app_name)
334
+ app_name.underscore
335
+ end
336
+ alias dsl_widget_name file_name
337
+
338
+ def human_name(app_name)
339
+ app_name.underscore.titlecase
340
+ end
341
+
342
+ def compact_name(gem_name)
343
+ gem_name.underscore.camelcase.downcase
344
+ end
345
+
346
+ def app_main_file(app_name)
347
+ <<~MULTI_LINE_STRING
348
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
349
+
350
+ require 'bundler/setup'
351
+ Bundler.require(:default)
352
+ require 'views/#{file_name(app_name)}/app_view'
353
+
354
+ class #{class_name(app_name)}
355
+ include Glimmer
356
+
357
+ APP_ROOT = File.expand_path('../..', __FILE__)
358
+ VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
359
+ LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
360
+
361
+ def open
362
+ app_view.open
363
+ end
364
+ end
365
+ MULTI_LINE_STRING
366
+ end
367
+
368
+ def gem_main_file(custom_widget_name, namespace = nil)
369
+ custom_widget_file_path = "views"
370
+ custom_widget_file_path += "/#{file_name(namespace)}" if namespace
371
+ custom_widget_file_path += "/#{file_name(custom_widget_name)}"
372
+
373
+ <<~MULTI_LINE_STRING
374
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
375
+
376
+ require 'glimmer-dsl-swt'
377
+ require '#{custom_widget_file_path}'
378
+ MULTI_LINE_STRING
379
+ end
380
+
381
+ def app_bin_file(app_name)
382
+ <<~MULTI_LINE_STRING
383
+ require_relative '../app/#{file_name(app_name)}'
384
+
385
+ #{class_name(app_name)}.new.open
386
+ MULTI_LINE_STRING
387
+ end
388
+
389
+ def gem_bin_file(gem_name, custom_shell_name, namespace)
390
+ # TODO change this so that it does not mix Glimmer unto the main object
391
+ <<~MULTI_LINE_STRING
392
+ require_relative '../lib/#{gem_name}'
393
+
394
+ class #{class_name(custom_shell_name)}App
395
+ include Glimmer
396
+
397
+ def open
398
+ #{dsl_widget_name(custom_shell_name)}.open
399
+ end
400
+ end
401
+
402
+ #{class_name(custom_shell_name)}App.new.open
403
+ MULTI_LINE_STRING
404
+ end
405
+
406
+ def gem_bin_command_file(gem_name)
407
+ <<~MULTI_LINE_STRING
408
+ #!/usr/bin/env jruby
409
+
410
+ require 'glimmer/launcher'
411
+
412
+ runner = File.expand_path("../#{gem_name}", __FILE__)
413
+ launcher = Glimmer::Launcher.new([runner] + ARGV)
414
+ launcher.launch
415
+ MULTI_LINE_STRING
416
+ end
417
+
418
+ def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
419
+ rakefile_content = File.read('Rakefile')
420
+ lines = rakefile_content.split("\n")
421
+ require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
422
+ lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
423
+ gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
424
+ if custom_shell_name
425
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
426
+ lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
427
+ lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
428
+ else
429
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
430
+ end
431
+ spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
432
+ lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_os_specific_options]")
433
+ lines << "\nrequire 'glimmer/rake_task'\n"
434
+ file_content = lines.join("\n")
435
+ if custom_shell_name
436
+ file_content << <<~MULTI_LINE_STRING
437
+ Glimmer::RakeTask::Package.javapackager_extra_args =
438
+ " -name '#{human_name(custom_shell_name)}'" +
439
+ " -title '#{human_name(custom_shell_name)}'" +
440
+ " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
441
+ " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).capitalize}'"
442
+ # " -BlicenseType=" +
443
+ # " -Bmac.category=" +
444
+ # " -Bmac.signing-key-developer-id-app="
445
+ MULTI_LINE_STRING
446
+ end
447
+ file_content
448
+ end
449
+
450
+ def spec_helper_file
451
+ content = File.read('spec/spec_helper.rb')
452
+ lines = content.split("\n")
453
+ require_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') })
454
+ lines[require_line_index...require_line_index] = [
455
+ "require 'bundler/setup'",
456
+ 'Bundler.require(:default, :development)',
457
+ ]
458
+ configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
459
+ lines[configure_block_line_index...configure_block_line_index] = [
460
+ ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
461
+ ' config.after do',
462
+ ' @target.dispose if @target && @target.respond_to?(:dispose)',
463
+ ' Glimmer::DSL::Engine.reset',
464
+ ' end',
465
+ ]
466
+
467
+ lines << "\nrequire 'glimmer/rake_task'\n"
468
+ lines.join("\n")
469
+ end
470
+
471
+ def custom_shell_file(custom_shell_name, namespace, shell_type)
472
+ namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
473
+
474
+ custom_shell_file_content = <<-MULTI_LINE_STRING
475
+ #{namespace_type} #{class_name(namespace)}
476
+ class #{class_name(custom_shell_name)}
477
+ include Glimmer::UI::CustomShell
478
+
479
+ MULTI_LINE_STRING
480
+
481
+ if shell_type == :gem
482
+ custom_shell_file_content += <<-MULTI_LINE_STRING
483
+ APP_ROOT = File.expand_path('../../../..', __FILE__)
484
+ VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
485
+ LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
486
+
487
+ MULTI_LINE_STRING
488
+ end
489
+
490
+ custom_shell_file_content += <<-MULTI_LINE_STRING
491
+ ## Add options like the following to configure CustomShell by outside consumers
492
+ #
493
+ # options :title, :background_color
494
+ # option :width, default: 320
495
+ # option :height, default: 240
496
+ option :greeting, default: 'Hello, World!'
497
+
498
+ ## Use before_body block to pre-initialize variables to use in body
499
+ #
500
+ #
501
+ MULTI_LINE_STRING
502
+
503
+ if %i[gem app].include?(shell_type)
504
+ custom_shell_file_content += <<-MULTI_LINE_STRING
505
+ before_body {
506
+ Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
507
+ Display.setAppVersion(VERSION)
508
+ @display = display {
509
+ on_about {
510
+ display_about_dialog
511
+ }
512
+ on_preferences {
513
+ display_preferences_dialog
514
+ }
515
+ }
516
+ }
517
+ MULTI_LINE_STRING
518
+ else
519
+ custom_shell_file_content += <<-MULTI_LINE_STRING
520
+ # before_body {
521
+ #
522
+ # }
523
+ MULTI_LINE_STRING
524
+ end
525
+
526
+ custom_shell_file_content += <<-MULTI_LINE_STRING
527
+
528
+ ## Use after_body block to setup observers for widgets in body
529
+ #
530
+ # after_body {
531
+ #
532
+ # }
533
+
534
+ ## Add widget content inside custom shell body
535
+ ## Top-most widget must be a shell or another custom shell
536
+ #
537
+ body {
538
+ shell {
539
+ # Replace example content below with custom shell content
540
+ minimum_size 320, 240
541
+ image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
542
+ text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
543
+ grid_layout
544
+ label(:center) {
545
+ text bind(self, :greeting)
546
+ font height: 40
547
+ layout_data :fill, :center, true, true
548
+ }
549
+ menu_bar {
550
+ menu {
551
+ text '&File'
552
+ menu_item {
553
+ text '&Preferences...'
554
+ on_widget_selected {
555
+ display_preferences_dialog
556
+ }
557
+ }
558
+ }
559
+ }
560
+ }
561
+ }
562
+ MULTI_LINE_STRING
563
+
564
+ if %i[gem app].include?(shell_type)
565
+ custom_shell_file_content += <<-MULTI_LINE_STRING
566
+
567
+ def display_about_dialog
568
+ message_box(body_root) {
569
+ text 'About'
570
+ message "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\\n\\n\#{LICENSE}"
571
+ }.open
572
+ end
573
+
574
+ def display_preferences_dialog
575
+ dialog(swt_widget) {
576
+ text 'Preferences'
577
+ grid_layout {
578
+ margin_height 5
579
+ margin_width 5
580
+ }
581
+ group {
582
+ row_layout {
583
+ type :vertical
584
+ spacing 10
585
+ }
586
+ text 'Greeting'
587
+ font style: :bold
588
+ [
589
+ 'Hello, World!',
590
+ 'Howdy, Partner!'
591
+ ].each do |greeting_text|
592
+ button(:radio) {
593
+ text greeting_text
594
+ selection bind(self, :greeting) { |g| g == greeting_text }
595
+ layout_data {
596
+ width 160
597
+ }
598
+ on_widget_selected { |event|
599
+ self.greeting = event.widget.getText
600
+ }
601
+ }
602
+ end
603
+ }
604
+ }.open
605
+ end
606
+ MULTI_LINE_STRING
607
+ end
608
+
609
+ custom_shell_file_content += <<-MULTI_LINE_STRING
610
+ end
611
+ end
612
+ MULTI_LINE_STRING
613
+ end
614
+
615
+ def custom_widget_file(custom_widget_name, namespace)
616
+ namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
617
+
618
+ <<~MULTI_LINE_STRING
619
+ #{namespace_type} #{class_name(namespace)}
620
+ class #{class_name(custom_widget_name)}
621
+ include Glimmer::UI::CustomWidget
622
+
623
+ ## Add options like the following to configure CustomWidget by outside consumers
624
+ #
625
+ # options :custom_text, :background_color
626
+ # option :foreground_color, default: :red
627
+
628
+ ## Use before_body block to pre-initialize variables to use in body
629
+ #
630
+ #
631
+ # before_body {
632
+ #
633
+ # }
634
+
635
+ ## Use after_body block to setup observers for widgets in body
636
+ #
637
+ # after_body {
638
+ #
639
+ # }
640
+
641
+ ## Add widget content under custom widget body
642
+ ##
643
+ ## If you want to add a shell as the top-most widget,
644
+ ## consider creating a custom shell instead
645
+ ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
646
+ #
647
+ body {
648
+ # Replace example content below with custom widget content
649
+ label {
650
+ background :red
651
+ }
652
+ }
653
+
654
+ end
655
+ end
656
+ MULTI_LINE_STRING
657
+ end
658
+ end
659
+ end
660
+ end
661
+ end