glimmer 0.8.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +823 -297
  4. data/VERSION +1 -1
  5. data/lib/glimmer.rb +35 -21
  6. data/lib/glimmer/config.rb +7 -12
  7. data/lib/glimmer/data_binding/observable_array.rb +32 -53
  8. data/lib/glimmer/data_binding/observable_model.rb +12 -16
  9. data/lib/glimmer/data_binding/observer.rb +3 -0
  10. data/lib/glimmer/dsl/engine.rb +58 -27
  11. data/lib/glimmer/dsl/expression.rb +0 -7
  12. data/lib/glimmer/dsl/static_expression.rb +2 -2
  13. data/lib/glimmer/excluded_keyword_error.rb +5 -0
  14. metadata +60 -142
  15. data/RUBY_VERSION +0 -1
  16. data/bin/girb +0 -10
  17. data/bin/girb_runner.rb +0 -13
  18. data/bin/glimmer +0 -5
  19. data/icons/scaffold_app.icns +0 -0
  20. data/lib/glimmer/css/rule.rb +0 -25
  21. data/lib/glimmer/css/style_sheet.rb +0 -19
  22. data/lib/glimmer/data_binding/list_selection_binding.rb +0 -52
  23. data/lib/glimmer/data_binding/observable_widget.rb +0 -17
  24. data/lib/glimmer/data_binding/shine.rb +0 -23
  25. data/lib/glimmer/data_binding/table_items_binding.rb +0 -56
  26. data/lib/glimmer/data_binding/tree_items_binding.rb +0 -71
  27. data/lib/glimmer/data_binding/widget_binding.rb +0 -33
  28. data/lib/glimmer/dsl/css/css_expression.rb +0 -21
  29. data/lib/glimmer/dsl/css/dsl.rb +0 -10
  30. data/lib/glimmer/dsl/css/dynamic_property_expression.rb +0 -12
  31. data/lib/glimmer/dsl/css/property_expression.rb +0 -22
  32. data/lib/glimmer/dsl/css/pv_expression.rb +0 -17
  33. data/lib/glimmer/dsl/css/rule_expression.rb +0 -25
  34. data/lib/glimmer/dsl/css/s_expression.rb +0 -26
  35. data/lib/glimmer/dsl/swt/async_exec_expression.rb +0 -14
  36. data/lib/glimmer/dsl/swt/bind_expression.rb +0 -37
  37. data/lib/glimmer/dsl/swt/color_expression.rb +0 -19
  38. data/lib/glimmer/dsl/swt/column_properties_expression.rb +0 -24
  39. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +0 -42
  40. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +0 -36
  41. data/lib/glimmer/dsl/swt/data_binding_expression.rb +0 -34
  42. data/lib/glimmer/dsl/swt/dialog_expression.rb +0 -26
  43. data/lib/glimmer/dsl/swt/display_expression.rb +0 -19
  44. data/lib/glimmer/dsl/swt/dsl.rb +0 -28
  45. data/lib/glimmer/dsl/swt/exec_expression.rb +0 -28
  46. data/lib/glimmer/dsl/swt/layout_data_expression.rb +0 -25
  47. data/lib/glimmer/dsl/swt/layout_expression.rb +0 -27
  48. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +0 -44
  49. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +0 -33
  50. data/lib/glimmer/dsl/swt/menu_expression.rb +0 -32
  51. data/lib/glimmer/dsl/swt/message_box_expression.rb +0 -29
  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 -35
  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 -55
  75. data/lib/glimmer/rake_task.rb +0 -58
  76. data/lib/glimmer/scaffold.rb +0 -582
  77. data/lib/glimmer/swt/color_proxy.rb +0 -53
  78. data/lib/glimmer/swt/display_proxy.rb +0 -88
  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 -101
  83. data/lib/glimmer/swt/message_box_proxy.rb +0 -48
  84. data/lib/glimmer/swt/packages.rb +0 -13
  85. data/lib/glimmer/swt/shell_proxy.rb +0 -152
  86. data/lib/glimmer/swt/swt_proxy.rb +0 -106
  87. data/lib/glimmer/swt/tab_item_proxy.rb +0 -65
  88. data/lib/glimmer/swt/table_proxy.rb +0 -150
  89. data/lib/glimmer/swt/tree_proxy.rb +0 -120
  90. data/lib/glimmer/swt/widget_listener_proxy.rb +0 -34
  91. data/lib/glimmer/swt/widget_proxy.rb +0 -489
  92. data/lib/glimmer/ui/custom_shell.rb +0 -45
  93. data/lib/glimmer/ui/custom_widget.rb +0 -244
  94. data/lib/glimmer/util/proc_tracker.rb +0 -16
  95. data/lib/glimmer/xml/depth_first_search_iterator.rb +0 -22
  96. data/lib/glimmer/xml/name_space_visitor.rb +0 -21
  97. data/lib/glimmer/xml/node.rb +0 -75
  98. data/lib/glimmer/xml/node_visitor.rb +0 -13
  99. data/lib/glimmer/xml/xml_visitor.rb +0 -65
  100. data/vendor/swt/linux/swt.jar +0 -0
  101. data/vendor/swt/mac/swt.jar +0 -0
  102. data/vendor/swt/windows/swt.jar +0 -0
@@ -1,29 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/xml/xml_expression'
3
- require 'glimmer/dsl/static_expression'
4
- require 'glimmer/dsl/top_level_expression'
5
- require 'glimmer/xml/node'
6
-
7
- module Glimmer
8
- module DSL
9
- module XML
10
- class TagExpression < StaticExpression
11
- include TopLevelExpression
12
- include NodeParentExpression
13
-
14
- def can_interpret?(parent, keyword, *args, &block)
15
- (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
16
- (keyword.to_s == "tag") and
17
- args[0].include?(:_name)
18
- end
19
-
20
- def interpret(parent, keyword, *args, &block)
21
- attributes = args[0] if (args.size == 1)
22
- tag_name = attributes[:_name]
23
- attributes.delete(:_name)
24
- Glimmer::XML::Node.new(parent, tag_name, attributes, &block)
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,22 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/xml/node'
3
-
4
- module Glimmer
5
- module DSL
6
- module XML
7
- class TextExpression < StaticExpression
8
- def can_interpret?(parent, keyword, *args, &block)
9
- (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
10
- (keyword.to_s == "text") and
11
- (args.size == 1) and
12
- !block
13
- end
14
-
15
- def interpret(parent, keyword, *args, &block)
16
- parent.children << args[0].to_s if parent
17
- args[0].to_s
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- require 'glimmer/dsl/xml/node_parent_expression'
2
- require 'glimmer/dsl/expression'
3
- require 'glimmer/xml/node'
4
-
5
- module Glimmer
6
- module DSL
7
- module XML
8
- class XmlExpression < Expression
9
- include NodeParentExpression
10
-
11
- def can_interpret?(parent, keyword, *args, &block)
12
- parent.is_a?(Glimmer::XML::Node)
13
- end
14
-
15
- def interpret(parent, keyword, *args, &block)
16
- Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,199 +0,0 @@
1
- require 'os'
2
- require 'rake'
3
-
4
- require_relative 'rake_task'
5
-
6
- module Glimmer
7
- class Launcher
8
- OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
9
-
10
- TEXT_USAGE_PREFIX = <<~MULTI_LINE_STRING
11
- Usage: glimmer [--quiet] [--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
- - "--quiet" : Does not announce file path of Glimmer application being launched
31
- - "--debug" : Displays extra debugging information, passes "--debug" to JRuby, and enables debug logging
32
- - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none)
33
-
34
- Example: glimmer samples/hello_world.rb
35
-
36
- This runs the Glimmer application samples/hello_world.rb
37
- MULTI_LINE_STRING
38
-
39
- GLIMMER_LIB_LOCAL = File.expand_path(File.join(__FILE__, '..', '..', 'glimmer.rb'))
40
- GLIMMER_LIB_GEM = 'glimmer'
41
- GLIMMER_OPTIONS = %w[--log-level --quiet]
42
- GLIMMER_OPTION_ENV_VAR_MAPPING = {
43
- '--log-level' => 'GLIMMER_LOGGER_LEVEL'
44
- }
45
- REGEX_RAKE_TASK_WITH_ARGS = /^([^\[]+)\[?([^\]]*)\]?$/
46
-
47
- @@mutex = Mutex.new
48
-
49
- class << self
50
- def platform_os
51
- OPERATING_SYSTEMS_SUPPORTED.detect {|os| OS.send("#{os}?")}
52
- end
53
-
54
- def swt_jar_file
55
- @swt_jar_file ||= File.expand_path(File.join(__FILE__, '..', '..', '..', 'vendor', 'swt', platform_os, 'swt.jar'))
56
- end
57
-
58
- def jruby_os_specific_options
59
- OS.mac? ? "-J-XstartOnFirstThread" : ""
60
- end
61
-
62
- def jruby_swt_options
63
- "#{jruby_os_specific_options} -J-classpath \"#{swt_jar_file}\""
64
- end
65
-
66
- def glimmer_lib
67
- @@mutex.synchronize do
68
- unless @glimmer_lib
69
- @glimmer_lib = GLIMMER_LIB_GEM
70
- glimmer_gem_listing = `jgem list #{GLIMMER_LIB_GEM}`.split("\n").map {|l| l.split.first}
71
- if !glimmer_gem_listing.include?(GLIMMER_LIB_GEM) && File.exists?(GLIMMER_LIB_LOCAL)
72
- @glimmer_lib = GLIMMER_LIB_LOCAL
73
- puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})"
74
- end
75
- end
76
- end
77
- @glimmer_lib
78
- end
79
-
80
- def glimmer_option_env_vars(glimmer_options)
81
- GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair|
82
- glimmer_options[pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => glimmer_options[pair.first]) : hash
83
- end
84
- end
85
-
86
- def load_env_vars(env_vars)
87
- env_vars.each do |key, value|
88
- ENV[key] = value
89
- end
90
- end
91
-
92
- def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
93
- jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
94
- env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
95
- env_vars_string = env_vars.map {|k,v| "#{k}=#{v}"}.join(' ')
96
- the_glimmer_lib = glimmer_lib
97
- devmode_require = nil
98
- if the_glimmer_lib == GLIMMER_LIB_LOCAL
99
- devmode_require = '-r puts_debuggerer '
100
- end
101
- rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')}
102
- potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS)
103
- application = potential_rake_task_parts[1]
104
- rake_task_args = potential_rake_task_parts[2].split(',')
105
- if rake_tasks.include?(application)
106
- load_env_vars(glimmer_option_env_vars(glimmer_options))
107
- rake_task = "glimmer:#{application}"
108
- puts "Running Glimmer rake task: #{rake_task}" if jruby_options_string.to_s.include?('--debug')
109
- Rake::Task[rake_task].invoke(*rake_task_args)
110
- else
111
- @@mutex.synchronize do
112
- puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
113
- end
114
- command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
115
- puts command if jruby_options_string.to_s.include?('--debug')
116
- system command
117
- end
118
- end
119
- end
120
-
121
- attr_reader :application_paths
122
- attr_reader :env_vars
123
- attr_reader :glimmer_options
124
- attr_reader :jruby_options
125
-
126
- def initialize(raw_options)
127
- raw_options << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !raw_options.join.include?('--quiet=')
128
- raw_options << '--log-level=DEBUG' if raw_options.join.include?('--debug') && !raw_options.join.include?('--log-level=')
129
- @application_paths = extract_application_paths(raw_options)
130
- @env_vars = extract_env_vars(raw_options)
131
- @glimmer_options = extract_glimmer_options(raw_options)
132
- @jruby_options = raw_options
133
- end
134
-
135
- def launch
136
- if @application_paths.empty?
137
- display_usage
138
- else
139
- launch_application
140
- end
141
- end
142
-
143
- private
144
-
145
- def launch_application
146
- load File.expand_path('./Rakefile') if File.exist?(File.expand_path('./Rakefile')) && caller.join("\n").include?('/bin/glimmer:')
147
- threads = @application_paths.map do |application_path|
148
- Thread.new do
149
- self.class.launch(
150
- application_path,
151
- jruby_options: @jruby_options,
152
- env_vars: @env_vars,
153
- glimmer_options: @glimmer_options
154
- )
155
- end
156
- end
157
- threads.each(&:join)
158
- end
159
-
160
- def display_usage
161
- rake_tasks = `rake -T`.gsub('rake glimmer:', 'glimmer ').split("\n").select {|l| l.start_with?('glimmer ')}
162
- puts TEXT_USAGE_PREFIX
163
- puts rake_tasks.join("\n")
164
- puts TEXT_USAGE_SUFFIX
165
- end
166
-
167
- def extract_application_paths(options)
168
- options.select do |option|
169
- !option.start_with?('-') && !option.include?('=')
170
- end.each do |application_path|
171
- options.delete(application_path)
172
- end
173
- end
174
-
175
- def extract_env_vars(options)
176
- options.select do |option|
177
- !option.start_with?('-') && option.include?('=')
178
- end.each do |env_var|
179
- options.delete(env_var)
180
- end.reduce({}) do |hash, env_var_string|
181
- match = env_var_string.match(/^([^=]+)=(.+)$/)
182
- hash.merge(match[1] => match[2])
183
- end
184
- end
185
-
186
- def extract_glimmer_options(options)
187
- options.select do |option|
188
- GLIMMER_OPTIONS.reduce(false) do |result, glimmer_option|
189
- result || option.include?(glimmer_option)
190
- end
191
- end.each do |glimmer_option|
192
- options.delete(glimmer_option)
193
- end.reduce({}) do |hash, glimmer_option_string|
194
- match = glimmer_option_string.match(/^([^=]+)=?(.+)?$/)
195
- hash.merge(match[1] => (match[2] || 'true'))
196
- end
197
- end
198
- end
199
- end
@@ -1,55 +0,0 @@
1
- module Glimmer
2
- module Package
3
- class << self
4
- attr_accessor :javapackager_extra_args
5
-
6
- def config
7
- project_name = File.basename(File.expand_path('.'))
8
- if !File.exists?('config/warble.rb')
9
- puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
10
- system('mkdir -p config')
11
- system('warble config')
12
- new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
13
- if line.include?('config.dirs =')
14
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos)')
15
- end
16
- if line.include?('config.includes =')
17
- line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
18
- end
19
- if line.include?('config.autodeploy_dir =')
20
- line = line.sub('# ', '')
21
- end
22
- output + "\n" + line
23
- end
24
- File.write('config/warble.rb', new_config)
25
- end
26
- end
27
-
28
- def jar
29
- system('mkdir -p dist')
30
- puts "Generating JAR with Warbler..."
31
- system('warble')
32
- end
33
-
34
- def native
35
- require 'facets/string/titlecase'
36
- require 'facets/string/underscore'
37
- project_name = File.basename(File.expand_path('.'))
38
- version_file = File.expand_path('./VERSION')
39
- version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
40
- license_file = File.expand_path('./LICENSE.txt')
41
- license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
42
- human_name = project_name.underscore.titlecase
43
- command = "javapackager -deploy -native -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\" "
44
- command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
45
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
46
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
47
- command += " #{javapackager_extra_args} " if javapackager_extra_args
48
- command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
49
- puts "Generating DMG/PKG/APP/JNLP with javapackager..."
50
- puts command
51
- system command
52
- end
53
- end
54
- end
55
- end
@@ -1,58 +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
- Glimmer::Package.config
11
- end
12
-
13
- desc 'Generate JAR file'
14
- task :jar do
15
- Glimmer::Package.jar
16
- end
17
-
18
- desc 'Generate Native files (DMG/PKG/APP on the Mac, EXE on Windows, RPM/DEB on Linux)'
19
- task :native do
20
- Glimmer::Package.native
21
- end
22
- end
23
-
24
- desc 'Package app for distribution (generating config, jar, and native files)'
25
- task :package do
26
- Rake::Task['glimmer:package:config'].execute
27
- Rake::Task['glimmer:package:jar'].execute
28
- Rake::Task['glimmer:package:native'].execute
29
- end
30
-
31
-
32
- desc 'Scaffold a Glimmer application directory structure to begin building a new app'
33
- task :scaffold, [:app_name] do |t, args|
34
- Scaffold.app(args[:app_name])
35
- end
36
-
37
- namespace :scaffold do
38
- desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under app/views (namespace is optional)'
39
- task :custom_shell, [:custom_shell_name, :namespace] do |t, args|
40
- Scaffold.custom_shell(args[:custom_shell_name], args[:namespace])
41
- end
42
-
43
- desc 'Scaffold a Glimmer::UI::CustomWidget subclass (represents a part of a view) under app/views (namespace is optional)'
44
- task :custom_widget, [:custom_widget_name, :namespace] do |t, args|
45
- Scaffold.custom_widget(args[:custom_widget_name], args[:namespace])
46
- end
47
-
48
- desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under its own Ruby gem + app project (namespace is required)'
49
- task :custom_shell_gem, [:custom_shell_name, :namespace] do |t, args|
50
- Scaffold.custom_shell_gem(args[:custom_shell_name], args[:namespace])
51
- end
52
-
53
- desc 'Scaffold a Glimmer::UI::CustomWidget subclass (represents a part of a view) under its own Ruby gem project (namespace is required)'
54
- task :custom_widget_gem, [:custom_widget_name, :namespace] do |t, args|
55
- Scaffold.custom_widget_gem(args[:custom_widget_name], args[:namespace])
56
- end
57
- end
58
- end
@@ -1,582 +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, default: 320
428
- # option :height, default: 240
429
- option :greeting, default: '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
- @display = display {
442
- on_about {
443
- display_about_dialog
444
- }
445
- on_preferences {
446
- display_preferences_dialog
447
- }
448
- }
449
- }
450
- MULTI_LINE_STRING
451
- else
452
- custom_shell_file_content += <<-MULTI_LINE_STRING
453
- # before_body {
454
- #
455
- # }
456
- MULTI_LINE_STRING
457
- end
458
-
459
- custom_shell_file_content += <<-MULTI_LINE_STRING
460
-
461
- ## Use after_body block to setup observers for widgets in body
462
- #
463
- # after_body {
464
- #
465
- # }
466
-
467
- ## Add widget content inside custom shell body
468
- ## Top-most widget must be a shell or another custom shell
469
- #
470
- body {
471
- shell {
472
- # Replace example content below with custom shell content
473
- minimum_size 320, 240
474
- text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
475
- grid_layout
476
- label(:center) {
477
- text bind(self, :greeting)
478
- font height: 40
479
- layout_data :fill, :center, true, true
480
- }
481
- }
482
- }
483
- MULTI_LINE_STRING
484
-
485
- if %i[gem app].include?(shell_type)
486
- custom_shell_file_content += <<-MULTI_LINE_STRING
487
-
488
- def display_about_dialog
489
- message_box = MessageBox.new(swt_widget)
490
- message_box.setText("About")
491
- message = "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\n\n"
492
- message += LICENSE
493
- message_box.setMessage(message)
494
- message_box.open
495
- end
496
-
497
- def display_preferences_dialog
498
- dialog(swt_widget) {
499
- text 'Preferences'
500
- grid_layout {
501
- margin_height 5
502
- margin_width 5
503
- }
504
- group {
505
- row_layout {
506
- type :vertical
507
- spacing 10
508
- }
509
- text 'Greeting'
510
- font style: :bold
511
- [
512
- 'Hello, World!',
513
- 'Howdy, Partner!'
514
- ].each do |greeting_text|
515
- button(:radio) {
516
- text greeting_text
517
- selection bind(self, :greeting) { |g| g == greeting_text }
518
- layout_data {
519
- width 160
520
- }
521
- on_widget_selected { |event|
522
- self.greeting = event.widget.getText
523
- }
524
- }
525
- end
526
- }
527
- }.open
528
- end
529
- MULTI_LINE_STRING
530
- end
531
-
532
- custom_shell_file_content += <<-MULTI_LINE_STRING
533
- end
534
- end
535
- MULTI_LINE_STRING
536
- end
537
-
538
- def custom_widget_file(custom_widget_name, namespace)
539
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
540
-
541
- <<~MULTI_LINE_STRING
542
- #{namespace_type} #{class_name(namespace)}
543
- class #{class_name(custom_widget_name)}
544
- include Glimmer::UI::CustomWidget
545
-
546
- ## Add options like the following to configure CustomWidget by outside consumers
547
- #
548
- # options :custom_text, :background_color
549
- # option :foreground_color, default: :red
550
-
551
- ## Use before_body block to pre-initialize variables to use in body
552
- #
553
- #
554
- # before_body {
555
- #
556
- # }
557
-
558
- ## Use after_body block to setup observers for widgets in body
559
- #
560
- # after_body {
561
- #
562
- # }
563
-
564
- ## Add widget content under custom widget body
565
- ##
566
- ## If you want to add a shell as the top-most widget,
567
- ## consider creating a custom shell instead
568
- ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
569
- #
570
- body {
571
- # Replace example content below with custom widget content
572
- label {
573
- background :red
574
- }
575
- }
576
-
577
- end
578
- end
579
- MULTI_LINE_STRING
580
- end
581
- end
582
- end