glimmer-dsl-swt 4.17.1.0 → 4.17.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
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
+ # This class declares a `greeting_label` custom widget (by convention)
23
+ class GreetingLabel
24
+ include Glimmer::UI::CustomWidget
25
+
26
+ # multiple options without default values
27
+ options :name, :colors
28
+
29
+ # single option with default value
30
+ option :greeting, default: 'Hello'
31
+
32
+ # internal attribute (not a custom widget option)
33
+ attr_accessor :color
34
+
35
+ before_body {
36
+ @font = {height: 24, style: :bold}
37
+ @color = :black
38
+ }
39
+
40
+ after_body {
41
+ return if colors.nil?
42
+
43
+ Thread.new {
44
+ colors.cycle { |color|
45
+ async_exec {
46
+ self.color = color
47
+ }
48
+ sleep(1)
49
+ }
50
+ }
51
+ }
52
+
53
+ body {
54
+ # pass received swt_style through to label to customize (e.g. :center to center text)
55
+ label(swt_style) {
56
+ text "#{greeting}, #{name}!"
57
+ font @font
58
+ foreground bind(self, :color)
59
+ }
60
+ }
61
+
62
+ end
63
+
64
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `greeting_label` custom widget
65
+ include Glimmer
66
+
67
+ shell {
68
+ fill_layout :vertical
69
+
70
+ minimum_size 215, 215
71
+ text 'Hello, Custom Widget!'
72
+
73
+ # custom widget options are passed in a hash
74
+ greeting_label(name: 'Sean')
75
+
76
+ # pass :center SWT style followed by custom widget options hash
77
+ greeting_label(:center, name: 'Laura', greeting: 'Aloha') #
78
+
79
+ greeting_label(:right, name: 'Rick') {
80
+ # you can nest attributes under custom widgets just like any standard widget
81
+ foreground :red
82
+ }
83
+
84
+ # the colors option cycles between colors for the label foreground every second
85
+ greeting_label(:center, name: 'Mary', greeting: 'Aloha', colors: [:red, :dark_green, :blue])
86
+ }.open
@@ -21,20 +21,25 @@
21
21
 
22
22
  class HelloTab
23
23
  include Glimmer
24
+
24
25
  def launch
25
26
  shell {
26
- text "Hello, Tab!"
27
+ text 'Hello, Tab!'
28
+
27
29
  tab_folder {
28
30
  tab_item {
29
- text "English"
31
+ text 'English'
32
+
30
33
  label {
31
- text "Hello, World!"
34
+ text 'Hello, World!'
32
35
  }
33
36
  }
37
+
34
38
  tab_item {
35
- text "French"
39
+ text 'French'
40
+
36
41
  label {
37
- text "Bonjour, Univers!"
42
+ text 'Bonjour, Univers!'
38
43
  }
39
44
  }
40
45
  }
@@ -22,8 +22,8 @@
22
22
  include Glimmer
23
23
 
24
24
  shell {
25
- text "Glimmer"
25
+ text 'Glimmer'
26
26
  label {
27
- text "Hello, World!"
27
+ text 'Hello, World!'
28
28
  }
29
29
  }.open
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.17.1.0
4
+ version: 4.17.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-24 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 1.0.0
18
+ version: 1.0.1
19
19
  name: glimmer
20
20
  prerelease: false
21
21
  type: :runtime
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -57,7 +57,7 @@ dependencies:
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.10.1
60
+ version: 0.10.2
61
61
  name: puts_debuggerer
62
62
  prerelease: false
63
63
  type: :runtime
@@ -65,13 +65,13 @@ dependencies:
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.1
68
+ version: 0.10.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.2.2
74
+ version: 0.2.3
75
75
  - - "<"
76
76
  - !ruby/object:Gem::Version
77
77
  version: 2.0.0
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 0.2.2
85
+ version: 0.2.3
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 2.0.0
@@ -100,26 +100,6 @@ dependencies:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.7.0
103
- - !ruby/object:Gem::Dependency
104
- requirement: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: 2.4.9
109
- - - "<"
110
- - !ruby/object:Gem::Version
111
- version: 3.0.0
112
- name: juwelier
113
- prerelease: false
114
- type: :runtime
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: 2.4.9
120
- - - "<"
121
- - !ruby/object:Gem::Version
122
- version: 3.0.0
123
103
  - !ruby/object:Gem::Dependency
124
104
  requirement: !ruby/object:Gem::Requirement
125
105
  requirements:
@@ -185,38 +165,38 @@ dependencies:
185
165
  requirements:
186
166
  - - ">="
187
167
  - !ruby/object:Gem::Version
188
- version: 6.2.1
168
+ version: 1.2.4
189
169
  - - "<"
190
170
  - !ruby/object:Gem::Version
191
- version: 7.0.0
192
- name: rdoc
171
+ version: 2.0.0
172
+ name: text-table
193
173
  prerelease: false
194
174
  type: :runtime
195
175
  version_requirements: !ruby/object:Gem::Requirement
196
176
  requirements:
197
177
  - - ">="
198
178
  - !ruby/object:Gem::Version
199
- version: 6.2.1
179
+ version: 1.2.4
200
180
  - - "<"
201
181
  - !ruby/object:Gem::Version
202
- version: 7.0.0
182
+ version: 2.0.0
203
183
  - !ruby/object:Gem::Dependency
204
184
  requirement: !ruby/object:Gem::Requirement
205
185
  requirements:
206
186
  - - ">="
207
187
  - !ruby/object:Gem::Version
208
- version: 1.2.4
188
+ version: 0.6.0
209
189
  - - "<"
210
190
  - !ruby/object:Gem::Version
211
191
  version: 2.0.0
212
- name: text-table
192
+ name: tty-markdown
213
193
  prerelease: false
214
194
  type: :runtime
215
195
  version_requirements: !ruby/object:Gem::Requirement
216
196
  requirements:
217
197
  - - ">="
218
198
  - !ruby/object:Gem::Version
219
- version: 1.2.4
199
+ version: 0.6.0
220
200
  - - "<"
221
201
  - !ruby/object:Gem::Version
222
202
  version: 2.0.0
@@ -225,21 +205,21 @@ dependencies:
225
205
  requirements:
226
206
  - - ">="
227
207
  - !ruby/object:Gem::Version
228
- version: 0.6.0
208
+ version: 2.4.9
229
209
  - - "<"
230
210
  - !ruby/object:Gem::Version
231
- version: 2.0.0
232
- name: tty-markdown
211
+ version: 3.0.0
212
+ name: juwelier
233
213
  prerelease: false
234
- type: :runtime
214
+ type: :development
235
215
  version_requirements: !ruby/object:Gem::Requirement
236
216
  requirements:
237
217
  - - ">="
238
218
  - !ruby/object:Gem::Version
239
- version: 0.6.0
219
+ version: 2.4.9
240
220
  - - "<"
241
221
  - !ruby/object:Gem::Version
242
- version: 2.0.0
222
+ version: 3.0.0
243
223
  - !ruby/object:Gem::Dependency
244
224
  requirement: !ruby/object:Gem::Requirement
245
225
  requirements:
@@ -251,7 +231,7 @@ dependencies:
251
231
  version: 3.0.0
252
232
  name: warbler
253
233
  prerelease: false
254
- type: :runtime
234
+ type: :development
255
235
  version_requirements: !ruby/object:Gem::Requirement
256
236
  requirements:
257
237
  - - ">="
@@ -398,11 +378,11 @@ files:
398
378
  - lib/glimmer/dsl/swt/widget_expression.rb
399
379
  - lib/glimmer/dsl/swt/widget_listener_expression.rb
400
380
  - lib/glimmer/launcher.rb
401
- - lib/glimmer/package.rb
402
381
  - lib/glimmer/rake_task.rb
403
382
  - lib/glimmer/rake_task/list.rb
383
+ - lib/glimmer/rake_task/package.rb
404
384
  - lib/glimmer/rake_task/sample.rb
405
- - lib/glimmer/scaffold.rb
385
+ - lib/glimmer/rake_task/scaffold.rb
406
386
  - lib/glimmer/swt/color_proxy.rb
407
387
  - lib/glimmer/swt/cursor_proxy.rb
408
388
  - lib/glimmer/swt/display_proxy.rb
@@ -440,6 +420,8 @@ files:
440
420
  - samples/hello/hello_combo.rb
441
421
  - samples/hello/hello_computed.rb
442
422
  - samples/hello/hello_computed/contact.rb
423
+ - samples/hello/hello_custom_shell.rb
424
+ - samples/hello/hello_custom_widget.rb
443
425
  - samples/hello/hello_drag_and_drop.rb
444
426
  - samples/hello/hello_list_multi_selection.rb
445
427
  - samples/hello/hello_list_single_selection.rb
@@ -1,112 +0,0 @@
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
-
26
- module Glimmer
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
- system('warble config')
44
- new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
45
- if line.include?('config.dirs =')
46
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app bin config db docs fonts icons images lib package script sounds vendor videos)')
47
- end
48
- if line.include?('config.includes =')
49
- line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
50
- end
51
- if line.include?('config.autodeploy_dir =')
52
- line = line.sub('# ', '')
53
- end
54
- output + "\n" + line
55
- end
56
- File.write('config/warble.rb', new_config)
57
- end
58
- end
59
-
60
- def jar
61
- FileUtils.mkdir_p('dist')
62
- puts "Generating JAR with Warbler..."
63
- system('warble')
64
- end
65
-
66
- def lock_jars
67
- puts 'Locking gem jar-dependencies by downloading & storing in vendor/jars...'
68
- FileUtils.mkdir_p('vendor/jars')
69
- command = "lock_jars --vendor-dir vendor/jars"
70
- puts command
71
- system command
72
- end
73
-
74
- def native(native_type=nil, native_extra_args)
75
- puts "Generating native executable with javapackager/jpackage..."
76
- require 'facets/string/titlecase'
77
- require 'facets/string/underscore'
78
- project_name = File.basename(File.expand_path('.'))
79
- version_file = File.expand_path('./VERSION')
80
- version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
81
- license_file = File.expand_path('./LICENSE.txt')
82
- license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
83
- copyright = license.split("\n").first
84
- human_name = project_name.underscore.titlecase
85
- icon = "package/#{OS.mac? ? 'macosx' : 'windows'}/#{human_name}.#{OS.mac? ? 'icns' : 'ico'}"
86
- if (`javapackager`.to_s.include?('Usage: javapackager') rescue nil)
87
- 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}\" "
88
- command += " -BsystemWide=false " if OS.windows?
89
- command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
90
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
91
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
92
- command += " -Bcopyright=\"#{copyright}\" " if copyright
93
- elsif (`jpackage`.to_s.include?('Usage: jpackage') rescue nil)
94
- 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}' "
95
- command += " --win-per-user-install --win-dir-chooser --win-menu --win-menu-group '#{human_name}' " if OS.windows?
96
- command += " --java-options '-XstartOnFirstThread' --mac-package-name '#{human_name}' --mac-package-identifier 'org.#{project_name}.application.#{project_name}' " if OS.mac?
97
- command += " --app-version \"#{version}\" " if version
98
- command += " --license-file LICENSE.txt " if license
99
- command += " --copyright \"#{copyright}\" " if copyright
100
- else
101
- puts "Neither javapackager nor jpackage exist in your Java installation. Please ensure javapackager or jpackage is available in PATH environment variable."
102
- return
103
- end
104
- command += " #{javapackager_extra_args} " if javapackager_extra_args
105
- command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
106
- command += " #{native_extra_args} " if native_extra_args
107
- puts command
108
- system command
109
- end
110
- end
111
- end
112
- end
@@ -1,652 +0,0 @@
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
- class Scaffold
31
- class << self
32
- include FileUtils
33
-
34
- VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
35
- RUBY_VERSION = File.read(File.expand_path('../../../RUBY_VERSION', __FILE__)).strip
36
-
37
- # TODO externalize all constants into scaffold/files
38
-
39
- GITIGNORE = <<~MULTI_LINE_STRING
40
- *.gem
41
- *.rbc
42
- /.config
43
- /coverage/
44
- /InstalledFiles
45
- /pkg/
46
- /spec/reports/
47
- /spec/examples.txt
48
- /test/tmp/
49
- /test/version_tmp/
50
- /tmp/
51
-
52
- # Used by dotenv library to load environment variables.
53
- # .env
54
-
55
- ## Specific to RubyMotion:
56
- .dat*
57
- .repl_history
58
- build/
59
- *.bridgesupport
60
- build-iPhoneOS/
61
- build-iPhoneSimulator/
62
-
63
- ## Specific to RubyMotion (use of CocoaPods):
64
- #
65
- # We recommend against adding the Pods directory to your .gitignore. However
66
- # you should judge for yourself, the pros and cons are mentioned at:
67
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
68
- #
69
- # vendor/Pods/
70
-
71
- ## Documentation cache and generated files:
72
- /.yardoc/
73
- /_yardoc/
74
- /doc/
75
- /rdoc/
76
-
77
- ## Environment normalization:
78
- /.bundle/
79
- /vendor/bundle
80
- /lib/bundler/man/
81
-
82
- # for a library or gem, you might want to ignore these files since the code is
83
- # intended to run in multiple environments; otherwise, check them in:
84
- # Gemfile.lock
85
- # .ruby-version
86
- # .ruby-gemset
87
-
88
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
89
- .rvmrc
90
-
91
- # Mac
92
- .DS_Store
93
-
94
- # Gladiator (Glimmer Editor)
95
- .gladiator
96
-
97
- # Glimmer
98
- dist
99
- packages
100
- vendor/jars
101
- MULTI_LINE_STRING
102
-
103
- GEMFILE = <<~MULTI_LINE_STRING
104
- # frozen_string_literal: true
105
-
106
- source 'https://rubygems.org'
107
-
108
- git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
109
-
110
- gem 'glimmer-dsl-swt', '~> #{VERSION}'
111
-
112
- group :development do
113
- gem 'rspec', '~> 3.5.0'
114
- gem 'git-glimmer', '1.7.0'
115
- gem 'juwelier', '2.4.9'
116
- gem 'simplecov', '>= 0'
117
- end
118
- MULTI_LINE_STRING
119
-
120
- RVM_FUNCTION = <<~MULTI_LINE_STRING
121
- # Load RVM into a shell session *as a function*
122
- if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
123
-
124
- # First try to load from a user install
125
- source "$HOME/.rvm/scripts/rvm"
126
-
127
- elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
128
-
129
- # Then try to load from a root install
130
- source "/usr/local/rvm/scripts/rvm"
131
-
132
- fi
133
- MULTI_LINE_STRING
134
-
135
- def app(app_name)
136
- gem_name = file_name(app_name)
137
- gem_summary = human_name(app_name)
138
- system "jruby -r git-glimmer -S juwelier --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
139
- cd gem_name
140
- rm_rf 'lib'
141
- write '.gitignore', GITIGNORE
142
- write '.ruby-version', RUBY_VERSION
143
- write '.ruby-gemset', app_name
144
- write 'VERSION', '1.0.0'
145
- write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
146
- write 'Gemfile', GEMFILE
147
- write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
148
- mkdir 'app'
149
- write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
150
- mkdir 'app/models'
151
- mkdir 'app/views'
152
- custom_shell('AppView', current_dir_name, :app)
153
-
154
- mkdir_p 'package/windows'
155
- icon_file = "package/windows/#{human_name(app_name)}.ico"
156
- cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
157
- puts "Created #{current_dir_name}/#{icon_file}"
158
-
159
- mkdir_p 'package/macosx'
160
- icon_file = "package/macosx/#{human_name(app_name)}.icns"
161
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
162
- puts "Created #{current_dir_name}/#{icon_file}"
163
-
164
- mkdir_p 'package/linux'
165
- icon_file = "package/linux/#{human_name(app_name)}.png"
166
- cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
167
- puts "Created #{current_dir_name}/#{icon_file}"
168
-
169
- mkdir 'bin'
170
- write "bin/#{file_name(app_name)}", app_bin_file(app_name)
171
- write 'spec/spec_helper.rb', spec_helper_file
172
- if OS.windows?
173
- system "bundle"
174
- system "glimmer package[image]"
175
- system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
176
- else
177
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
178
- if OS.mac?
179
- system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
180
- else
181
- system "glimmer bin/#{file_name(app_name)}"
182
- end
183
- end
184
- end
185
-
186
- def custom_shell(custom_shell_name, namespace, shell_type = nil)
187
- namespace ||= current_dir_name
188
- root_dir = File.exists?('app') ? 'app' : 'lib'
189
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
190
- mkdir_p parent_dir unless File.exists?(parent_dir)
191
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
192
- end
193
-
194
- def custom_widget(custom_widget_name, namespace)
195
- namespace ||= current_dir_name
196
- root_dir = File.exists?('app') ? 'app' : 'lib'
197
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
198
- mkdir_p parent_dir unless File.exists?(parent_dir)
199
- write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
200
- end
201
-
202
- def custom_shell_gem(custom_shell_name, namespace)
203
- gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
204
- gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
205
- begin
206
- custom_shell_keyword = dsl_widget_name(custom_shell_name)
207
- MAIN_OBJECT.method(custom_shell_keyword)
208
- return puts("CustomShell keyword `#{custom_shell_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
209
- rescue NameError
210
- # No Op (keyword is not taken by a built in Ruby method)
211
- end
212
- if namespace
213
- gem_name += "-#{compact_name(namespace)}"
214
- gem_summary += " (#{human_name(namespace)})"
215
- else
216
- return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
217
- namespace = 'glimmer'
218
- end
219
- system "jruby -r git-glimmer -S juwelier --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
220
- cd gem_name
221
- write '.gitignore', GITIGNORE
222
- write '.ruby-version', RUBY_VERSION
223
- write '.ruby-gemset', gem_name
224
- write 'VERSION', '1.0.0'
225
- write 'Gemfile', GEMFILE
226
- write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
227
- append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
228
- mkdir 'lib/views'
229
- custom_shell(custom_shell_name, namespace, :gem)
230
- mkdir 'bin'
231
- write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
232
- write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
233
- FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
234
- write 'spec/spec_helper.rb', spec_helper_file
235
-
236
- mkdir_p 'package/windows'
237
- icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
238
- cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
239
- puts "Created #{current_dir_name}/#{icon_file}"
240
-
241
- mkdir_p 'package/macosx'
242
- icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
243
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
244
- puts "Created #{current_dir_name}/#{icon_file}"
245
-
246
- mkdir_p 'package/linux'
247
- icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
248
- cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
249
- puts "Created #{current_dir_name}/#{icon_file}"
250
-
251
- if OS.windows?
252
- system "bundle"
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 bundle\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
- system "jruby -r git-glimmer -S juwelier --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
281
- cd gem_name
282
- write '.gitignore', GITIGNORE
283
- write '.ruby-version', RUBY_VERSION
284
- write '.ruby-gemset', gem_name
285
- write 'VERSION', '1.0.0'
286
- write 'Gemfile', GEMFILE
287
- write 'Rakefile', gem_rakefile
288
- write 'spec/spec_helper.rb', spec_helper_file
289
- append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
290
- mkdir 'lib/views'
291
- custom_widget(custom_widget_name, namespace)
292
- if OS.windows?
293
- system "bundle"
294
- else
295
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
296
- end
297
- puts "Finished creating #{gem_name} Ruby gem."
298
- puts 'Edit Rakefile to configure gem details.'
299
- puts 'Run `rake` to execute specs.'
300
- puts 'Run `rake build` to build gem.'
301
- puts 'Run `rake release` to release into rubygems.org once ready.'
302
- end
303
-
304
- private
305
-
306
- def write(file, content)
307
- File.write file, content
308
- file_path = File.expand_path(file)
309
- puts "Created #{current_dir_name}/#{file}"
310
- end
311
-
312
- def append(file, content)
313
- File.open(file, 'a') do |f|
314
- f.write(content)
315
- end
316
- end
317
-
318
- def current_dir_name
319
- File.basename(File.expand_path('.'))
320
- end
321
-
322
- def class_name(app_name)
323
- app_name.underscore.camelcase(:upper)
324
- end
325
-
326
- def file_name(app_name)
327
- app_name.underscore
328
- end
329
- alias dsl_widget_name file_name
330
-
331
- def human_name(app_name)
332
- app_name.underscore.titlecase
333
- end
334
-
335
- def compact_name(gem_name)
336
- gem_name.underscore.camelcase.downcase
337
- end
338
-
339
- def app_main_file(app_name)
340
- <<~MULTI_LINE_STRING
341
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
342
-
343
- require 'bundler/setup'
344
- Bundler.require(:default)
345
- require 'views/#{file_name(app_name)}/app_view'
346
-
347
- class #{class_name(app_name)}
348
- include Glimmer
349
-
350
- APP_ROOT = File.expand_path('../..', __FILE__)
351
- VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
352
- LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
353
-
354
- def open
355
- app_view.open
356
- end
357
- end
358
- MULTI_LINE_STRING
359
- end
360
-
361
- def gem_main_file(custom_widget_name, namespace = nil)
362
- custom_widget_file_path = "views"
363
- custom_widget_file_path += "/#{file_name(namespace)}" if namespace
364
- custom_widget_file_path += "/#{file_name(custom_widget_name)}"
365
-
366
- <<~MULTI_LINE_STRING
367
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
368
-
369
- require 'glimmer-dsl-swt'
370
- require '#{custom_widget_file_path}'
371
- MULTI_LINE_STRING
372
- end
373
-
374
- def app_bin_file(app_name)
375
- <<~MULTI_LINE_STRING
376
- require_relative '../app/#{file_name(app_name)}'
377
-
378
- #{class_name(app_name)}.new.open
379
- MULTI_LINE_STRING
380
- end
381
-
382
- def gem_bin_file(gem_name, custom_shell_name, namespace)
383
- # TODO change this so that it does not mix Glimmer unto the main object
384
- <<~MULTI_LINE_STRING
385
- require_relative '../lib/#{gem_name}'
386
-
387
- class #{class_name(custom_shell_name)}App
388
- include Glimmer
389
-
390
- def open
391
- #{dsl_widget_name(custom_shell_name)}.open
392
- end
393
- end
394
-
395
- #{class_name(custom_shell_name)}App.new.open
396
- MULTI_LINE_STRING
397
- end
398
-
399
- def gem_bin_command_file(gem_name)
400
- <<~MULTI_LINE_STRING
401
- #!/usr/bin/env jruby
402
-
403
- require 'glimmer/launcher'
404
-
405
- runner = File.expand_path("../#{gem_name}", __FILE__)
406
- launcher = Glimmer::Launcher.new([runner] + ARGV)
407
- launcher.launch
408
- MULTI_LINE_STRING
409
- end
410
-
411
- def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
412
- rakefile_content = File.read('Rakefile')
413
- lines = rakefile_content.split("\n")
414
- require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
415
- lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
416
- gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
417
- if custom_shell_name
418
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
419
- lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
420
- lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
421
- else
422
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
423
- end
424
- spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
425
- lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_os_specific_options]")
426
- lines << "\nrequire 'glimmer/rake_task'\n"
427
- file_content = lines.join("\n")
428
- if custom_shell_name
429
- file_content << <<~MULTI_LINE_STRING
430
- Glimmer::Package.javapackager_extra_args =
431
- " -name '#{human_name(custom_shell_name)}'" +
432
- " -title '#{human_name(custom_shell_name)}'" +
433
- " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
434
- " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).capitalize}'"
435
- # " -BlicenseType=" +
436
- # " -Bmac.category=" +
437
- # " -Bmac.signing-key-developer-id-app="
438
- MULTI_LINE_STRING
439
- end
440
- file_content
441
- end
442
-
443
- def spec_helper_file
444
- content = File.read('spec/spec_helper.rb')
445
- lines = content.split("\n")
446
- require_line_index = lines.index(lines.detect {|l| l.include?(current_dir_name) })
447
- lines[require_line_index..require_line_index] = [
448
- "require 'bundler/setup'",
449
- 'Bundler.require(:default, :development)',
450
- ]
451
- configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
452
- lines[configure_block_line_index...configure_block_line_index] = [
453
- ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
454
- ' config.after do',
455
- ' @target.dispose if @target && @target.respond_to?(:dispose)',
456
- ' Glimmer::DSL::Engine.reset',
457
- ' end',
458
- ]
459
-
460
- lines << "\nrequire 'glimmer/rake_task'\n"
461
- lines.join("\n")
462
- end
463
-
464
- def custom_shell_file(custom_shell_name, namespace, shell_type)
465
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
466
-
467
- custom_shell_file_content = <<-MULTI_LINE_STRING
468
- #{namespace_type} #{class_name(namespace)}
469
- class #{class_name(custom_shell_name)}
470
- include Glimmer::UI::CustomShell
471
-
472
- MULTI_LINE_STRING
473
-
474
- if shell_type == :gem
475
- custom_shell_file_content += <<-MULTI_LINE_STRING
476
- APP_ROOT = File.expand_path('../../../..', __FILE__)
477
- VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
478
- LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
479
-
480
- MULTI_LINE_STRING
481
- end
482
-
483
- custom_shell_file_content += <<-MULTI_LINE_STRING
484
- ## Add options like the following to configure CustomShell by outside consumers
485
- #
486
- # options :title, :background_color
487
- # option :width, default: 320
488
- # option :height, default: 240
489
- option :greeting, default: 'Hello, World!'
490
-
491
- ## Use before_body block to pre-initialize variables to use in body
492
- #
493
- #
494
- MULTI_LINE_STRING
495
-
496
- if %i[gem app].include?(shell_type)
497
- custom_shell_file_content += <<-MULTI_LINE_STRING
498
- before_body {
499
- Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
500
- Display.setAppVersion(VERSION)
501
- @display = display {
502
- on_about {
503
- display_about_dialog
504
- }
505
- on_preferences {
506
- display_preferences_dialog
507
- }
508
- }
509
- }
510
- MULTI_LINE_STRING
511
- else
512
- custom_shell_file_content += <<-MULTI_LINE_STRING
513
- # before_body {
514
- #
515
- # }
516
- MULTI_LINE_STRING
517
- end
518
-
519
- custom_shell_file_content += <<-MULTI_LINE_STRING
520
-
521
- ## Use after_body block to setup observers for widgets in body
522
- #
523
- # after_body {
524
- #
525
- # }
526
-
527
- ## Add widget content inside custom shell body
528
- ## Top-most widget must be a shell or another custom shell
529
- #
530
- body {
531
- shell {
532
- # Replace example content below with custom shell content
533
- minimum_size 320, 240
534
- image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
535
- text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
536
- grid_layout
537
- label(:center) {
538
- text bind(self, :greeting)
539
- font height: 40
540
- layout_data :fill, :center, true, true
541
- }
542
- menu_bar {
543
- menu {
544
- text '&File'
545
- menu_item {
546
- text '&Preferences...'
547
- on_widget_selected {
548
- display_preferences_dialog
549
- }
550
- }
551
- }
552
- }
553
- }
554
- }
555
- MULTI_LINE_STRING
556
-
557
- if %i[gem app].include?(shell_type)
558
- custom_shell_file_content += <<-MULTI_LINE_STRING
559
-
560
- def display_about_dialog
561
- message_box(body_root) {
562
- text 'About'
563
- message "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\\n\\n\#{LICENSE}"
564
- }.open
565
- end
566
-
567
- def display_preferences_dialog
568
- dialog(swt_widget) {
569
- text 'Preferences'
570
- grid_layout {
571
- margin_height 5
572
- margin_width 5
573
- }
574
- group {
575
- row_layout {
576
- type :vertical
577
- spacing 10
578
- }
579
- text 'Greeting'
580
- font style: :bold
581
- [
582
- 'Hello, World!',
583
- 'Howdy, Partner!'
584
- ].each do |greeting_text|
585
- button(:radio) {
586
- text greeting_text
587
- selection bind(self, :greeting) { |g| g == greeting_text }
588
- layout_data {
589
- width 160
590
- }
591
- on_widget_selected { |event|
592
- self.greeting = event.widget.getText
593
- }
594
- }
595
- end
596
- }
597
- }.open
598
- end
599
- MULTI_LINE_STRING
600
- end
601
-
602
- custom_shell_file_content += <<-MULTI_LINE_STRING
603
- end
604
- end
605
- MULTI_LINE_STRING
606
- end
607
-
608
- def custom_widget_file(custom_widget_name, namespace)
609
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
610
-
611
- <<~MULTI_LINE_STRING
612
- #{namespace_type} #{class_name(namespace)}
613
- class #{class_name(custom_widget_name)}
614
- include Glimmer::UI::CustomWidget
615
-
616
- ## Add options like the following to configure CustomWidget by outside consumers
617
- #
618
- # options :custom_text, :background_color
619
- # option :foreground_color, default: :red
620
-
621
- ## Use before_body block to pre-initialize variables to use in body
622
- #
623
- #
624
- # before_body {
625
- #
626
- # }
627
-
628
- ## Use after_body block to setup observers for widgets in body
629
- #
630
- # after_body {
631
- #
632
- # }
633
-
634
- ## Add widget content under custom widget body
635
- ##
636
- ## If you want to add a shell as the top-most widget,
637
- ## consider creating a custom shell instead
638
- ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
639
- #
640
- body {
641
- # Replace example content below with custom widget content
642
- label {
643
- background :red
644
- }
645
- }
646
-
647
- end
648
- end
649
- MULTI_LINE_STRING
650
- end
651
- end
652
- end