glimmer-dsl-libui 0.9.2 → 0.9.4

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: c3ad3f4e1a2e367a8e95fba05f1b539f2aa865dfab7e2234541933be97dda171
4
- data.tar.gz: 44255036ce4a887224c84f861d0654483bada4ff8ed3c2a1c4192083a19cf45b
3
+ metadata.gz: 916c5f10df3886ef6a5eed0ba6cbade95141812b5f5ab302ba3fb6dc0449a989
4
+ data.tar.gz: 6558bc6824e050a4f36c8d89d8ee2eded34017e2f931905f7469e045e56ab5e7
5
5
  SHA512:
6
- metadata.gz: e018c132e8b838ce839adeaae9d812d52ab8be960b87a8d3e5c85cf8045d988b83495640fb4bef7cb778960d2f25b7da8fcf4d659bd8ada7ed8277d26cc9ff9f
7
- data.tar.gz: 3fb97e3a7946c9690c0bd48fdbee89d65f99833b11bd9b033c21b099e51f394b98d1aa96c4c51b9e0445c309a5b28f4f272c53174617e20b4e578dc602338c5a
6
+ metadata.gz: 5395eb43d9bc4a6aee0a18d498334a15475bd17cd976853bfb79c831eb55cdda6d68a9f8f04d62586d6d442004f0c74cef96f4f11e2ac53a08fba100813f989d
7
+ data.tar.gz: 8d8ed838367b768e7c18d47027f0b8a11d5728bf578339867b60411566dec0ada11294f9691008489f8fedaf971548d0c8bdc927f1b2f53f8f3de0a8e9a90b01
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.9.4
4
+
5
+ - Scaffold Custom Window via `glimmer scaffold:customwindow[name,namespace]`
6
+
7
+ ## 0.9.3
8
+
9
+ - Application Scaffolding via `glimmer scaffold[app_name]` includes a Model layer
10
+
3
11
  ## 0.9.2
4
12
 
5
13
  - Add `glimmer` commands `glimmer package:gem`, `glimmer package:gemspec`, and `glimmer package:clean`
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.9.2
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.9.4
2
2
  ## Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library ([Fukuoka Award Winning](http://www.digitalfukuoka.jp/topics/187?locale=ja))
3
3
  ### The Quickest Way From Zero To GUI
4
4
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
@@ -351,6 +351,7 @@ Learn more about the differences between various [Glimmer](https://github.com/An
351
351
  - [Run Application](#run-application)
352
352
  - [Run Examples](#run-examples)
353
353
  - [Scaffold Application](#scaffold-application)
354
+ - [Scaffold Custom Window](#scaffold-custom-window)
354
355
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
355
356
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
356
357
  - [API](#api)
@@ -421,7 +422,7 @@ gem install glimmer-dsl-libui
421
422
  Or install via Bundler `Gemfile`:
422
423
 
423
424
  ```ruby
424
- gem 'glimmer-dsl-libui', '~> 0.9.2'
425
+ gem 'glimmer-dsl-libui', '~> 0.9.4'
425
426
  ```
426
427
 
427
428
  Test that installation worked by running the [Glimmer Meta-Example](#examples):
@@ -625,7 +626,7 @@ Scaffold Glimmer DSL for LibUI application with this command:
625
626
  glimmer "scaffold[app_name]"
626
627
  ```
627
628
 
628
- That will generate the general MVC structure of a new Glimmer DSL for LibUI application.
629
+ That will automatically generate the general MVC structure of a new Glimmer DSL for LibUI application and launch the application when done.
629
630
 
630
631
  For example, if we run:
631
632
 
@@ -645,6 +646,7 @@ Created hello_world/Gemfile
645
646
  Created hello_world/Rakefile
646
647
  Created hello_world/app/hello_world.rb
647
648
  Created hello_world/app/hello_world/view/hello_world.rb
649
+ Created hello_world/app/hello_world/model/greeting.rb
648
650
  Created hello_world/icons/windows/Hello World.ico
649
651
  Created hello_world/icons/macosx/Hello World.icns
650
652
  Created hello_world/icons/linux/Hello World.png
@@ -655,8 +657,19 @@ Created hello_world/bin/hello_world
655
657
  They include a basic Hello, World! application with menus and about/preferences dialogs.
656
658
 
657
659
  Views live under `app/app_name/view` (e.g. `app/hello_world/view`)
660
+
658
661
  Models live under `app/app_name/model` (e.g. `app/hello_world/model`)
659
662
 
663
+ The application runs automatically once scaffolding is done.
664
+
665
+ ![glimmer-dsl-libui-mac-scaffold-app-initial-screen.png](images/glimmer-dsl-libui-mac-scaffold-app-initial-screen.png)
666
+
667
+ ![glimmer-dsl-libui-mac-scaffold-app-preferences.png](images/glimmer-dsl-libui-mac-scaffold-app-preferences.png)
668
+
669
+ ![glimmer-dsl-libui-mac-scaffold-app-changed-greeting.png](images/glimmer-dsl-libui-mac-scaffold-app-changed-greeting.png)
670
+
671
+ ![glimmer-dsl-libui-mac-scaffold-app-about.png](images/glimmer-dsl-libui-mac-scaffold-app-about.png)
672
+
660
673
  Once you step into the application directory, you can run it in one of multiple ways:
661
674
 
662
675
  ```
@@ -677,11 +690,7 @@ glimmer run
677
690
 
678
691
  ![glimmer-dsl-libui-mac-scaffold-app-initial-screen.png](images/glimmer-dsl-libui-mac-scaffold-app-initial-screen.png)
679
692
 
680
- ![glimmer-dsl-libui-mac-scaffold-app-preferences.png](images/glimmer-dsl-libui-mac-scaffold-app-preferences.png)
681
-
682
- ![glimmer-dsl-libui-mac-scaffold-app-changed-greeting.png](images/glimmer-dsl-libui-mac-scaffold-app-changed-greeting.png)
683
-
684
- The application comes with `juwelier` for auto-generating an application gem from its `Rakefile` gem configuration.
693
+ The application comes with the [juwelier](https://rubygems.org/gems/juwelier) gem for auto-generating an application gem from the app `Rakefile` and `Gemfile` configuration (no need to manually declare gems in a gemspec... just use `Gemfile` normally and [juwelier](https://rubygems.org/gems/juwelier) takes care of the rest by generating an app gemspec automatically from `Gemfile`).
685
694
 
686
695
  You can package the newly scaffolded app as a Ruby gem by running this command:
687
696
 
@@ -721,6 +730,158 @@ hello_world
721
730
 
722
731
  ![glimmer-dsl-libui-mac-scaffold-app-initial-screen.png](images/glimmer-dsl-libui-mac-scaffold-app-initial-screen.png)
723
732
 
733
+ ### Scaffold Custom Window
734
+
735
+ When you are in a scaffolded application, you can scaffold a new custom window (a window that you can put anything in to represent a view concept in your application) by running this command:
736
+
737
+ ```
738
+ glimmer scaffold:customwindow[name,namespace]
739
+ ```
740
+
741
+ The name represents the custom window view class name (it can be underscored, and Glimmer will automatically classify it).
742
+
743
+ The namespace is optional and represents the module that the custom window view class will live under. If left off, the main application class namespace is used (e.g. the top-level `HelloWorld` class namespace for a `hello_world` application).
744
+
745
+ You can also use the shorter `cw` alias for `customwindow`:
746
+
747
+ ```
748
+ glimmer scaffold:cw[name,namespace]
749
+ ```
750
+
751
+ For example by running this command under a `hello_world` application:
752
+
753
+ ```
754
+ glimmer scaffold:cw[greeting_window]
755
+ ```
756
+
757
+ That will generate this class under `app/hello_world/view/greeting_window`:
758
+
759
+ ```ruby
760
+ class HelloWorld
761
+ module View
762
+ class GreetingWindow
763
+ include Glimmer::LibUI::CustomWindow
764
+
765
+
766
+ ## Add options like the following to configure CustomWindow by outside consumers
767
+ #
768
+ # options :title, :background_color
769
+ # option :width, default: 320
770
+ # option :height, default: 240
771
+
772
+ ## Use before_body block to pre-initialize variables to use in body and
773
+ # to setup application menu
774
+ #
775
+ # before_body do
776
+ #
777
+ # end
778
+
779
+ ## Use after_body block to setup observers for controls in body
780
+ #
781
+ # after_body do
782
+ #
783
+ # end
784
+
785
+ ## Add control content inside custom window body
786
+ ## Top-most control must be a window or another custom window
787
+ #
788
+ body {
789
+ window {
790
+ # Replace example content below with custom window content
791
+ content_size 240, 240
792
+ title 'Hello World'
793
+
794
+ margined true
795
+
796
+ label {
797
+ text 'Hello World'
798
+ }
799
+ }
800
+ }
801
+ end
802
+ end
803
+ end
804
+ ```
805
+
806
+ When the generated file is required in another view, the custom window keyword `greeting_window` become available and reusable, like by calling:
807
+
808
+ ```ruby
809
+ greeting_window.show
810
+ ```
811
+
812
+ Here is an example that generates a custom window with a namespace:
813
+
814
+ ```
815
+ glimmer scaffold:cw[train,station]
816
+ ```
817
+
818
+ That will generate this class under `app/station/view/train`:
819
+
820
+ ```ruby
821
+ module Station
822
+ module View
823
+ class Train
824
+ include Glimmer::LibUI::CustomWindow
825
+
826
+
827
+ ## Add options like the following to configure CustomWindow by outside consumers
828
+ #
829
+ # options :title, :background_color
830
+ # option :width, default: 320
831
+ # option :height, default: 240
832
+
833
+ ## Use before_body block to pre-initialize variables to use in body and
834
+ # to setup application menu
835
+ #
836
+ # before_body do
837
+ #
838
+ # end
839
+
840
+ ## Use after_body block to setup observers for controls in body
841
+ #
842
+ # after_body do
843
+ #
844
+ # end
845
+
846
+ ## Add control content inside custom window body
847
+ ## Top-most control must be a window or another custom window
848
+ #
849
+ body {
850
+ window {
851
+ # Replace example content below with custom window content
852
+ content_size 240, 240
853
+ title 'Station'
854
+
855
+ margined true
856
+
857
+ label {
858
+ text 'Station'
859
+ }
860
+ }
861
+ }
862
+ end
863
+ end
864
+ end
865
+ ```
866
+
867
+ When that file is required, the `train` keyword becomes available:
868
+
869
+ ```ruby
870
+ train.show
871
+ ```
872
+
873
+ If for whatever reason, you end up with 2 custom window views having the same name with different namespaces, then you can invoke the specific custom window you want by including the Ruby namespace in underscored format separated by double-underscores:
874
+
875
+ ```ruby
876
+ station__view__train.show
877
+ ```
878
+
879
+ Or another `train` custom window view:
880
+
881
+ ```ruby
882
+ hello_world__view__train.show
883
+ ```
884
+
724
885
  ## Girb (Glimmer IRB)
725
886
 
726
887
  You can run the `girb` command (`bin/girb` if you cloned the project locally) to do some quick and dirty experimentation and learning:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.4
Binary file
@@ -155,6 +155,7 @@ module Glimmer
155
155
  mkdir_p "app/#{file_name(app_name)}/model"
156
156
  mkdir_p "app/#{file_name(app_name)}/view"
157
157
  custom_window(class_name(app_name), current_dir_name, window_type, custom_window_class_name: 'Application')
158
+ application_model(current_dir_name)
158
159
 
159
160
  mkdir_p 'icons/windows'
160
161
  icon_file = "icons/windows/#{human_name(app_name)}.ico"
@@ -366,6 +367,16 @@ module Glimmer
366
367
  puts 'Run `rake build` to build gem.'
367
368
  puts 'Run `rake release` to release into rubygems.org once ready.'
368
369
  end
370
+
371
+ def application_model(current_dir_name)
372
+ model_name = 'Greeting'
373
+ namespace ||= current_dir_name
374
+ root_dir = File.exist?('app') ? 'app' : 'lib'
375
+ parent_dir = "#{root_dir}/#{file_name(namespace)}/model"
376
+ return puts("The file '#{parent_dir}/#{file_name(model_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(model_name)}.rb")
377
+ mkdir_p parent_dir unless File.exist?(parent_dir)
378
+ write "#{parent_dir}/#{file_name(model_name)}.rb", model_file(model_name, namespace)
379
+ end
369
380
 
370
381
  private
371
382
 
@@ -527,7 +538,16 @@ module Glimmer
527
538
  window_options[:custom_window_class_name] ||= 'CustomWindow'
528
539
  namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
529
540
 
530
- custom_window_file_content = <<-MULTI_LINE_STRING
541
+ custom_window_file_content = ''
542
+
543
+ if %i[gem app].include?(window_type)
544
+ custom_window_file_content += <<-MULTI_LINE_STRING
545
+ require '#{current_dir_name}/model/greeting'
546
+
547
+ MULTI_LINE_STRING
548
+ end
549
+
550
+ custom_window_file_content += <<-MULTI_LINE_STRING
531
551
  #{namespace_type} #{class_name(namespace)}
532
552
  module View
533
553
  class #{class_name(custom_window_name)}
@@ -543,15 +563,6 @@ module Glimmer
543
563
  MULTI_LINE_STRING
544
564
  end
545
565
 
546
- if %i[gem app].include?(window_type)
547
- custom_window_file_content += <<-MULTI_LINE_STRING
548
- GREETINGS = [
549
- 'Hello, World!',
550
- 'Howdy, Partner!'
551
- ]
552
- MULTI_LINE_STRING
553
- end
554
-
555
566
  custom_window_file_content += <<-MULTI_LINE_STRING
556
567
 
557
568
  ## Add options like the following to configure CustomWindow by outside consumers
@@ -561,14 +572,6 @@ module Glimmer
561
572
  # option :height, default: 240
562
573
  MULTI_LINE_STRING
563
574
 
564
- if %i[gem app].include?(window_type)
565
- custom_window_file_content += <<-MULTI_LINE_STRING
566
-
567
- # GREETING Array selected index
568
- option :greeting_index, default: 0
569
- MULTI_LINE_STRING
570
- end
571
-
572
575
  custom_window_file_content += <<-MULTI_LINE_STRING
573
576
 
574
577
  ## Use before_body block to pre-initialize variables to use in body and
@@ -579,6 +582,8 @@ module Glimmer
579
582
  if %i[gem app].include?(window_type)
580
583
  custom_window_file_content += <<-MULTI_LINE_STRING
581
584
  before_body do
585
+ @greeting = Model::Greeting.new
586
+
582
587
  menu('File') {
583
588
  menu_item('Preferences...') {
584
589
  on_clicked do
@@ -634,7 +639,7 @@ module Glimmer
634
639
  margined true
635
640
 
636
641
  label {
637
- text <= [self, :greeting_index, on_read: -> { greeting }]
642
+ #{%i[gem app].include?(window_type) ? "text <= [@greeting, :text]" : "text '#{human_name(custom_window_name)}'"}
638
643
  }
639
644
  }
640
645
  }
@@ -643,10 +648,6 @@ module Glimmer
643
648
  if %i[gem app].include?(window_type)
644
649
  custom_window_file_content += <<-MULTI_LINE_STRING
645
650
 
646
- def greeting
647
- GREETINGS[greeting_index]
648
- end
649
-
650
651
  def display_about_dialog
651
652
  message = "#{human_name(namespace)}#{" - #{human_name(custom_window_name)}" if window_type == :gem} \#{VERSION}\\n\\n\#{LICENSE}"
652
653
  msg_box('About', message)
@@ -674,8 +675,8 @@ module Glimmer
674
675
  radio_buttons {
675
676
  stretchy false
676
677
 
677
- items GREETINGS
678
- selected <=> [self, :greeting_index]
678
+ items Model::Greeting::GREETINGS
679
+ selected <=> [@greeting, :text_index]
679
680
  }
680
681
  }
681
682
  }.show
@@ -790,6 +791,37 @@ end
790
791
  MULTI_LINE_STRING
791
792
  end
792
793
 
794
+ def model_file(model_name, namespace)
795
+ namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
796
+
797
+ <<-MULTI_LINE_STRING
798
+ #{namespace_type} #{class_name(namespace)}
799
+ module Model
800
+ class #{class_name(model_name)}
801
+ GREETINGS = [
802
+ 'Hello, World!',
803
+ 'Howdy, Partner!'
804
+ ]
805
+
806
+ attr_accessor :text
807
+
808
+ def initialize
809
+ @text = GREETINGS.first
810
+ end
811
+
812
+ def text_index=(new_text_index)
813
+ self.text = GREETINGS[new_text_index]
814
+ end
815
+
816
+ def text_index
817
+ GREETINGS.index(text)
818
+ end
819
+ end
820
+ end
821
+ end
822
+ MULTI_LINE_STRING
823
+ end
824
+
793
825
  end
794
826
 
795
827
  end
@@ -93,16 +93,16 @@ namespace :glimmer do
93
93
  Glimmer::RakeTask::Scaffold.app(args[:app_name])
94
94
  end
95
95
 
96
- # namespace :scaffold do
97
- # desc 'Scaffold Glimmer::UI::CustomWindow subclass (full window view) under app/views (namespace is optional) [alt: scaffold:cw]'
98
- # task :customwindow, [:name, :namespace] do |t, args|
99
- # require_relative 'rake_task/scaffold'
100
- # Glimmer::RakeTask::Scaffold.custom_window(args[:name], args[:namespace])
101
- # end
102
- #
103
- # task :cw, [:name, :namespace] => :customwindow
104
- # task :custom_window, [:name, :namespace] => :customwindow
105
- # task :"custom-window", [:name, :namespace] => :customwindow
96
+ namespace :scaffold do
97
+ desc 'Scaffold Glimmer::UI::CustomWindow subclass (full window view) under app/views (namespace is optional) [alt: scaffold:cw]'
98
+ task :customwindow, [:name, :namespace] do |t, args|
99
+ require_relative 'rake_task/scaffold'
100
+ Glimmer::RakeTask::Scaffold.custom_window(args[:name], args[:namespace])
101
+ end
102
+
103
+ task :cw, [:name, :namespace] => :customwindow
104
+ task :custom_window, [:name, :namespace] => :customwindow
105
+ task :"custom-window", [:name, :namespace] => :customwindow
106
106
  #
107
107
  # desc 'Scaffold Glimmer::UI::CustomControl subclass (part of a view) under app/views (namespace is optional) [alt: scaffold:cc]'
108
108
  # task :customcontrol, [:name, :namespace] do |t, args|
@@ -159,7 +159,7 @@ namespace :glimmer do
159
159
  # task :custom_window_gem, [:name, :namespace] => 'gem:customwindow'
160
160
  # task :custom_control_gem, [:name, :namespace] => 'gem:customcontrol'
161
161
  # task :custom_shape_gem, [:name, :namespace] => 'gem:customshape'
162
- # end
162
+ end
163
163
 
164
164
  namespace :list do
165
165
  task :list_require do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2023-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer