glimmer-dsl-web 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2020-2022 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
+ module Glimmer
23
+ module Web
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ class Class
2
+ def inherited(klass)
3
+ @descendants ||= []
4
+ @descendants << klass
5
+ end
6
+
7
+ def descendants
8
+ @descendants.to_collection.map { |klass| [klass] + (klass.descendants if klass.respond_to?(:descendants)).to_a }.flatten.compact
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ # TODO double check if the latest Opal implemented everything below already
2
+ require 'date'
3
+ require 'time'
4
+
5
+ class DateTime < Date
6
+ def initialize(*args, &block)
7
+ @time = Time.new(*args, &block)
8
+ methods_to_exclude = [:to_date, :to_time, :==, :eql?, :class] + Object.new.methods
9
+ methods_to_define = @time.methods - methods_to_exclude
10
+ methods_to_define.each do |method_name|
11
+ singleton_class.define_method(method_name) do |*args, &block|
12
+ @time.send(method_name, *args, &block)
13
+ end
14
+ end
15
+ end
16
+
17
+ def to_date
18
+ @time.to_date
19
+ end
20
+
21
+ def to_time
22
+ @time
23
+ end
24
+
25
+ def ==(other)
26
+ return false if other.class != self.class
27
+ year == other.year and
28
+ month == other.month and
29
+ day == other.day and
30
+ hour == other.hour and
31
+ min == other.min and
32
+ sec == other.sec
33
+ end
34
+ alias eql? ==
35
+ end
36
+
37
+ class Date
38
+ def to_datetime
39
+ # TODO support timezone
40
+ DateTime.new(year, month, day, hour, min, sec)
41
+ end
42
+ end
43
+
44
+ class Time
45
+ class << self
46
+ alias new_original new
47
+ def new(*args)
48
+ if args.size >= 7
49
+ Glimmer::Config.logger.debug "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!"
50
+ args = args[0...6]
51
+ end
52
+ new_original(*args)
53
+ end
54
+ end
55
+
56
+ def to_datetime
57
+ # TODO support timezone
58
+ DateTime.new(year, month, day, hour, min, sec)
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ # TODO double check if the latest Opal implemented everything below already
2
+ class Exception
3
+ def full_message
4
+ backtrace.join("\n")
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2020-2022 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
+ include Glimmer
23
+
24
+ shell {
25
+ text 'Glimmer'
26
+ label {
27
+ text 'Hello, World!'
28
+ }
29
+ }.open