glimmer-dsl-web 0.0.6 → 0.0.7

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.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -21,7 +21,7 @@
21
21
 
22
22
  require 'glimmer-dsl-web'
23
23
 
24
- Address = Struct.new(:street, :street2, :city, :state, :zip_code, keyword_init: true) do
24
+ Address = Struct.new(:street, :street2, :city, :state, :zip_code, :billing_and_shipping, keyword_init: true) do
25
25
  STATES = {
26
26
  "AK"=>"Alaska",
27
27
  "AL"=>"Alabama",
@@ -89,7 +89,10 @@ Address = Struct.new(:street, :street2, :city, :state, :zip_code, keyword_init:
89
89
  end
90
90
 
91
91
  def summary
92
- values.map(&:to_s).reject(&:empty?).join(', ')
92
+ string_attributes = to_h.except(:billing_and_shipping)
93
+ summary = string_attributes.values.map(&:to_s).reject(&:empty?).join(', ')
94
+ summary += " (Billing & Shipping)" if billing_and_shipping
95
+ summary
93
96
  end
94
97
  end
95
98
 
@@ -98,14 +101,15 @@ end
98
101
  street2: 'Apartment 3C, 2nd door to the right',
99
102
  city: 'San Diego',
100
103
  state: 'California',
101
- zip_code: '91911'
104
+ zip_code: '91911',
105
+ billing_and_shipping: true,
102
106
  )
103
107
 
104
108
  include Glimmer
105
109
 
106
110
  Document.ready? do
107
111
  div {
108
- form(style: 'display: grid; grid-auto-columns: 80px 200px;') { |address_form|
112
+ div(style: 'display: grid; grid-auto-columns: 80px 260px;') { |address_div|
109
113
  label('Street: ', for: 'street-field')
110
114
  input(id: 'street-field') {
111
115
  # Bidirectional Data-Binding with <=> ensures input.value and @address.street
@@ -139,16 +143,25 @@ Document.ready? do
139
143
  # on_write option specifies :to_s method to invoke on value before writing to model attribute
140
144
  # to ensure the numeric zip code value is stored as a String
141
145
  value <=> [@address, :zip_code,
142
- on_write: :to_s
146
+ on_write: :to_s,
143
147
  ]
144
148
  }
145
149
 
150
+ div(style: 'grid-column: 1 / span 2') {
151
+ input(id: 'billing-and-shipping-field', type: 'checkbox') {
152
+ checked <=> [@address, :billing_and_shipping]
153
+ }
154
+ label(for: 'billing-and-shipping-field') {
155
+ 'Use this address for both Billing & Shipping'
156
+ }
157
+ }
158
+
146
159
  style {
147
160
  <<~CSS
148
- .#{address_form.element_id} * {
161
+ #{address_div.selector} * {
149
162
  margin: 5px;
150
163
  }
151
- .#{address_form.element_id} input, .#{address_form.element_id} select {
164
+ #{address_div.selector} input, #{address_div.selector} select {
152
165
  grid-column: 2;
153
166
  }
154
167
  CSS
@@ -156,10 +169,12 @@ Document.ready? do
156
169
  }
157
170
 
158
171
  div(style: 'margin: 5px') {
159
- # Unidirectional Data-Binding is done with <= to ensure @address.summary changes update div.inner_text
160
- # as computed by changes to the address member attributes + state_code address custom attribute
172
+ # Unidirectional Data-Binding is done with <= to ensure @address.summary changes
173
+ # automatically update div.inner_text
174
+ # (computed by changes to address attributes, meaning if street changes,
175
+ # @address.summary is automatically recomputed.)
161
176
  inner_text <= [@address, :summary,
162
- computed_by: @address.members + ['state_code']
177
+ computed_by: @address.members + ['state_code'],
163
178
  ]
164
179
  }
165
180
  }.render
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -0,0 +1,117 @@
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer-dsl-web'
23
+
24
+ class TimePresenter
25
+ attr_accessor :date_time, :month_string, :week_string
26
+
27
+ def initialize
28
+ @date_time = Time.now
29
+ end
30
+
31
+ def month_string
32
+ @date_time&.strftime('%Y-%m')
33
+ end
34
+
35
+ def month_string=(value)
36
+ if value.match(/^\d{4}-\d{2}$/)
37
+ year, month = value.split('-')
38
+ self.date_time = Time.new(year, month, date_time.day, date_time.hour, date_time.min)
39
+ end
40
+ end
41
+
42
+ def week_string
43
+ return nil if @date_time.nil?
44
+ year = @date_time.year
45
+ week = ((@date_time.yday / 7).to_i + 1).to_s.rjust(2, '0')
46
+ "#{year}-W#{week}"
47
+ end
48
+
49
+ def date_time_string
50
+ @date_time&.strftime('%Y-%m-%dT%H:%M')
51
+ end
52
+
53
+ def date_time_string=(value)
54
+ if value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/)
55
+ date_time_parts = value.split('T')
56
+ date_parts = date_time_parts.first.split('-')
57
+ time_parts = date_time_parts.last.split(':')
58
+ self.date_time = Time.new(*date_parts, *time_parts)
59
+ end
60
+ end
61
+ end
62
+
63
+ @time_presenter = TimePresenter.new
64
+
65
+ include Glimmer
66
+
67
+ Document.ready? do
68
+ div {
69
+ div(style: 'display: grid; grid-auto-columns: 130px 260px;') { |container_div|
70
+ label('Date Time: ', for: 'date-time-field')
71
+ input(id: 'date-time-field', type: 'datetime-local') {
72
+ # Bidirectional Data-Binding with <=> ensures input.value and @time_presenter.date_time
73
+ # automatically stay in sync when either side changes
74
+ value <=> [@time_presenter, :date_time]
75
+ }
76
+
77
+ label('Date: ', for: 'date-field')
78
+ input(id: 'date-field', type: 'date') {
79
+ value <=> [@time_presenter, :date_time]
80
+ }
81
+
82
+ label('Time: ', for: 'time-field')
83
+ input(id: 'time-field', type: 'time') {
84
+ value <=> [@time_presenter, :date_time]
85
+ }
86
+
87
+ label('Month: ', for: 'month-field')
88
+ input(id: 'month-field', type: 'month') {
89
+ value <=> [@time_presenter, :month_string, computed_by: :date_time]
90
+ }
91
+
92
+ label('Week: ', for: 'week-field')
93
+ input(id: 'week-field', type: 'week', disabled: true) {
94
+ value <=> [@time_presenter, :week_string, computed_by: :date_time]
95
+ }
96
+
97
+ label('Time String: ', for: 'time-string-field')
98
+ input(id: 'time-string-field', type: 'text') {
99
+ value <=> [@time_presenter, :date_time_string, computed_by: :date_time]
100
+ }
101
+
102
+ style {
103
+ <<~CSS
104
+ #{container_div.selector} * {
105
+ margin: 5px;
106
+ }
107
+ #{container_div.selector} label {
108
+ grid-column: 1;
109
+ }
110
+ #{container_div.selector} input {
111
+ grid-column: 2;
112
+ }
113
+ CSS
114
+ }
115
+ }
116
+ }.render
117
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-01 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -241,6 +241,7 @@ files:
241
241
  - lib/glimmer-dsl-web/samples/hello/hello_button.rb
242
242
  - lib/glimmer-dsl-web/samples/hello/hello_data_binding.rb
243
243
  - lib/glimmer-dsl-web/samples/hello/hello_form.rb
244
+ - lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb
244
245
  - lib/glimmer-dsl-web/samples/hello/hello_world.rb
245
246
  - lib/glimmer-dsl-web/vendor/jquery.js
246
247
  - lib/glimmer/config/opal_logger.rb
@@ -260,7 +261,6 @@ files:
260
261
  - lib/glimmer/web/element_proxy.rb
261
262
  - lib/glimmer/web/event_proxy.rb
262
263
  - lib/glimmer/web/listener_proxy.rb
263
- - lib/glimmer/web/property_owner.rb
264
264
  homepage: http://github.com/AndyObtiva/glimmer-dsl-web
265
265
  licenses:
266
266
  - MIT
@@ -1,24 +0,0 @@
1
- module Glimmer
2
- module Web
3
- # Adapts Glimmer UI classes to SWT JavaBean property owner classes (which are now adapted to Opal)
4
- module PropertyOwner
5
- # TODO consider adding has_attribute?
6
-
7
- def get_attribute(attribute_name)
8
- send(attribute_getter(attribute_name))
9
- end
10
-
11
- def set_attribute(attribute_name, *args)
12
- send(attribute_setter(attribute_name), *args) unless args.size == 1 && send(attribute_getter(attribute_name)) == args.first
13
- end
14
-
15
- def attribute_setter(attribute_name)
16
- "#{attribute_name.to_s.underscore}="
17
- end
18
-
19
- def attribute_getter(attribute_name)
20
- attribute_name.to_s.underscore
21
- end
22
- end
23
- end
24
- end