glimmer-dsl-opal 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +95 -20
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal.rb +10 -8
- data/lib/glimmer/data_binding/element_binding.rb +35 -0
- data/lib/glimmer/data_binding/observable_element.rb +14 -0
- data/lib/glimmer/dsl/opal/bind_expression.rb +37 -0
- data/lib/glimmer/dsl/opal/button_expression.rb +17 -0
- data/lib/glimmer/dsl/opal/combo_expression.rb +17 -0
- data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +40 -0
- data/lib/glimmer/dsl/opal/composite_expression.rb +17 -0
- data/lib/glimmer/dsl/opal/data_binding_expression.rb +34 -0
- data/lib/glimmer/dsl/opal/dsl.rb +9 -0
- data/lib/glimmer/dsl/opal/label_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/property_expression.rb +1 -1
- data/lib/glimmer/dsl/opal/shell_expression.rb +2 -2
- data/lib/glimmer/dsl/opal/widget_listener_expression.rb +18 -0
- data/lib/glimmer/opal/div_proxy.rb +14 -0
- data/lib/glimmer/opal/{shell.rb → document_proxy.rb} +19 -5
- data/lib/glimmer/opal/element_proxy.rb +52 -0
- data/lib/glimmer/opal/event_listener_proxy.rb +18 -0
- data/lib/glimmer/opal/input_proxy.rb +30 -0
- data/lib/glimmer/opal/label_proxy.rb +24 -0
- data/lib/glimmer/opal/select_proxy.rb +58 -0
- data/lib/samples/elaborate/contact_manager.rb +95 -0
- data/lib/samples/elaborate/contact_manager/contact.rb +11 -0
- data/lib/samples/elaborate/contact_manager/contact_manager_presenter.rb +36 -0
- data/lib/samples/elaborate/contact_manager/contact_repository.rb +244 -0
- data/lib/samples/elaborate/launch +6 -0
- data/lib/samples/elaborate/login.rb +88 -0
- data/lib/samples/elaborate/tic_tac_toe.rb +53 -0
- data/lib/samples/elaborate/tic_tac_toe/board.rb +124 -0
- data/lib/samples/elaborate/tic_tac_toe/cell.rb +27 -0
- data/lib/samples/hello/hello_browser.rb +8 -0
- data/lib/samples/hello/hello_combo.rb +34 -0
- data/lib/samples/hello/hello_computed.rb +69 -0
- data/lib/samples/hello/hello_computed/contact.rb +21 -0
- data/lib/samples/hello/hello_list_multi_selection.rb +44 -0
- data/lib/samples/hello/hello_list_single_selection.rb +34 -0
- data/lib/samples/hello/hello_tab.rb +24 -0
- data/lib/samples/hello/hello_world.rb +8 -0
- data/lib/samples/hello/launch +10 -0
- data/lib/samples/launch +4 -0
- metadata +39 -6
- data/lib/glimmer/opal/label.rb +0 -31
@@ -0,0 +1,244 @@
|
|
1
|
+
require_relative "contact"
|
2
|
+
|
3
|
+
class ContactManager
|
4
|
+
class ContactRepository
|
5
|
+
NAMES_FIRST = %w[
|
6
|
+
Liam
|
7
|
+
Noah
|
8
|
+
William
|
9
|
+
James
|
10
|
+
Oliver
|
11
|
+
Benjamin
|
12
|
+
Elijah
|
13
|
+
Lucas
|
14
|
+
Mason
|
15
|
+
Logan
|
16
|
+
Alexander
|
17
|
+
Ethan
|
18
|
+
Jacob
|
19
|
+
Michael
|
20
|
+
Daniel
|
21
|
+
Henry
|
22
|
+
Jackson
|
23
|
+
Sebastian
|
24
|
+
Aiden
|
25
|
+
Matthew
|
26
|
+
Samuel
|
27
|
+
David
|
28
|
+
Joseph
|
29
|
+
Carter
|
30
|
+
Owen
|
31
|
+
Wyatt
|
32
|
+
John
|
33
|
+
Jack
|
34
|
+
Luke
|
35
|
+
Jayden
|
36
|
+
Dylan
|
37
|
+
Grayson
|
38
|
+
Levi
|
39
|
+
Isaac
|
40
|
+
Gabriel
|
41
|
+
Julian
|
42
|
+
Mateo
|
43
|
+
Anthony
|
44
|
+
Jaxon
|
45
|
+
Lincoln
|
46
|
+
Joshua
|
47
|
+
Christopher
|
48
|
+
Andrew
|
49
|
+
Theodore
|
50
|
+
Caleb
|
51
|
+
Ryan
|
52
|
+
Asher
|
53
|
+
Nathan
|
54
|
+
Thomas
|
55
|
+
Leo
|
56
|
+
Isaiah
|
57
|
+
Charles
|
58
|
+
Josiah
|
59
|
+
Hudson
|
60
|
+
Christian
|
61
|
+
Hunter
|
62
|
+
Connor
|
63
|
+
Eli
|
64
|
+
Ezra
|
65
|
+
Aaron
|
66
|
+
Landon
|
67
|
+
Adrian
|
68
|
+
Jonathan
|
69
|
+
Nolan
|
70
|
+
Jeremiah
|
71
|
+
Easton
|
72
|
+
Elias
|
73
|
+
Colton
|
74
|
+
Cameron
|
75
|
+
Carson
|
76
|
+
Robert
|
77
|
+
Angel
|
78
|
+
Maverick
|
79
|
+
Nicholas
|
80
|
+
Dominic
|
81
|
+
Jaxson
|
82
|
+
Greyson
|
83
|
+
Adam
|
84
|
+
Ian
|
85
|
+
Austin
|
86
|
+
Santiago
|
87
|
+
Jordan
|
88
|
+
Cooper
|
89
|
+
Brayden
|
90
|
+
Roman
|
91
|
+
Evan
|
92
|
+
Ezekiel
|
93
|
+
Xaviar
|
94
|
+
Jose
|
95
|
+
Jace
|
96
|
+
Jameson
|
97
|
+
Leonardo
|
98
|
+
Axel
|
99
|
+
Everett
|
100
|
+
Kayden
|
101
|
+
Miles
|
102
|
+
Sawyer
|
103
|
+
Jason
|
104
|
+
Emma
|
105
|
+
Olivia
|
106
|
+
Ava
|
107
|
+
Isabella
|
108
|
+
Sophia
|
109
|
+
Charlotte
|
110
|
+
Mia
|
111
|
+
Amelia
|
112
|
+
Harper
|
113
|
+
Evelyn
|
114
|
+
Abigail
|
115
|
+
Emily
|
116
|
+
Elizabeth
|
117
|
+
Mila
|
118
|
+
Ella
|
119
|
+
Avery
|
120
|
+
Sofia
|
121
|
+
Camila
|
122
|
+
Aria
|
123
|
+
Scarlett
|
124
|
+
Victoria
|
125
|
+
Madison
|
126
|
+
Luna
|
127
|
+
Grace
|
128
|
+
Chloe
|
129
|
+
Penelope
|
130
|
+
Layla
|
131
|
+
Riley
|
132
|
+
Zoey
|
133
|
+
Nora
|
134
|
+
Lily
|
135
|
+
Eleanor
|
136
|
+
Hannah
|
137
|
+
Lillian
|
138
|
+
Addison
|
139
|
+
Aubrey
|
140
|
+
Ellie
|
141
|
+
Stella
|
142
|
+
Natalie
|
143
|
+
Zoe
|
144
|
+
Leah
|
145
|
+
Hazel
|
146
|
+
Violet
|
147
|
+
Aurora
|
148
|
+
Savannah
|
149
|
+
Audrey
|
150
|
+
Brooklyn
|
151
|
+
Bella
|
152
|
+
Claire
|
153
|
+
Skylar
|
154
|
+
Lucy
|
155
|
+
Paisley
|
156
|
+
Everly
|
157
|
+
Anna
|
158
|
+
Caroline
|
159
|
+
Nova
|
160
|
+
Genesis
|
161
|
+
Emilia
|
162
|
+
Kennedy
|
163
|
+
Samantha
|
164
|
+
Maya
|
165
|
+
Willow
|
166
|
+
Kinsley
|
167
|
+
Naomi
|
168
|
+
Aaliyah
|
169
|
+
Elena
|
170
|
+
Sarah
|
171
|
+
Ariana
|
172
|
+
Allison
|
173
|
+
Gabriella
|
174
|
+
Alice
|
175
|
+
Madelyn
|
176
|
+
Cora
|
177
|
+
Ruby
|
178
|
+
Eva
|
179
|
+
Serenity
|
180
|
+
Autumn
|
181
|
+
Adeline
|
182
|
+
Hailey
|
183
|
+
Gianna
|
184
|
+
Valentina
|
185
|
+
Isla
|
186
|
+
Eliana
|
187
|
+
Quinn
|
188
|
+
Nevaeh
|
189
|
+
Ivy
|
190
|
+
Sadie
|
191
|
+
Piper
|
192
|
+
Lydia
|
193
|
+
Alexa
|
194
|
+
Josephine
|
195
|
+
Emery
|
196
|
+
Julia
|
197
|
+
Delilah
|
198
|
+
Arianna
|
199
|
+
Vivian
|
200
|
+
Kaylee
|
201
|
+
Sophie
|
202
|
+
Brielle
|
203
|
+
Madeline
|
204
|
+
]
|
205
|
+
NAMES_LAST = %w[
|
206
|
+
Smith
|
207
|
+
Johnson
|
208
|
+
Williams
|
209
|
+
Brown
|
210
|
+
Jones
|
211
|
+
Miller
|
212
|
+
Davis
|
213
|
+
Wilson
|
214
|
+
Anderson
|
215
|
+
Taylor
|
216
|
+
]
|
217
|
+
def initialize(contacts = nil)
|
218
|
+
@contacts = contacts || 1000.times.map do |n|
|
219
|
+
random_first_name_index = (rand*NAMES_FIRST.size).to_i
|
220
|
+
random_last_name_index = (rand*NAMES_LAST.size).to_i
|
221
|
+
first_name = NAMES_FIRST[random_first_name_index]
|
222
|
+
last_name = NAMES_LAST[random_last_name_index]
|
223
|
+
email = "#{first_name}@#{last_name}.com".downcase
|
224
|
+
Contact.new(
|
225
|
+
first_name: first_name,
|
226
|
+
last_name: last_name,
|
227
|
+
email: email
|
228
|
+
)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def find(attribute_filter_map)
|
233
|
+
@contacts.find_all do |contact|
|
234
|
+
match = true
|
235
|
+
attribute_filter_map.keys.each do |attribute_name|
|
236
|
+
contact_value = contact.send(attribute_name).downcase
|
237
|
+
filter_value = attribute_filter_map[attribute_name].downcase
|
238
|
+
match = false unless contact_value.match(filter_value)
|
239
|
+
end
|
240
|
+
match
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "java"
|
2
|
+
require "observer"
|
3
|
+
|
4
|
+
#Presents login screen data
|
5
|
+
class LoginPresenter
|
6
|
+
|
7
|
+
attr_accessor :user_name
|
8
|
+
attr_accessor :password
|
9
|
+
attr_accessor :status
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@user_name = ""
|
13
|
+
@password = ""
|
14
|
+
@status = "Logged Out"
|
15
|
+
end
|
16
|
+
|
17
|
+
def status=(status)
|
18
|
+
@status = status
|
19
|
+
|
20
|
+
#TODO add feature to bind dependent properties to master property (2017-07-25 nested data binding)
|
21
|
+
notify_observers("logged_in")
|
22
|
+
notify_observers("logged_out")
|
23
|
+
end
|
24
|
+
|
25
|
+
def logged_in
|
26
|
+
self.status == "Logged In"
|
27
|
+
end
|
28
|
+
|
29
|
+
def logged_out
|
30
|
+
!self.logged_in
|
31
|
+
end
|
32
|
+
|
33
|
+
def login
|
34
|
+
self.status = "Logged In"
|
35
|
+
end
|
36
|
+
|
37
|
+
def logout
|
38
|
+
self.user_name = ""
|
39
|
+
self.password = ""
|
40
|
+
self.status = "Logged Out"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
#Login screen
|
46
|
+
class Login
|
47
|
+
include Glimmer
|
48
|
+
|
49
|
+
def launch
|
50
|
+
presenter = LoginPresenter.new
|
51
|
+
@shell = shell {
|
52
|
+
text "Login"
|
53
|
+
composite {
|
54
|
+
grid_layout 2, false #two columns with differing widths
|
55
|
+
|
56
|
+
label { text "Username:" } # goes in column 1
|
57
|
+
text { # goes in column 2
|
58
|
+
text bind(presenter, :user_name)
|
59
|
+
enabled bind(presenter, :logged_out)
|
60
|
+
}
|
61
|
+
|
62
|
+
label { text "Password:" }
|
63
|
+
text(:password, :border) {
|
64
|
+
text bind(presenter, :password)
|
65
|
+
enabled bind(presenter, :logged_out)
|
66
|
+
}
|
67
|
+
|
68
|
+
label { text "Status:" }
|
69
|
+
label { text bind(presenter, :status) }
|
70
|
+
|
71
|
+
button {
|
72
|
+
text "Login"
|
73
|
+
enabled bind(presenter, :logged_out)
|
74
|
+
on_widget_selected { presenter.login }
|
75
|
+
}
|
76
|
+
|
77
|
+
button {
|
78
|
+
text "Logout"
|
79
|
+
enabled bind(presenter, :logged_in)
|
80
|
+
on_widget_selected { presenter.logout }
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
@shell.open
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
Login.new.launch
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative "tic_tac_toe/board"
|
2
|
+
|
3
|
+
class TicTacToe
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@tic_tac_toe_board = Board.new
|
8
|
+
@shell = shell {
|
9
|
+
text "Tic-Tac-Toe"
|
10
|
+
composite {
|
11
|
+
grid_layout 3, true
|
12
|
+
(1..3).each { |row|
|
13
|
+
(1..3).each { |column|
|
14
|
+
button {
|
15
|
+
layout_data :fill, :fill, true, true
|
16
|
+
text bind(@tic_tac_toe_board[row, column], :sign)
|
17
|
+
enabled bind(@tic_tac_toe_board[row, column], :empty)
|
18
|
+
on_widget_selected {
|
19
|
+
@tic_tac_toe_board.mark(row, column)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
observe(@tic_tac_toe_board, :game_status) { |game_status|
|
27
|
+
display_win_message if game_status == Board::WIN
|
28
|
+
display_draw_message if game_status == Board::DRAW
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_win_message
|
33
|
+
display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
|
34
|
+
end
|
35
|
+
|
36
|
+
def display_draw_message
|
37
|
+
display_game_over_message("Draw!")
|
38
|
+
end
|
39
|
+
|
40
|
+
def display_game_over_message(message)
|
41
|
+
message_box = MessageBox.new(@shell.swt_widget)
|
42
|
+
message_box.setText("Game Over")
|
43
|
+
message_box.setMessage(message)
|
44
|
+
message_box.open
|
45
|
+
@tic_tac_toe_board.reset
|
46
|
+
end
|
47
|
+
|
48
|
+
def open
|
49
|
+
@shell.open
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
TicTacToe.new.open
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require_relative 'cell'
|
2
|
+
|
3
|
+
class TicTacToe
|
4
|
+
class Board
|
5
|
+
DRAW = :draw
|
6
|
+
IN_PROGRESS = :in_progress
|
7
|
+
WIN = :win
|
8
|
+
attr :winning_sign
|
9
|
+
attr_accessor :game_status
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@sign_state_machine = {nil => "X", "X" => "O", "O" => "X"}
|
13
|
+
build_grid
|
14
|
+
@winning_sign = Cell::EMPTY
|
15
|
+
@game_status = IN_PROGRESS
|
16
|
+
end
|
17
|
+
|
18
|
+
#row and column numbers are 1-based
|
19
|
+
def mark(row, column)
|
20
|
+
self[row, column].mark(current_sign)
|
21
|
+
game_over? #updates winning sign
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_sign
|
25
|
+
@current_sign = @sign_state_machine[@current_sign]
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](row, column)
|
29
|
+
@grid[row-1][column-1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def game_over?
|
33
|
+
win? or draw?
|
34
|
+
end
|
35
|
+
|
36
|
+
def win?
|
37
|
+
win = (row_win? or column_win? or diagonal_win?)
|
38
|
+
self.game_status=WIN if win
|
39
|
+
win
|
40
|
+
end
|
41
|
+
|
42
|
+
def reset
|
43
|
+
(1..3).each do |row|
|
44
|
+
(1..3).each do |column|
|
45
|
+
self[row, column].reset
|
46
|
+
end
|
47
|
+
end
|
48
|
+
@winning_sign = Cell::EMPTY
|
49
|
+
@current_sign = nil
|
50
|
+
self.game_status=IN_PROGRESS
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def build_grid
|
56
|
+
@grid = []
|
57
|
+
3.times do |row_index| #0-based
|
58
|
+
@grid << []
|
59
|
+
3.times { @grid[row_index] << Cell.new }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def row_win?
|
64
|
+
(1..3).each do |row|
|
65
|
+
if row_has_same_sign(row)
|
66
|
+
@winning_sign = self[row, 1].sign
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def column_win?
|
74
|
+
(1..3).each do |column|
|
75
|
+
if column_has_same_sign(column)
|
76
|
+
@winning_sign = self[1, column].sign
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
false
|
81
|
+
end
|
82
|
+
|
83
|
+
#needs refactoring if we ever decide to make the board size dynamic
|
84
|
+
def diagonal_win?
|
85
|
+
if (self[1, 1].sign == self[2, 2].sign) and (self[2, 2].sign == self[3, 3].sign) and self[1, 1].marked
|
86
|
+
@winning_sign = self[1, 1].sign
|
87
|
+
return true
|
88
|
+
end
|
89
|
+
if (self[3, 1].sign == self[2, 2].sign) and (self[2, 2].sign == self[1, 3].sign) and self[3, 1].marked
|
90
|
+
@winning_sign = self[3, 1].sign
|
91
|
+
return true
|
92
|
+
end
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
def draw?
|
97
|
+
@board_full = true
|
98
|
+
3.times do |x|
|
99
|
+
3.times do |y|
|
100
|
+
@board_full = false if self[x, y].empty
|
101
|
+
end
|
102
|
+
end
|
103
|
+
self.game_status = DRAW if @board_full
|
104
|
+
@board_full
|
105
|
+
end
|
106
|
+
|
107
|
+
def row_has_same_sign(number)
|
108
|
+
row_sign = self[number, 1].sign
|
109
|
+
[2, 3].each do |column|
|
110
|
+
return false unless row_sign == (self[number, column].sign)
|
111
|
+
end
|
112
|
+
true if self[number, 1].marked
|
113
|
+
end
|
114
|
+
|
115
|
+
def column_has_same_sign(number)
|
116
|
+
column_sign = self[1, number].sign
|
117
|
+
[2, 3].each do |row|
|
118
|
+
return false unless column_sign == (self[row, number].sign)
|
119
|
+
end
|
120
|
+
true if self[1, number].marked
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|