glimmer-dsl-swt 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7caca40c9a1207a97846a5c5511fe24a07f4689979e57d54c395a33b3b341ba
4
- data.tar.gz: 4b41ad30f7e63cd67bc87e88668cfb7f5b2d49b3d4cb7081bcfa04b6dcfefa90
3
+ metadata.gz: 0d324a6327e85a840d2a980ba78a47fa9c50e927b409f128c60d9b2ac38f2124
4
+ data.tar.gz: ace770a87429cbaca623310837618e14f12e8375221c433751e1feb13e768eff
5
5
  SHA512:
6
- metadata.gz: 2f41fda28c273df8bb93810f68c7841f60346b3469b7afeea9992bdf34f06dae28912af64dcce1ebcc6604832383de7a3082d3f4fe7238d5fa6563476792246d
7
- data.tar.gz: 92e0b7e06ebcf4e7af47bfbc22189449d5161ebda431bd4be5973c4447ba622bac139bf31d4cbaaf5e92658d6695a49e522086e54f8a4303cd394fd9bdef2e65
6
+ metadata.gz: 0d7e8c740b9fb6a8993e906a485cdc50241ea5a12664ff4f9ec128de2b2f77ad9718ae41fb0e9bd391546127273769769a1ac259870f2327bd29bba18d40afe3
7
+ data.tar.gz: 56406b25d9ab52e5af2043f33860cbd8cc0a5681b4e7eeba77325122c71cf9897c7bcd6f19ea68e3b3171f1e0dfa07c8d8dc501297fce2e8c83cc37ba3ed024b
data/README.md CHANGED
@@ -1,11 +1,36 @@
1
- # Glimmer DSL for SWT 0.1.0 (Desktop GUI)
1
+ # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.2.1 (Desktop GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
+ [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
5
+ [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
6
 
5
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for SWT enables desktop development with Glimmer.
7
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer).
6
8
 
7
- You may find full setup/usage instructions at the main Glimmer project page:
8
- [https://github.com/AndyObtiva/glimmer](https://github.com/AndyObtiva/glimmer)
9
+ [Glimmer](https://github.com/AndyObtiva/glimmer) is a native-GUI cross-platform desktop development library written in Ruby. Glimmer's main innovation is a JRuby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support to greatly facilitate synchronizing the GUI with domain models. As a result, that achieves true decoupling of object oriented components, enabling developers to solve business problems without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models test-first afterwards.
10
+
11
+ You may find full setup/usage instructions at the main [Glimmer project page](https://github.com/AndyObtiva/glimmer).
12
+
13
+ Other Glimmer DSL gems:
14
+ - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
15
+ - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
16
+ - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
17
+
18
+ ## Example
19
+
20
+ ```ruby
21
+ include Glimmer
22
+
23
+ shell {
24
+ text 'Glimmer'
25
+ label {
26
+ text 'Hello, World!'
27
+ }
28
+ }.open
29
+ ```
30
+
31
+ ![Glimmer DSL for SWT Hello World](https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-hello-world.png)
32
+
33
+ Learn more at the main [Glimmer project page](https://github.com/AndyObtiva/glimmer).
9
34
 
10
35
  ## Help
11
36
 
@@ -15,11 +40,9 @@ You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub
15
40
 
16
41
  [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
17
42
 
18
- ### IRC Channel
19
-
20
- If you need live help, try the [#glimmer](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer) IRC channel on [irc.mibbit.net](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer). If no one was available, you may [leave a GitHub issue](https://github.com/AndyObtiva/glimmer/issues) to schedule a meetup on IRC.
43
+ ### Chat
21
44
 
22
- [Click here to connect to #glimmer IRC channel immediately via a web interface.](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer)
45
+ If you need live help, try to [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
23
46
 
24
47
  ## Feature Suggestions
25
48
 
@@ -1 +1 @@
1
- jruby-9.2.11.1
1
+ jruby-9.2.12.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
Binary file
@@ -3,11 +3,18 @@ require 'glimmer/swt/packages'
3
3
  module Glimmer
4
4
  class << self
5
5
  def included(klass)
6
+ if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:Dependencies)
7
+ begin
8
+ ActiveSupport::Dependencies.unhook!
9
+ rescue => e
10
+ # noop TODO support logging unimportant details below debug level
11
+ end
12
+ end
6
13
  if Config.import_swt_packages
7
14
  klass.include(SWT::Packages)
8
15
  klass.extend(SWT::Packages)
9
- klass.extend(Glimmer)
10
16
  end
17
+ klass.extend(Glimmer)
11
18
  end
12
19
  end
13
20
  end
@@ -1,16 +1,24 @@
1
1
  module Glimmer
2
2
  module Config
3
+ DEFAULT_IMPORT_SWT_PACKAGES = [
4
+ 'org.eclipse.swt',
5
+ 'org.eclipse.swt.widgets',
6
+ 'org.eclipse.swt.layout',
7
+ 'org.eclipse.swt.graphics',
8
+ 'org.eclipse.swt.browser',
9
+ 'org.eclipse.swt.custom',
10
+ 'org.eclipse.swt.dnd',
11
+ ]
12
+
3
13
  class << self
4
14
  # Tells Glimmer to import SWT packages into including class (default: true)
5
15
  def import_swt_packages=(value)
6
- @@import_swt_packages = !!value
16
+ @@import_swt_packages = value
7
17
  end
8
18
 
9
19
  # Returns whether Glimmer will import SWT packages into including class
10
20
  def import_swt_packages
11
- unless defined? @@import_swt_packages
12
- @@import_swt_packages = true
13
- end
21
+ @@import_swt_packages = DEFAULT_IMPORT_SWT_PACKAGES if !defined?(@@import_swt_packages) || (defined?(@@import_swt_packages) && @@import_swt_packages == true)
14
22
  @@import_swt_packages
15
23
  end
16
24
  end
@@ -2,9 +2,14 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
2
2
 
3
3
  # External requires
4
4
  require 'java'
5
- require 'nested_inherited_jruby_include_package'
6
- require 'super_module'
7
- require 'glimmer'
5
+ if ENV['BUNDLER_REQUIRE'].to_s.downcase == 'true'
6
+ require 'bundler'
7
+ Bundler.require
8
+ else
9
+ require 'nested_inherited_jruby_include_package'
10
+ require 'super_module'
11
+ require 'glimmer'
12
+ end
8
13
 
9
14
  # Internal requires
10
15
  require 'ext/glimmer/config'
@@ -1,4 +1,3 @@
1
- require 'glimmer'
2
1
  require 'glimmer/data_binding/observable'
3
2
  require 'glimmer/data_binding/observer'
4
3
 
@@ -22,23 +22,24 @@ module Glimmer
22
22
  @table.body_root.column_properties = @column_properties
23
23
  end
24
24
  call(@model_binding.evaluate_property)
25
- model = model_binding.base_model
26
- observe(model, model_binding.property_name_expression)
25
+ observe(model_binding)
27
26
  @table.on_widget_disposed do |dispose_event|
28
27
  unregister_all_observables
29
28
  end
30
29
  end
31
30
 
32
31
  def call(new_model_collection=nil)
32
+ new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read)
33
33
  if new_model_collection and new_model_collection.is_a?(Array)
34
34
  observe(new_model_collection, @column_properties)
35
35
  @model_collection = new_model_collection
36
36
  end
37
- populate_table(@model_collection, @table, @column_properties)
37
+ populate_table(@model_collection, @table, @column_properties)
38
38
  end
39
-
39
+
40
40
  def populate_table(model_collection, parent, column_properties)
41
41
  selected_table_item_models = parent.swt_widget.getSelection.map(&:getData)
42
+ parent.finish_edit!
42
43
  parent.swt_widget.removeAll
43
44
  model_collection.each do |model|
44
45
  table_item = TableItem.new(parent.swt_widget, SWT::SWTProxy[:none])
@@ -1,6 +1,5 @@
1
- require 'glimmer'
2
- require_relative 'observable'
3
- require_relative 'observer'
1
+ require 'glimmer/data_binding/observable'
2
+ require 'glimmer/data_binding/observer'
4
3
 
5
4
  module Glimmer
6
5
  module DataBinding
@@ -10,10 +9,10 @@ module Glimmer
10
9
  include Observer
11
10
 
12
11
  attr_reader :widget, :property
13
- def initialize(model, property, translator = nil)
14
- @widget = model
12
+ def initialize(widget, property, translator = nil)
13
+ @widget = widget
15
14
  @property = property
16
- @translator = translator || proc {|value| value}
15
+ @translator = translator || proc {|value| value} #TODO check on this it doesn't seem used
17
16
 
18
17
  if @widget.respond_to?(:dispose)
19
18
  @widget.on_widget_disposed do |dispose_event|
@@ -21,10 +20,12 @@ module Glimmer
21
20
  end
22
21
  end
23
22
  end
23
+
24
24
  def call(value)
25
25
  converted_value = translated_value = @translator.call(value)
26
26
  @widget.set_attribute(@property, converted_value) unless evaluate_property == converted_value
27
27
  end
28
+
28
29
  def evaluate_property
29
30
  @widget.get_attribute(@property)
30
31
  end
@@ -0,0 +1,25 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/swt/dnd_proxy'
3
+
4
+ # TODO consider turning static keywords like bind into methods
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ # Responsible for returning DND constant values
10
+ #
11
+ # Named DndExpression (not DNDExpression) so that the DSL engine
12
+ # discovers quickly by convention
13
+ class DndExpression < StaticExpression
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ block.nil? &&
16
+ args.size > 0
17
+ end
18
+
19
+ def interpret(parent, keyword, *args, &block)
20
+ Glimmer::SWT::DNDProxy[*args]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -14,10 +14,6 @@ module Glimmer
14
14
 
15
15
  include_package 'org.eclipse.swt.widgets'
16
16
 
17
- def can_interpret?(parent, keyword, *args, &block)
18
- keyword == 'message_box'
19
- end
20
-
21
17
  def interpret(parent, keyword, *args, &block)
22
18
  potential_parent = args.first
23
19
  parent = args.shift if potential_parent.is_a?(Shell) || (potential_parent.respond_to?(:swt_widget) && potential_parent.swt_widget.is_a?(Shell))
@@ -33,7 +33,7 @@ module Glimmer
33
33
  This runs the Glimmer application samples/hello_world.rb
34
34
  MULTI_LINE_STRING
35
35
 
36
- GLIMMER_LIB_LOCAL = File.expand_path(File.join(__FILE__, '..', '..', 'glimmer-dsl-swt.rb'))
36
+ GLIMMER_LIB_LOCAL = File.expand_path(File.join('lib', 'glimmer-dsl-swt.rb'))
37
37
  GLIMMER_LIB_GEM = 'glimmer-dsl-swt'
38
38
  GLIMMER_OPTIONS = %w[--log-level --quiet]
39
39
  GLIMMER_OPTION_ENV_VAR_MAPPING = {
@@ -1,5 +1,7 @@
1
1
  require 'os'
2
2
 
3
+ # TODO refactor to nest under RakeTask namespace
4
+
3
5
  module Glimmer
4
6
  module Package
5
7
  class << self
@@ -59,4 +59,26 @@ namespace :glimmer do
59
59
  Scaffold.custom_widget_gem(args[:custom_widget_name], args[:namespace])
60
60
  end
61
61
  end
62
+
63
+ namespace :list do
64
+ task :list_require do
65
+ require_relative 'rake_task/list'
66
+ end
67
+
68
+ desc 'List Glimmer custom widget gems available at rubygems.org (query is optional)'
69
+ task :custom_widget_gems, [:query] => :list_require do |t, args|
70
+ Glimmer::RakeTask::List.custom_widget_gems(args[:query])
71
+ end
72
+
73
+ desc 'List Glimmer custom shell gems available at rubygems.org (query is optional)'
74
+ task :custom_shell_gems, [:query] => :list_require do |t, args|
75
+ Glimmer::RakeTask::List.custom_shell_gems(args[:query])
76
+ end
77
+
78
+ desc 'List Glimmer DSL gems available at rubygems.org (query is optional)'
79
+ task :dsl_gems, [:query] => :list_require do |t, args|
80
+ Glimmer::RakeTask::List.dsl_gems(args[:query])
81
+ end
82
+
83
+ end
62
84
  end
@@ -0,0 +1,73 @@
1
+ require 'facets'
2
+ require 'text-table'
3
+
4
+ module Glimmer
5
+ module RakeTask
6
+ # Lists Glimmer related gems to use in rake_task.rb
7
+ class List
8
+ class << self
9
+ REGEX_GEM_LINE = /^([^\(]+) \(([^\)]+)\)$/
10
+
11
+ def custom_widget_gems(query=nil)
12
+ list_gems('glimmer-cw-', query) do |result|
13
+ puts
14
+ puts " Glimmer Custom Widget Gems#{" matching [#{query}]" if query} at rubygems.org:"
15
+ puts result
16
+ end
17
+ end
18
+
19
+ def custom_shell_gems(query=nil)
20
+ list_gems('glimmer-cs-', query) do |result|
21
+ puts
22
+ puts " Glimmer Custom Shell Gems#{" matching [#{query}]" if query} at rubygems.org:"
23
+ puts result
24
+ end
25
+ end
26
+
27
+ def dsl_gems(query=nil)
28
+ list_gems('glimmer-dsl-', query) do |result|
29
+ puts
30
+ puts " Glimmer DSL Gems#{" matching [#{query}]" if query} at rubygems.org:"
31
+ puts result
32
+ end
33
+ end
34
+
35
+ def list_gems(gem_prefix, query=nil, &printer)
36
+ lines = `gem search -d #{gem_prefix}`.split("\n")
37
+ gems = lines.slice_before {|l| l.match(REGEX_GEM_LINE) }.to_a
38
+ gems = gems.map do |gem|
39
+ {
40
+ name: gem[0].match(REGEX_GEM_LINE)[1],
41
+ version: gem[0].match(REGEX_GEM_LINE)[2],
42
+ author: gem[1].strip,
43
+ description: gem[4..-1].map(&:strip).join(' ')
44
+ }
45
+ end.select do |gem|
46
+ query.nil? || "#{gem[:name]} #{gem[:author]} #{gem[:description]}".downcase.include?(query.to_s.downcase)
47
+ end
48
+ printer.call(tablify(gem_prefix, gems))
49
+ end
50
+
51
+ def tablify(gem_prefix, gems)
52
+ array_of_arrays = gems.map do |gem|
53
+ [
54
+ gem[:name].sub(gem_prefix, '').underscore.titlecase,
55
+ gem[:name],
56
+ gem[:version],
57
+ gem[:author].sub('Author: ', ''),
58
+ gem[:description],
59
+ ]
60
+ end
61
+ Text::Table.new(
62
+ :head => %w[Name Gem Version Author Description],
63
+ :rows => array_of_arrays,
64
+ :horizontal_padding => 1,
65
+ :vertical_boundary => ' ',
66
+ :horizontal_boundary => ' ',
67
+ :boundary_intersection => ' '
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -2,6 +2,8 @@ require 'fileutils'
2
2
  require 'os'
3
3
  require 'facets'
4
4
 
5
+ # TODO refactor to nest under RakeTask namespace
6
+
5
7
  class Scaffold
6
8
  class << self
7
9
  include FileUtils
@@ -155,7 +157,6 @@ class Scaffold
155
157
  end
156
158
  mkdir 'bin'
157
159
  write "bin/#{file_name(app_name)}", app_bin_file(app_name)
158
- FileUtils.chmod 0755, "bin/#{file_name(app_name)}"
159
160
  system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
160
161
  system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
161
162
  # TODO generate rspec test suite
@@ -193,14 +194,14 @@ class Scaffold
193
194
  write '.ruby-gemset', gem_name
194
195
  write 'VERSION', '1.0.0'
195
196
  write 'Gemfile', GEMFILE_GEM
196
- write 'Rakefile', gem_rakefile(custom_shell_name, namespace)
197
+ write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
197
198
  append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
198
199
  mkdir 'lib/views'
199
200
  custom_shell(custom_shell_name, namespace, :gem)
200
201
  mkdir 'bin'
201
202
  write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
202
203
  write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
203
- FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
204
+ FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
204
205
  if OS.mac?
205
206
  mkdir_p 'package/macosx'
206
207
  icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
@@ -317,8 +318,6 @@ class Scaffold
317
318
 
318
319
  def app_bin_file(app_name)
319
320
  <<~MULTI_LINE_STRING
320
- #!/usr/bin/env ruby
321
-
322
321
  require_relative '../app/#{file_name(app_name)}'
323
322
 
324
323
  #{class_name(app_name)}.new.open
@@ -327,8 +326,6 @@ class Scaffold
327
326
 
328
327
  def gem_bin_file(gem_name, custom_shell_name, namespace)
329
328
  <<~MULTI_LINE_STRING
330
- #!/usr/bin/env ruby
331
-
332
329
  require_relative '../lib/#{gem_name}'
333
330
 
334
331
  include Glimmer
@@ -349,7 +346,7 @@ class Scaffold
349
346
  MULTI_LINE_STRING
350
347
  end
351
348
 
352
- def gem_rakefile(custom_shell_name = nil, namespace = nil)
349
+ def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
353
350
  rakefile_content = File.read('Rakefile')
354
351
  lines = rakefile_content.split("\n")
355
352
  require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
@@ -357,7 +354,7 @@ class Scaffold
357
354
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
358
355
  if custom_shell_name
359
356
  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)}']")
357
+ lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
361
358
  else
362
359
  lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
363
360
  end
@@ -0,0 +1,34 @@
1
+ require 'glimmer/swt/style_constantizable'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ # Proxy for org.eclipse.swt.dnd.DND
6
+ #
7
+ # Follows the Proxy Design Pattern
8
+ class DNDProxy
9
+ include StyleConstantizable
10
+
11
+ class << self
12
+ JAVA_IMPORT = 'org.eclipse.swt.dnd.DND'
13
+
14
+ java_import JAVA_IMPORT
15
+
16
+ def constant_java_import
17
+ JAVA_IMPORT
18
+ end
19
+
20
+ def constant_source_class
21
+ DND
22
+ end
23
+
24
+ def constant_value_none
25
+ DND::DROP_NONE
26
+ end
27
+
28
+ def extra_styles
29
+ {}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end