glimmer 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +212 -161
  3. data/RUBY_VERSION +1 -0
  4. data/VERSION +1 -0
  5. data/icons/scaffold_app.icns +0 -0
  6. data/lib/glimmer.rb +5 -47
  7. data/lib/glimmer/config.rb +35 -0
  8. data/lib/glimmer/css/{rule_set.rb → rule.rb} +3 -5
  9. data/lib/glimmer/css/style_sheet.rb +4 -5
  10. data/lib/glimmer/data_binding/observable_model.rb +1 -1
  11. data/lib/glimmer/dsl/css/dsl.rb +2 -2
  12. data/lib/glimmer/dsl/css/dynamic_property_expression.rb +12 -0
  13. data/lib/glimmer/dsl/css/property_expression.rb +3 -3
  14. data/lib/glimmer/dsl/css/pv_expression.rb +17 -0
  15. data/lib/glimmer/dsl/css/{rule_set_expression.rb → rule_expression.rb} +4 -4
  16. data/lib/glimmer/dsl/css/s_expression.rb +3 -3
  17. data/lib/glimmer/dsl/engine.rb +35 -5
  18. data/lib/glimmer/dsl/expression_handler.rb +3 -3
  19. data/lib/glimmer/dsl/swt/color_expression.rb +2 -0
  20. data/lib/glimmer/dsl/swt/dsl.rb +2 -0
  21. data/lib/glimmer/dsl/swt/tab_item_expression.rb +1 -1
  22. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +5 -5
  23. data/lib/glimmer/dsl/xml/name_space_expression.rb +1 -1
  24. data/lib/glimmer/launcher.rb +64 -19
  25. data/lib/glimmer/rake_task.rb +64 -23
  26. data/lib/glimmer/scaffold.rb +442 -0
  27. data/lib/glimmer/swt/layout_data_proxy.rb +1 -1
  28. data/lib/glimmer/swt/layout_proxy.rb +2 -2
  29. data/lib/glimmer/swt/swt_proxy.rb +3 -3
  30. data/lib/glimmer/swt/widget_proxy.rb +5 -5
  31. data/lib/glimmer/ui/custom_widget.rb +3 -3
  32. data/lib/glimmer/xml/node.rb +1 -1
  33. data/lib/glimmer/xml/xml_visitor.rb +2 -2
  34. metadata +16 -42
  35. data/bin/gladiator +0 -6
  36. data/lib/glimmer/dsl/css/p_expression.rb +0 -25
  37. data/lib/glimmer/ui/video.rb +0 -289
  38. data/samples/gladiator.rb +0 -765
@@ -1,25 +1,47 @@
1
1
  require 'os'
2
+ require 'rake'
3
+
4
+ require_relative 'rake_task'
2
5
 
3
6
  module Glimmer
4
7
  class Launcher
5
8
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
6
- TEXT_USAGE = <<-MULTILINE
7
- Usage: glimmer [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] application.rb [[application2.rb]...]
8
-
9
- Runs Glimmer applications using JRuby, automatically preloading
10
- the glimmer ruby gem and SWT jar dependency.
11
-
12
- Optionally, JRuby options may be passed in.
9
+
10
+ TEXT_USAGE_PREFIX = <<~MULTI_LINE_STRING
11
+ Usage: glimmer [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
12
+
13
+ Runs Glimmer applications/tasks.
14
+
15
+ Either a single task or one or more applications may be specified.
16
+
17
+ When a task is specified, it runs via rake. Some tasks take arguments in square brackets.
18
+
19
+ Available tasks are below (you may also lookup by adding `require 'glimmer/rake_task'` in Rakefile and running rake -T):
20
+ MULTI_LINE_STRING
21
+
22
+ TEXT_USAGE_SUFFIX = <<~MULTI_LINE_STRING
23
+
24
+ When applications are specified, they are run using JRuby,
25
+ automatically preloading the glimmer Ruby gem and SWT jar dependency.
26
+
27
+ Optionally, extra Glimmer options, JRuby options and environment variables may be passed in.
28
+
29
+ Glimmer options:
30
+ - "--debug" : Displays extra debugging information and passes "--debug" to JRuby
31
+ - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is "WARN")
32
+
33
+ Example: glimmer samples/hello_world.rb
34
+
35
+ This runs the Glimmer application samples/hello_world.rb
36
+ MULTI_LINE_STRING
13
37
 
14
- Example: glimmer samples/hello_world.rb
15
- This runs the Glimmer application samples/hello_world.rb
16
- MULTILINE
17
38
  GLIMMER_LIB_LOCAL = File.expand_path(File.join(__FILE__, '..', '..', 'glimmer.rb'))
18
39
  GLIMMER_LIB_GEM = 'glimmer'
19
40
  GLIMMER_OPTIONS = %w[--log-level]
20
41
  GLIMMER_OPTION_ENV_VAR_MAPPING = {
21
42
  '--log-level' => 'GLIMMER_LOGGER_LEVEL'
22
43
  }
44
+ REGEX_RAKE_TASK_WITH_ARGS = /^([^\[]+)\[?([^\]]*)\]?$/
23
45
 
24
46
  @@mutex = Mutex.new
25
47
 
@@ -44,7 +66,7 @@ module Glimmer
44
66
  @@mutex.synchronize do
45
67
  unless @glimmer_lib
46
68
  @glimmer_lib = GLIMMER_LIB_GEM
47
- glimmer_gem_listing = `jgem list #{GLIMMER_LIB_GEM}`
69
+ glimmer_gem_listing = `jgem list #{GLIMMER_LIB_GEM}`.split("\n").map {|l| l.split.first}
48
70
  if !glimmer_gem_listing.include?(GLIMMER_LIB_GEM) && File.exists?(GLIMMER_LIB_LOCAL)
49
71
  @glimmer_lib = GLIMMER_LIB_LOCAL
50
72
  puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})"
@@ -55,22 +77,43 @@ module Glimmer
55
77
  end
56
78
 
57
79
  def glimmer_option_env_vars(glimmer_options)
58
- glimmer_options.map do |k, v|
59
- "#{GLIMMER_OPTION_ENV_VAR_MAPPING[k]}=#{v}"
60
- end.join(' ')
80
+ glimmer_options.reduce({}) do |hash, pair|
81
+ hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => pair.last)
82
+ end
83
+ end
84
+
85
+ def load_env_vars(env_vars)
86
+ env_vars.each do |key, value|
87
+ ENV[key] = value
88
+ end
61
89
  end
62
90
 
63
91
  def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
64
92
  jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
93
+ env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
65
94
  env_vars_string = env_vars.map {|k,v| "#{k}=#{v}"}.join(' ')
66
- env_vars_string = [env_vars_string, glimmer_option_env_vars(glimmer_options)].join(' ')
67
95
  the_glimmer_lib = glimmer_lib
68
96
  devmode_require = nil
69
97
  if the_glimmer_lib == GLIMMER_LIB_LOCAL
70
98
  devmode_require = '-r puts_debuggerer '
71
99
  end
72
- puts "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}" if jruby_options_string.to_s.include?('--debug')
73
- system "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
100
+ rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')}
101
+ potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS)
102
+ application = potential_rake_task_parts[1]
103
+ rake_task_args = potential_rake_task_parts[2].split(',')
104
+ if rake_tasks.include?(application)
105
+ load_env_vars(glimmer_option_env_vars(glimmer_options))
106
+ rake_task = "glimmer:#{application}"
107
+ puts "Running Glimmer rake task: #{rake_task}" if jruby_options_string.to_s.include?('--debug')
108
+ Rake::Task[rake_task].invoke(*rake_task_args)
109
+ else
110
+ @@mutex.synchronize do
111
+ puts "Launching Glimmer Application: #{application}" unless application.to_s.match(/(irb)|(gladiator)/)
112
+ end
113
+ command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
114
+ puts command if jruby_options_string.to_s.include?('--debug')
115
+ system command
116
+ end
74
117
  end
75
118
  end
76
119
 
@@ -93,7 +136,6 @@ module Glimmer
93
136
 
94
137
  def launch_application
95
138
  threads = @application_paths.map do |application_path|
96
- puts "Launching Glimmer Application: #{application_path}" unless application_path.to_s.match(/(irb)|(gladiator)/)
97
139
  Thread.new do
98
140
  self.class.launch(
99
141
  application_path,
@@ -107,7 +149,10 @@ module Glimmer
107
149
  end
108
150
 
109
151
  def display_usage
110
- puts TEXT_USAGE
152
+ rake_tasks = `rake -T`.gsub('rake glimmer:', 'glimmer ').split("\n").select {|l| l.start_with?('glimmer ')}
153
+ puts TEXT_USAGE_PREFIX
154
+ puts rake_tasks.join("\n")
155
+ puts TEXT_USAGE_SUFFIX
111
156
  end
112
157
 
113
158
  def extract_application_paths(options)
@@ -1,4 +1,7 @@
1
- require 'glimmer/package'
1
+ require 'rake'
2
+
3
+ require_relative 'package'
4
+ require_relative 'scaffold'
2
5
 
3
6
  namespace :glimmer do
4
7
  namespace :package do
@@ -11,7 +14,10 @@ namespace :glimmer do
11
14
  system('warble config')
12
15
  new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
13
16
  if line.include?('config.dirs =')
14
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts images sounds videos)')
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']")
15
21
  end
16
22
  if line.include?('config.autodeploy_dir =')
17
23
  line = line.sub('# ', '')
@@ -21,28 +27,63 @@ namespace :glimmer do
21
27
  File.write('config/warble.rb', new_config)
22
28
  end
23
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
24
57
  end
25
58
 
26
- desc 'Package app for distribution'
27
- task :package => 'package:config' do
28
- require 'facets/string/titlecase'
29
- require 'facets/string/underscore'
30
- project_name = File.basename(File.expand_path('.'))
31
- version_file = File.expand_path('./VERSION')
32
- version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
33
- license_file = File.expand_path('./LICENSE.txt')
34
- license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
35
- human_name = project_name.underscore.titlecase
36
- system('mkdir -p dist')
37
- puts "Generating JAR with Warbler..."
38
- system('warble')
39
- 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}\" "
40
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
41
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
42
- command += " #{Glimmer::Package.javapackager_extra_args} " if Glimmer::Package.javapackager_extra_args
43
- command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
44
- puts "Generating DMG/PKG/APP/JNLP with javapackager..."
45
- puts command
46
- system command
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 project (namespace is required)'
80
+ task :custom_shell_gem, [:custom_widget_name, :namespace] do |t, args|
81
+ Scaffold.custom_shell_gem(args[:custom_widget_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
47
88
  end
48
89
  end
@@ -0,0 +1,442 @@
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
+ ## Uncomment the following section 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)
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/#{app_name.underscore}"
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)
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)
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 = "Glimmer Custom Widget - #{human_name(custom_shell_name)}"
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
197
+ append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
198
+ mkdir 'lib/views'
199
+ custom_shell(custom_shell_name, namespace)
200
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
201
+ puts "Finished creating #{gem_name} Ruby gem."
202
+ puts 'Edit Rakefile to configure gem details.'
203
+ puts 'Run `rake` to execute specs.'
204
+ puts 'Run `rake build` to build gem.'
205
+ puts 'Run `rake release` to release into rubygems.org once ready.'
206
+ end
207
+
208
+ def custom_widget_gem(custom_widget_name, namespace)
209
+ gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
210
+ gem_summary = "Glimmer Custom Widget - #{human_name(custom_widget_name)}"
211
+ if namespace
212
+ gem_name += "-#{compact_name(namespace)}"
213
+ gem_summary += " (#{human_name(namespace)})"
214
+ else
215
+ namespace = 'glimmer'
216
+ end
217
+ system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
218
+ cd gem_name
219
+ write '.gitignore', GITIGNORE
220
+ write '.ruby-version', RUBY_VERSION
221
+ write '.ruby-gemset', gem_name
222
+ write 'VERSION', '1.0.0'
223
+ write 'Gemfile', GEMFILE_GEM
224
+ write 'Rakefile', gem_rakefile
225
+ write 'spec/spec_helper.rb', spec_helper_file
226
+ append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
227
+ mkdir 'lib/views'
228
+ custom_widget(custom_widget_name, namespace)
229
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
230
+ puts "Finished creating #{gem_name} Ruby gem."
231
+ puts 'Edit Rakefile to configure gem details.'
232
+ puts 'Run `rake` to execute specs.'
233
+ puts 'Run `rake build` to build gem.'
234
+ puts 'Run `rake release` to release into rubygems.org once ready.'
235
+ end
236
+
237
+ private
238
+
239
+ def write(file, content)
240
+ File.write file, content
241
+ file_path = File.expand_path(file)
242
+ puts "Created #{current_dir_name}/#{file}"
243
+ end
244
+
245
+ def append(file, content)
246
+ File.open(file, 'a') do |f|
247
+ f.write(content)
248
+ end
249
+ end
250
+
251
+ def current_dir_name
252
+ File.basename(File.expand_path('.'))
253
+ end
254
+
255
+ def class_name(app_name)
256
+ app_name.camelcase(:upper)
257
+ end
258
+
259
+ def file_name(app_name)
260
+ app_name.underscore
261
+ end
262
+
263
+ def human_name(app_name)
264
+ app_name.underscore.titlecase
265
+ end
266
+
267
+ def compact_name(gem_name)
268
+ gem_name.camelcase.downcase
269
+ end
270
+
271
+ def app_main_file(app_name)
272
+ <<~MULTI_LINE_STRING
273
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
274
+
275
+ require 'bundler/setup'
276
+ Bundler.require(:default)
277
+ require 'views/#{file_name(app_name)}/app_view'
278
+
279
+ class #{class_name(app_name)}
280
+ include Glimmer
281
+
282
+ APP_ROOT = File.expand_path('../..', __FILE__)
283
+ VERSION = File.read(File.expand_path('VERSION', APP_ROOT))
284
+
285
+ def open
286
+ app_view.open
287
+ end
288
+ end
289
+
290
+ #{class_name(app_name)}.new.open
291
+ MULTI_LINE_STRING
292
+ end
293
+
294
+ def gem_main_file(custom_widget_name, namespace = nil)
295
+ custom_widget_file_path = "views"
296
+ custom_widget_file_path += "/#{file_name(namespace)}" if namespace
297
+ custom_widget_file_path += "/#{file_name(custom_widget_name)}"
298
+
299
+ <<~MULTI_LINE_STRING
300
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
301
+
302
+ require 'glimmer'
303
+ require '#{custom_widget_file_path}'
304
+ MULTI_LINE_STRING
305
+ end
306
+
307
+ def app_bin_file(app_name)
308
+ <<~MULTI_LINE_STRING
309
+ #!/usr/bin/env ruby
310
+
311
+ require_relative '../app/#{file_name(app_name)}'
312
+ MULTI_LINE_STRING
313
+ end
314
+
315
+ def gem_rakefile
316
+ rakefile_content = File.read('Rakefile')
317
+ lines = rakefile_content.split("\n")
318
+ require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
319
+ lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
320
+ gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
321
+ lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
322
+ spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
323
+ lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
324
+ lines << "\nrequire 'glimmer/rake_task'\n"
325
+ lines.join("\n")
326
+ end
327
+
328
+ def spec_helper_file
329
+ content = File.read('spec/spec_helper.rb')
330
+ lines = content.split("\n")
331
+ require_line_index = lines.index(lines.detect {|l| l.include?('glimmer-cw-video') })
332
+ lines[require_line_index...require_line_index] = [
333
+ "require 'bundler/setup'",
334
+ 'Bundler.require(:default, :development)',
335
+ ]
336
+ configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
337
+ lines[configure_block_line_index...configure_block_line_index] = [
338
+ ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
339
+ ' config.after do',
340
+ ' @target.dispose if @target && @target.respond_to?(:dispose)',
341
+ ' Glimmer::DSL::Engine.reset',
342
+ ' end',
343
+ ]
344
+
345
+ lines << "\nrequire 'glimmer/rake_task'\n"
346
+ lines.join("\n")
347
+ end
348
+
349
+ def custom_shell_file(custom_shell_name, namespace)
350
+ namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
351
+
352
+ <<~MULTI_LINE_STRING
353
+ #{namespace_type} #{class_name(namespace)}
354
+ class #{class_name(custom_shell_name)}
355
+ include Glimmer::UI::CustomShell
356
+
357
+ ## Add options like the following to configure CustomShell by outside consumers
358
+ #
359
+ # options :title, :background_color
360
+ # option :width, 320
361
+ # option :height, 240
362
+
363
+ ## Uncomment before_body block to pre-initialize variables to use in body
364
+ #
365
+ #
366
+ # before_body {
367
+ #
368
+ # }
369
+
370
+ ## Uncomment after_body block to setup observers for widgets in body
371
+ #
372
+ # after_body {
373
+ #
374
+ # }
375
+
376
+ ## Add widget content inside custom shell body
377
+ ## Top-most widget must be a shell or another custom shell
378
+ #
379
+ body {
380
+ shell {
381
+ # Replace example content below with custom shell content
382
+ minimum_size 320, 240
383
+ text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
384
+ grid_layout
385
+ label {
386
+ text "Hello, World!"
387
+ font height: 40
388
+ layout_data :center, :center, true, true
389
+ }
390
+ }
391
+ }
392
+
393
+ end
394
+ end
395
+ MULTI_LINE_STRING
396
+ end
397
+
398
+ def custom_widget_file(custom_widget_name, namespace)
399
+ namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
400
+
401
+ <<~MULTI_LINE_STRING
402
+ #{namespace_type} #{class_name(namespace)}
403
+ class #{class_name(custom_widget_name)}
404
+ include Glimmer::UI::CustomWidget
405
+
406
+ ## Add options like the following to configure CustomWidget by outside consumers
407
+ #
408
+ # options :custom_text, :background_color
409
+ # option :foreground_color, :red
410
+
411
+ ## Uncomment before_body block to pre-initialize variables to use in body
412
+ #
413
+ #
414
+ # before_body {
415
+ #
416
+ # }
417
+
418
+ ## Uncomment after_body block to setup observers for widgets in body
419
+ #
420
+ # after_body {
421
+ #
422
+ # }
423
+
424
+ ## Add widget content under custom widget body
425
+ ##
426
+ ## If you want to add a shell as the top-most widget,
427
+ ## consider creating a custom shell instead
428
+ ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
429
+ #
430
+ body {
431
+ # Replace example content below with custom widget content
432
+ label {
433
+ background :red
434
+ }
435
+ }
436
+
437
+ end
438
+ end
439
+ MULTI_LINE_STRING
440
+ end
441
+ end
442
+ end