glimmer 0.7.8 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +232 -108
  4. data/VERSION +1 -1
  5. data/lib/glimmer.rb +1 -20
  6. data/lib/glimmer/config.rb +0 -13
  7. data/lib/glimmer/dsl/engine.rb +33 -18
  8. data/lib/glimmer/dsl/expression.rb +0 -7
  9. data/lib/glimmer/dsl/static_expression.rb +2 -2
  10. metadata +48 -172
  11. data/RUBY_VERSION +0 -1
  12. data/bin/girb +0 -10
  13. data/bin/girb_runner.rb +0 -13
  14. data/bin/glimmer +0 -5
  15. data/icons/scaffold_app.icns +0 -0
  16. data/lib/glimmer/css/rule.rb +0 -25
  17. data/lib/glimmer/css/style_sheet.rb +0 -19
  18. data/lib/glimmer/data_binding/list_selection_binding.rb +0 -52
  19. data/lib/glimmer/data_binding/model_binding.rb +0 -248
  20. data/lib/glimmer/data_binding/observable.rb +0 -21
  21. data/lib/glimmer/data_binding/observable_array.rb +0 -107
  22. data/lib/glimmer/data_binding/observable_model.rb +0 -108
  23. data/lib/glimmer/data_binding/observable_widget.rb +0 -17
  24. data/lib/glimmer/data_binding/observer.rb +0 -124
  25. data/lib/glimmer/data_binding/shine.rb +0 -23
  26. data/lib/glimmer/data_binding/table_items_binding.rb +0 -47
  27. data/lib/glimmer/data_binding/tree_items_binding.rb +0 -71
  28. data/lib/glimmer/data_binding/widget_binding.rb +0 -33
  29. data/lib/glimmer/dsl/css/css_expression.rb +0 -21
  30. data/lib/glimmer/dsl/css/dsl.rb +0 -10
  31. data/lib/glimmer/dsl/css/dynamic_property_expression.rb +0 -12
  32. data/lib/glimmer/dsl/css/property_expression.rb +0 -22
  33. data/lib/glimmer/dsl/css/pv_expression.rb +0 -17
  34. data/lib/glimmer/dsl/css/rule_expression.rb +0 -25
  35. data/lib/glimmer/dsl/css/s_expression.rb +0 -26
  36. data/lib/glimmer/dsl/swt/async_exec_expression.rb +0 -14
  37. data/lib/glimmer/dsl/swt/bind_expression.rb +0 -37
  38. data/lib/glimmer/dsl/swt/color_expression.rb +0 -19
  39. data/lib/glimmer/dsl/swt/column_properties_expression.rb +0 -24
  40. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +0 -42
  41. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +0 -36
  42. data/lib/glimmer/dsl/swt/data_binding_expression.rb +0 -34
  43. data/lib/glimmer/dsl/swt/dialog_expression.rb +0 -26
  44. data/lib/glimmer/dsl/swt/display_expression.rb +0 -19
  45. data/lib/glimmer/dsl/swt/dsl.rb +0 -28
  46. data/lib/glimmer/dsl/swt/exec_expression.rb +0 -28
  47. data/lib/glimmer/dsl/swt/layout_data_expression.rb +0 -25
  48. data/lib/glimmer/dsl/swt/layout_expression.rb +0 -27
  49. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +0 -44
  50. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +0 -33
  51. data/lib/glimmer/dsl/swt/menu_expression.rb +0 -32
  52. data/lib/glimmer/dsl/swt/observe_expression.rb +0 -32
  53. data/lib/glimmer/dsl/swt/property_expression.rb +0 -22
  54. data/lib/glimmer/dsl/swt/rgb_expression.rb +0 -12
  55. data/lib/glimmer/dsl/swt/rgba_expression.rb +0 -12
  56. data/lib/glimmer/dsl/swt/shell_expression.rb +0 -25
  57. data/lib/glimmer/dsl/swt/swt_expression.rb +0 -25
  58. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +0 -15
  59. data/lib/glimmer/dsl/swt/tab_item_expression.rb +0 -33
  60. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +0 -31
  61. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +0 -31
  62. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +0 -26
  63. data/lib/glimmer/dsl/swt/widget_expression.rb +0 -34
  64. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +0 -32
  65. data/lib/glimmer/dsl/xml/dsl.rb +0 -11
  66. data/lib/glimmer/dsl/xml/html_expression.rb +0 -25
  67. data/lib/glimmer/dsl/xml/meta_expression.rb +0 -23
  68. data/lib/glimmer/dsl/xml/name_space_expression.rb +0 -37
  69. data/lib/glimmer/dsl/xml/node_parent_expression.rb +0 -33
  70. data/lib/glimmer/dsl/xml/tag_expression.rb +0 -29
  71. data/lib/glimmer/dsl/xml/text_expression.rb +0 -22
  72. data/lib/glimmer/dsl/xml/xml_expression.rb +0 -21
  73. data/lib/glimmer/launcher.rb +0 -199
  74. data/lib/glimmer/package.rb +0 -7
  75. data/lib/glimmer/rake_task.rb +0 -89
  76. data/lib/glimmer/scaffold.rb +0 -588
  77. data/lib/glimmer/swt/color_proxy.rb +0 -53
  78. data/lib/glimmer/swt/display_proxy.rb +0 -74
  79. data/lib/glimmer/swt/font_proxy.rb +0 -72
  80. data/lib/glimmer/swt/layout_data_proxy.rb +0 -84
  81. data/lib/glimmer/swt/layout_proxy.rb +0 -82
  82. data/lib/glimmer/swt/menu_proxy.rb +0 -84
  83. data/lib/glimmer/swt/packages.rb +0 -13
  84. data/lib/glimmer/swt/shell_proxy.rb +0 -170
  85. data/lib/glimmer/swt/swt_proxy.rb +0 -106
  86. data/lib/glimmer/swt/tab_item_proxy.rb +0 -65
  87. data/lib/glimmer/swt/tree_proxy.rb +0 -120
  88. data/lib/glimmer/swt/widget_listener_proxy.rb +0 -34
  89. data/lib/glimmer/swt/widget_proxy.rb +0 -489
  90. data/lib/glimmer/ui/custom_shell.rb +0 -45
  91. data/lib/glimmer/ui/custom_widget.rb +0 -244
  92. data/lib/glimmer/util/proc_tracker.rb +0 -16
  93. data/lib/glimmer/xml/depth_first_search_iterator.rb +0 -22
  94. data/lib/glimmer/xml/name_space_visitor.rb +0 -21
  95. data/lib/glimmer/xml/node.rb +0 -75
  96. data/lib/glimmer/xml/node_visitor.rb +0 -13
  97. data/lib/glimmer/xml/xml_visitor.rb +0 -65
  98. data/vendor/swt/linux/swt.jar +0 -0
  99. data/vendor/swt/mac/swt.jar +0 -0
  100. data/vendor/swt/windows/swt.jar +0 -0
@@ -1,7 +0,0 @@
1
- module Glimmer
2
- module Package
3
- class << self
4
- attr_accessor :javapackager_extra_args
5
- end
6
- end
7
- end
@@ -1,89 +0,0 @@
1
- require 'rake'
2
-
3
- require_relative 'package'
4
- require_relative 'scaffold'
5
-
6
- namespace :glimmer do
7
- namespace :package do
8
- desc 'Generate JAR config file'
9
- task :config do
10
- project_name = File.basename(File.expand_path('.'))
11
- if !File.exists?('config/warble.rb')
12
- puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
13
- system('mkdir -p config')
14
- system('warble config')
15
- new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
16
- if line.include?('config.dirs =')
17
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos)')
18
- end
19
- if line.include?('config.includes =')
20
- line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
21
- end
22
- if line.include?('config.autodeploy_dir =')
23
- line = line.sub('# ', '')
24
- end
25
- output + "\n" + line
26
- end
27
- File.write('config/warble.rb', new_config)
28
- end
29
- end
30
-
31
- desc 'Generate JAR file'
32
- task :jar => 'package:config' do
33
- system('mkdir -p dist')
34
- puts "Generating JAR with Warbler..."
35
- system('warble')
36
- end
37
-
38
- desc 'Generate Native files (DMG/PKG/APP on the Mac)'
39
- task :native => 'package:jar' do
40
- require 'facets/string/titlecase'
41
- require 'facets/string/underscore'
42
- project_name = File.basename(File.expand_path('.'))
43
- version_file = File.expand_path('./VERSION')
44
- version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
45
- license_file = File.expand_path('./LICENSE.txt')
46
- license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
47
- human_name = project_name.underscore.titlecase
48
- command = "javapackager -deploy -native -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -BjvmOptions=-XstartOnFirstThread -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" "
49
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
50
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
51
- command += " #{Glimmer::Package.javapackager_extra_args} " if Glimmer::Package.javapackager_extra_args
52
- command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
53
- puts "Generating DMG/PKG/APP/JNLP with javapackager..."
54
- puts command
55
- system command
56
- end
57
- end
58
-
59
- desc 'Package app for distribution (generating config, jar, and native files)'
60
- task :package => 'package:native'
61
-
62
-
63
- desc 'Scaffold a Glimmer application directory structure to begin building a new app'
64
- task :scaffold, [:app_name] do |t, args|
65
- Scaffold.app(args[:app_name])
66
- end
67
-
68
- namespace :scaffold do
69
- desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under app/views (namespace is optional)'
70
- task :custom_shell, [:custom_shell_name, :namespace] do |t, args|
71
- Scaffold.custom_shell(args[:custom_shell_name], args[:namespace])
72
- end
73
-
74
- desc 'Scaffold a Glimmer::UI::CustomWidget subclass (represents a part of a view) under app/views (namespace is optional)'
75
- task :custom_widget, [:custom_widget_name, :namespace] do |t, args|
76
- Scaffold.custom_widget(args[:custom_widget_name], args[:namespace])
77
- end
78
-
79
- desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under its own Ruby gem + app project (namespace is required)'
80
- task :custom_shell_gem, [:custom_shell_name, :namespace] do |t, args|
81
- Scaffold.custom_shell_gem(args[:custom_shell_name], args[:namespace])
82
- end
83
-
84
- desc 'Scaffold a Glimmer::UI::CustomWidget subclass (represents a part of a view) under its own Ruby gem project (namespace is required)'
85
- task :custom_widget_gem, [:custom_widget_name, :namespace] do |t, args|
86
- Scaffold.custom_widget_gem(args[:custom_widget_name], args[:namespace])
87
- end
88
- end
89
- end
@@ -1,588 +0,0 @@
1
- require 'fileutils'
2
- require 'os'
3
- require 'facets'
4
-
5
- class Scaffold
6
- class << self
7
- include FileUtils
8
-
9
- VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
10
- RUBY_VERSION = File.read(File.expand_path('../../../RUBY_VERSION', __FILE__)).strip
11
-
12
- # TODO externalize all constants into scaffold/files
13
-
14
- GITIGNORE = <<~MULTI_LINE_STRING
15
- *.gem
16
- *.rbc
17
- /.config
18
- /coverage/
19
- /InstalledFiles
20
- /pkg/
21
- /spec/reports/
22
- /spec/examples.txt
23
- /test/tmp/
24
- /test/version_tmp/
25
- /tmp/
26
-
27
- # Used by dotenv library to load environment variables.
28
- # .env
29
-
30
- ## Specific to RubyMotion:
31
- .dat*
32
- .repl_history
33
- build/
34
- *.bridgesupport
35
- build-iPhoneOS/
36
- build-iPhoneSimulator/
37
-
38
- ## Specific to RubyMotion (use of CocoaPods):
39
- #
40
- # We recommend against adding the Pods directory to your .gitignore. However
41
- # you should judge for yourself, the pros and cons are mentioned at:
42
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
43
- #
44
- # vendor/Pods/
45
-
46
- ## Documentation cache and generated files:
47
- /.yardoc/
48
- /_yardoc/
49
- /doc/
50
- /rdoc/
51
-
52
- ## Environment normalization:
53
- /.bundle/
54
- /vendor/bundle
55
- /lib/bundler/man/
56
-
57
- # for a library or gem, you might want to ignore these files since the code is
58
- # intended to run in multiple environments; otherwise, check them in:
59
- Gemfile.lock
60
- # .ruby-version
61
- # .ruby-gemset
62
-
63
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
64
- .rvmrc
65
-
66
- # Mac
67
- .DS_Store
68
-
69
- # Gladiator (Glimmer Editor)
70
- .gladiator
71
-
72
- # Glimmer
73
- dist
74
- packages
75
- MULTI_LINE_STRING
76
-
77
- GEMFILE_APP = <<~MULTI_LINE_STRING
78
- # frozen_string_literal: true
79
-
80
- source 'https://rubygems.org'
81
-
82
- git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
83
-
84
- gem 'glimmer', '~> #{VERSION}'
85
-
86
- group :test do
87
- gem 'rspec'
88
- end
89
- MULTI_LINE_STRING
90
-
91
- GEMFILE_GEM = <<~MULTI_LINE_STRING
92
- # frozen_string_literal: true
93
-
94
- source 'https://rubygems.org'
95
-
96
- git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
97
-
98
- gem 'glimmer', '~> #{VERSION}'
99
-
100
- group :development do
101
- gem 'rspec', '~> 3.5.0'
102
- gem 'jeweler', '2.3.9'
103
- gem 'simplecov', '>= 0'
104
- end
105
- MULTI_LINE_STRING
106
-
107
- RAKEFILE = <<~MULTI_LINE_STRING
108
- require 'glimmer/rake_task'
109
-
110
- ## Use the following configuration if you would like to customize javapackager
111
- ## arguments for `glimmer package` command.
112
- #
113
- # Glimmer::Package.javapackager_extra_args =
114
- # " -BlicenseType=" +
115
- # " -Bmac.CFBundleIdentifier=" +
116
- # " -Bmac.category=" +
117
- # " -Bmac.signing-key-developer-id-app="
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
- mkdir app_name
137
- cd app_name
138
- write '.gitignore', GITIGNORE
139
- write '.ruby-version', RUBY_VERSION
140
- write '.ruby-gemset', app_name
141
- write 'VERSION', '1.0.0'
142
- write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
143
- write 'Gemfile', GEMFILE_APP
144
- write 'Rakefile', RAKEFILE
145
- mkdir 'app'
146
- write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
147
- mkdir 'app/models'
148
- mkdir 'app/views'
149
- custom_shell('AppView', current_dir_name, :app)
150
- if OS.mac?
151
- mkdir_p 'package/macosx'
152
- icon_file = "package/macosx/#{human_name(app_name)}.icns"
153
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
154
- puts "Created #{current_dir_name}/#{icon_file}"
155
- end
156
- mkdir 'bin'
157
- write "bin/#{file_name(app_name)}", app_bin_file(app_name)
158
- FileUtils.chmod 0755, "bin/#{file_name(app_name)}"
159
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
160
- system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
161
- # TODO generate rspec test suite
162
- end
163
-
164
- def custom_shell(custom_shell_name, namespace, shell_type = nil)
165
- namespace ||= current_dir_name
166
- root_dir = File.exists?('app') ? 'app' : 'lib'
167
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
168
- mkdir_p parent_dir unless File.exists?(parent_dir)
169
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
170
- end
171
-
172
- def custom_widget(custom_widget_name, namespace)
173
- namespace ||= current_dir_name
174
- root_dir = File.exists?('app') ? 'app' : 'lib'
175
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
176
- mkdir_p parent_dir unless File.exists?(parent_dir)
177
- write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
178
- end
179
-
180
- def custom_shell_gem(custom_shell_name, namespace)
181
- gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
182
- gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
183
- if namespace
184
- gem_name += "-#{compact_name(namespace)}"
185
- gem_summary += " (#{human_name(namespace)})"
186
- else
187
- namespace = 'glimmer'
188
- end
189
- system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
190
- cd gem_name
191
- write '.gitignore', GITIGNORE
192
- write '.ruby-version', RUBY_VERSION
193
- write '.ruby-gemset', gem_name
194
- write 'VERSION', '1.0.0'
195
- write 'Gemfile', GEMFILE_GEM
196
- write 'Rakefile', gem_rakefile(custom_shell_name, namespace)
197
- append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
198
- mkdir 'lib/views'
199
- custom_shell(custom_shell_name, namespace, :gem)
200
- mkdir 'bin'
201
- write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
202
- write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
203
- FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
204
- if OS.mac?
205
- mkdir_p 'package/macosx'
206
- icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
207
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
208
- puts "Created #{current_dir_name}/#{icon_file}"
209
- end
210
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
211
- system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app"
212
- puts "Finished creating #{gem_name} Ruby gem."
213
- puts 'Edit Rakefile to configure gem details.'
214
- puts 'Run `rake` to execute specs.'
215
- puts 'Run `rake build` to build gem.'
216
- puts 'Run `rake release` to release into rubygems.org once ready.'
217
- end
218
-
219
- def custom_widget_gem(custom_widget_name, namespace)
220
- gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
221
- gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
222
- if namespace
223
- gem_name += "-#{compact_name(namespace)}"
224
- gem_summary += " (#{human_name(namespace)})"
225
- else
226
- namespace = 'glimmer'
227
- end
228
- system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
229
- cd gem_name
230
- write '.gitignore', GITIGNORE
231
- write '.ruby-version', RUBY_VERSION
232
- write '.ruby-gemset', gem_name
233
- write 'VERSION', '1.0.0'
234
- write 'Gemfile', GEMFILE_GEM
235
- write 'Rakefile', gem_rakefile
236
- write 'spec/spec_helper.rb', spec_helper_file
237
- append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
238
- mkdir 'lib/views'
239
- custom_widget(custom_widget_name, namespace)
240
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
241
- puts "Finished creating #{gem_name} Ruby gem."
242
- puts 'Edit Rakefile to configure gem details.'
243
- puts 'Run `rake` to execute specs.'
244
- puts 'Run `rake build` to build gem.'
245
- puts 'Run `rake release` to release into rubygems.org once ready.'
246
- end
247
-
248
- private
249
-
250
- def write(file, content)
251
- File.write file, content
252
- file_path = File.expand_path(file)
253
- puts "Created #{current_dir_name}/#{file}"
254
- end
255
-
256
- def append(file, content)
257
- File.open(file, 'a') do |f|
258
- f.write(content)
259
- end
260
- end
261
-
262
- def current_dir_name
263
- File.basename(File.expand_path('.'))
264
- end
265
-
266
- def class_name(app_name)
267
- app_name.underscore.camelcase(:upper)
268
- end
269
-
270
- def file_name(app_name)
271
- app_name.underscore
272
- end
273
- alias dsl_widget_name file_name
274
-
275
- def human_name(app_name)
276
- app_name.underscore.titlecase
277
- end
278
-
279
- def compact_name(gem_name)
280
- gem_name.underscore.camelcase.downcase
281
- end
282
-
283
- def app_main_file(app_name)
284
- <<~MULTI_LINE_STRING
285
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
286
-
287
- require 'bundler/setup'
288
- Bundler.require(:default)
289
- require 'views/#{file_name(app_name)}/app_view'
290
-
291
- class #{class_name(app_name)}
292
- include Glimmer
293
-
294
- APP_ROOT = File.expand_path('../..', __FILE__)
295
- VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
296
- LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
297
-
298
- def open
299
- app_view.open
300
- end
301
- end
302
- MULTI_LINE_STRING
303
- end
304
-
305
- def gem_main_file(custom_widget_name, namespace = nil)
306
- custom_widget_file_path = "views"
307
- custom_widget_file_path += "/#{file_name(namespace)}" if namespace
308
- custom_widget_file_path += "/#{file_name(custom_widget_name)}"
309
-
310
- <<~MULTI_LINE_STRING
311
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
312
-
313
- require 'glimmer'
314
- require '#{custom_widget_file_path}'
315
- MULTI_LINE_STRING
316
- end
317
-
318
- def app_bin_file(app_name)
319
- <<~MULTI_LINE_STRING
320
- #!/usr/bin/env ruby
321
-
322
- require_relative '../app/#{file_name(app_name)}'
323
-
324
- #{class_name(app_name)}.new.open
325
- MULTI_LINE_STRING
326
- end
327
-
328
- def gem_bin_file(gem_name, custom_shell_name, namespace)
329
- <<~MULTI_LINE_STRING
330
- #!/usr/bin/env ruby
331
-
332
- require_relative '../lib/#{gem_name}'
333
-
334
- include Glimmer
335
-
336
- #{dsl_widget_name(custom_shell_name)}.open
337
- MULTI_LINE_STRING
338
- end
339
-
340
- def gem_bin_command_file(gem_name)
341
- <<~MULTI_LINE_STRING
342
- #!/usr/bin/env ruby
343
-
344
- require 'glimmer/launcher'
345
-
346
- runner = File.expand_path("../#{gem_name}", __FILE__)
347
- launcher = Glimmer::Launcher.new([runner] + ARGV)
348
- launcher.launch
349
- MULTI_LINE_STRING
350
- end
351
-
352
- def gem_rakefile(custom_shell_name = nil, namespace = nil)
353
- rakefile_content = File.read('Rakefile')
354
- lines = rakefile_content.split("\n")
355
- require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
356
- lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
357
- gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
358
- if custom_shell_name
359
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*.rb', 'bin/**/*']")
360
- lines.insert(gem_files_line_index+1, " gem.executables = ['#{file_name(custom_shell_name)}']")
361
- else
362
- lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
363
- end
364
- spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
365
- lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
366
- lines << "\nrequire 'glimmer/rake_task'\n"
367
- file_content = lines.join("\n")
368
- if custom_shell_name
369
- file_content << <<~MULTI_LINE_STRING
370
- Glimmer::Package.javapackager_extra_args =
371
- " -name '#{human_name(custom_shell_name)}'" +
372
- " -title '#{human_name(custom_shell_name)}'" +
373
- " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
374
- " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name)}'"
375
- # " -BlicenseType=" +
376
- # " -Bmac.category=" +
377
- # " -Bmac.signing-key-developer-id-app="
378
- MULTI_LINE_STRING
379
- end
380
- file_content
381
- end
382
-
383
- def spec_helper_file
384
- content = File.read('spec/spec_helper.rb')
385
- lines = content.split("\n")
386
- require_line_index = lines.index(lines.detect {|l| l.include?(current_dir_name) })
387
- lines[require_line_index...require_line_index] = [
388
- "require 'bundler/setup'",
389
- 'Bundler.require(:default, :development)',
390
- ]
391
- configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
392
- lines[configure_block_line_index...configure_block_line_index] = [
393
- ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
394
- ' config.after do',
395
- ' @target.dispose if @target && @target.respond_to?(:dispose)',
396
- ' Glimmer::DSL::Engine.reset',
397
- ' end',
398
- ]
399
-
400
- lines << "\nrequire 'glimmer/rake_task'\n"
401
- lines.join("\n")
402
- end
403
-
404
- def custom_shell_file(custom_shell_name, namespace, shell_type)
405
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
406
-
407
- custom_shell_file_content = <<-MULTI_LINE_STRING
408
- #{namespace_type} #{class_name(namespace)}
409
- class #{class_name(custom_shell_name)}
410
- include Glimmer::UI::CustomShell
411
-
412
- MULTI_LINE_STRING
413
-
414
- if shell_type == :gem
415
- custom_shell_file_content += <<-MULTI_LINE_STRING
416
- GEM_ROOT = File.expand_path('../../../..', __FILE__)
417
- VERSION = File.read(File.join(GEM_ROOT, 'VERSION'))
418
- LICENSE = File.read(File.join(GEM_ROOT, 'LICENSE.txt'))
419
-
420
- MULTI_LINE_STRING
421
- end
422
-
423
- custom_shell_file_content += <<-MULTI_LINE_STRING
424
- ## Add options like the following to configure CustomShell by outside consumers
425
- #
426
- # options :title, :background_color
427
- # option :width, 320
428
- # option :height, 240
429
- option :greeting, 'Hello, World!'
430
-
431
- ## Use before_body block to pre-initialize variables to use in body
432
- #
433
- #
434
- MULTI_LINE_STRING
435
-
436
- if %i[gem app].include?(shell_type)
437
- custom_shell_file_content += <<-MULTI_LINE_STRING
438
- before_body {
439
- Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
440
- Display.setAppVersion(VERSION)
441
- }
442
- MULTI_LINE_STRING
443
- else
444
- custom_shell_file_content += <<-MULTI_LINE_STRING
445
- # before_body {
446
- #
447
- # }
448
- MULTI_LINE_STRING
449
- end
450
-
451
- custom_shell_file_content += <<-MULTI_LINE_STRING
452
-
453
- ## Use after_body block to setup observers for widgets in body
454
- #
455
- # after_body {
456
- #
457
- # }
458
-
459
- ## Add widget content inside custom shell body
460
- ## Top-most widget must be a shell or another custom shell
461
- #
462
- body {
463
- shell {
464
- # Replace example content below with custom shell content
465
- minimum_size 320, 240
466
- text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
467
- grid_layout
468
- MULTI_LINE_STRING
469
-
470
- if %i[gem app].include?(shell_type)
471
- custom_shell_file_content += <<-MULTI_LINE_STRING
472
- on_about {
473
- display_about_dialog
474
- }
475
- on_preferences {
476
- display_preferences_dialog
477
- }
478
- MULTI_LINE_STRING
479
- end
480
-
481
- custom_shell_file_content += <<-MULTI_LINE_STRING
482
- label(:center) {
483
- text bind(self, :greeting)
484
- font height: 40
485
- layout_data :fill, :center, true, true
486
- }
487
- }
488
- }
489
- MULTI_LINE_STRING
490
-
491
- if %i[gem app].include?(shell_type)
492
- custom_shell_file_content += <<-MULTI_LINE_STRING
493
-
494
- def display_about_dialog
495
- message_box = MessageBox.new(swt_widget)
496
- message_box.setText("About")
497
- message = "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\n\n"
498
- message += LICENSE
499
- message_box.setMessage(message)
500
- message_box.open
501
- end
502
-
503
- def display_preferences_dialog
504
- dialog(swt_widget) {
505
- text 'Preferences'
506
- grid_layout {
507
- margin_height 5
508
- margin_width 5
509
- }
510
- group {
511
- row_layout {
512
- type :vertical
513
- spacing 10
514
- }
515
- text 'Greeting'
516
- font style: :bold
517
- [
518
- 'Hello, World!',
519
- 'Howdy, Partner!'
520
- ].each do |greeting_text|
521
- button(:radio) {
522
- text greeting_text
523
- selection bind(self, :greeting) { |g| g == greeting_text }
524
- layout_data {
525
- width 160
526
- }
527
- on_widget_selected { |event|
528
- self.greeting = event.widget.getText
529
- }
530
- }
531
- end
532
- }
533
- }.open
534
- end
535
- MULTI_LINE_STRING
536
- end
537
-
538
- custom_shell_file_content += <<-MULTI_LINE_STRING
539
- end
540
- end
541
- MULTI_LINE_STRING
542
- end
543
-
544
- def custom_widget_file(custom_widget_name, namespace)
545
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
546
-
547
- <<~MULTI_LINE_STRING
548
- #{namespace_type} #{class_name(namespace)}
549
- class #{class_name(custom_widget_name)}
550
- include Glimmer::UI::CustomWidget
551
-
552
- ## Add options like the following to configure CustomWidget by outside consumers
553
- #
554
- # options :custom_text, :background_color
555
- # option :foreground_color, :red
556
-
557
- ## Use before_body block to pre-initialize variables to use in body
558
- #
559
- #
560
- # before_body {
561
- #
562
- # }
563
-
564
- ## Use after_body block to setup observers for widgets in body
565
- #
566
- # after_body {
567
- #
568
- # }
569
-
570
- ## Add widget content under custom widget body
571
- ##
572
- ## If you want to add a shell as the top-most widget,
573
- ## consider creating a custom shell instead
574
- ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
575
- #
576
- body {
577
- # Replace example content below with custom widget content
578
- label {
579
- background :red
580
- }
581
- }
582
-
583
- end
584
- end
585
- MULTI_LINE_STRING
586
- end
587
- end
588
- end