glimmer-dsl-web 0.8.10 → 0.9.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +4 -3
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-web.gemspec +10 -2
  6. data/lib/glimmer/dsl/web/bind_expression.rb +0 -21
  7. data/lib/glimmer/dsl/web/component_slot_content_expression.rb +0 -21
  8. data/lib/glimmer/dsl/web/content_data_binding_expression.rb +0 -21
  9. data/lib/glimmer/dsl/web/dsl.rb +0 -21
  10. data/lib/glimmer/dsl/web/observe_expression.rb +0 -21
  11. data/lib/glimmer/helpers/glimmer_helper.rb +21 -0
  12. data/lib/glimmer/util/debounce.rb +34 -0
  13. data/lib/glimmer/util/proc_tracker.rb +0 -21
  14. data/lib/glimmer/util/url_builder.rb +0 -21
  15. data/lib/glimmer/util/url_query_string_builder.rb +0 -21
  16. data/lib/glimmer/web/component/back_link.rb +16 -0
  17. data/lib/glimmer/web/component/page_component.rb +32 -0
  18. data/lib/glimmer/web/component/page_component_button.rb +49 -0
  19. data/lib/glimmer/web/component/page_component_link.rb +49 -0
  20. data/lib/glimmer/web/component.rb +8 -21
  21. data/lib/glimmer/web/element_proxy.rb +5 -21
  22. data/lib/glimmer/web/event_proxy.rb +0 -21
  23. data/lib/glimmer/web/formatting_element_proxy.rb +0 -21
  24. data/lib/glimmer/web/listener_proxy.rb +0 -21
  25. data/lib/glimmer/web.rb +0 -21
  26. data/lib/glimmer-dsl-web/ext/kernel.rb +0 -21
  27. data/lib/glimmer-dsl-web/samples/hello/hello_button.rb +0 -21
  28. data/lib/glimmer-dsl-web/samples/hello/hello_component.rb +0 -21
  29. data/lib/glimmer-dsl-web/samples/hello/hello_component_attribute_data_binding.rb +0 -21
  30. data/lib/glimmer-dsl-web/samples/hello/hello_component_attribute_listeners.rb +0 -21
  31. data/lib/glimmer-dsl-web/samples/hello/hello_component_listeners.rb +0 -21
  32. data/lib/glimmer-dsl-web/samples/hello/hello_component_listeners_default_slot.rb +0 -21
  33. data/lib/glimmer-dsl-web/samples/hello/hello_component_slots.rb +0 -21
  34. data/lib/glimmer-dsl-web/samples/hello/hello_content_data_binding.rb +0 -21
  35. data/lib/glimmer-dsl-web/samples/hello/hello_data_binding.rb +0 -21
  36. data/lib/glimmer-dsl-web/samples/hello/hello_form.rb +0 -21
  37. data/lib/glimmer-dsl-web/samples/hello/hello_form_mvp.rb +0 -21
  38. data/lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb +0 -21
  39. data/lib/glimmer-dsl-web/samples/hello/hello_observer.rb +0 -21
  40. data/lib/glimmer-dsl-web/samples/hello/hello_observer_data_binding.rb +0 -21
  41. data/lib/glimmer-dsl-web/samples/hello/hello_page_component_link/conference_talk_page.rb +43 -0
  42. data/lib/glimmer-dsl-web/samples/hello/hello_page_component_link/conference_talks_page.rb +30 -0
  43. data/lib/glimmer-dsl-web/samples/hello/hello_page_component_link/models/conference_talk.rb +9 -0
  44. data/lib/glimmer-dsl-web/samples/hello/hello_paragraph.rb +0 -21
  45. data/lib/glimmer-dsl-web/samples/hello/hello_style.rb +0 -21
  46. data/lib/glimmer-dsl-web/samples/hello/hello_svg.rb +0 -21
  47. data/lib/glimmer-dsl-web/samples/hello/hello_world.rb +0 -21
  48. data/lib/glimmer-dsl-web.rb +3 -21
  49. data/lib/rails/resource_service.rb +9 -7
  50. metadata +9 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c899b0a787682edbeef45beea8eb4742b296026e9302927c7ee2dbd57486451e
4
- data.tar.gz: 4ec88fbe899b1beab079d7fcf7bed0ca0554db5448acc39e4bd42e07f830ab0b
3
+ metadata.gz: 481114ba7f1ac010cb7c751e3bad3fc70ee0e8353f8702ad8a86fd56a110b64d
4
+ data.tar.gz: be9b2ba00df78c89061b984f5437f32e5e0b7a87cdbcd34b8245837f722e01a5
5
5
  SHA512:
6
- metadata.gz: ea45917a51ea567c9a6acf3c77a0642dbe2edac020826923a3fd4433724384384e00ed87758dff1e9e4bb08b3ba5681f6dfc34ccb1577d06179d1895fedf4ac0
7
- data.tar.gz: 8abec79d203b6220589cbe4cbd04104332b1bcb99e6eef81af3c583295fa4ba1ae80aa01b05722e7bf21db183f600294d121f69b2e735cc3a43beb351b8006e1
6
+ metadata.gz: 8415b5c4fe8801512ee1e5e7d6c8d1a487dabd3420f920992ca547095aa75b59c35e0349a3a229568d91a22bdee0278cf9558de61d242f050e3e11492190d920
7
+ data.tar.gz: 3c14a0224d41730249213c2140c293a3fbb7f4f71f76d0573c84deb5218226cac2f073ba65e8bc19e0f970a38decc4e8166f46733e13d16d82c2fa2059864478
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.9.0
4
+
5
+ - page_component_link(text:, component_class:, component_attributes:, page_url:, css_id:, css_class:, css_style:) Glimmer Web Component to instantly render a new page component in the Frontend while changing the browser URL to a shareable bookmarkable URL
6
+ - page_component_button(text:, component_class:, component_attributes:, page_url:, css_id:, css_class:, css_style:) Glimmer Web Component to instantly render a new page component in the Frontend while changing the browser URL to a shareable bookmarkable URL
7
+ - back_link Glimmer Web Component that renders an anchor tag that can trigger the browser history back button
8
+ - `Glimmer::Util::Debounce.new(&work).call(delay: 300, debounce: true)` to support debouncing repetitive requests, such as those made by a text input filter.
9
+ - Normalize glimmer_component ActiveRecord::Base option values by calling as_json on them automatically
10
+ - Normalize glimmer_component ActiveRecord::Relation option values by calling to_a on them automatically
11
+ - Support `structure {}` as an alias for `markup {}` inside `Glimmer::Web::Component` implementors
12
+ - Hello, Page Component Link! sample
13
+
3
14
  ## 0.8.10
4
15
 
5
16
  - Remove unnecessary `puts` statements from `Rails::ResourceService`
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 Web 0.8.10 (Beta)
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 Web 0.9.0 (Beta)
2
2
  ## Ruby-in-the-Browser Web Frontend Framework
3
3
  ### The "Rails" of Frontend Frameworks!!! ([Fukuoka Award Winning](https://andymaleh.blogspot.com/2025/01/glimmer-dsl-for-web-wins-in-fukuoka.html))
4
4
  #### Finally, Ruby Developer Productivity, Happiness, and Fun in the Frontend!!!
@@ -1411,7 +1411,7 @@ Please follow these steps to setup.
1411
1411
  Install a Rails 7 gem:
1412
1412
 
1413
1413
  ```
1414
- gem install rails -v7.0.8.10
1414
+ gem install rails -v7.0.9.0
1415
1415
  ```
1416
1416
 
1417
1417
  Start a new Rails 7 app:
@@ -1423,7 +1423,8 @@ rails new glimmer_app_server
1423
1423
  Add the following to `Gemfile`:
1424
1424
 
1425
1425
  ```
1426
- gem 'glimmer-dsl-web', '~> 0.8.10'
1426
+ gem 'glimmer-dsl-web', '~> 0.9.0'
1427
+ gem 'opal-rails', '2.0.4' # for Rails 7 use of Sprockets
1427
1428
  ```
1428
1429
 
1429
1430
  Run:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.10
1
+ 0.9.0
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-web 0.8.10 ruby lib
5
+ # stub: glimmer-dsl-web 0.9.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.8.10".freeze
9
+ s.version = "0.9.0".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -50,6 +50,9 @@ Gem::Specification.new do |s|
50
50
  "lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb",
51
51
  "lib/glimmer-dsl-web/samples/hello/hello_observer.rb",
52
52
  "lib/glimmer-dsl-web/samples/hello/hello_observer_data_binding.rb",
53
+ "lib/glimmer-dsl-web/samples/hello/hello_page_component_link/conference_talk_page.rb",
54
+ "lib/glimmer-dsl-web/samples/hello/hello_page_component_link/conference_talks_page.rb",
55
+ "lib/glimmer-dsl-web/samples/hello/hello_page_component_link/models/conference_talk.rb",
53
56
  "lib/glimmer-dsl-web/samples/hello/hello_paragraph.rb",
54
57
  "lib/glimmer-dsl-web/samples/hello/hello_style.rb",
55
58
  "lib/glimmer-dsl-web/samples/hello/hello_svg.rb",
@@ -88,12 +91,17 @@ Gem::Specification.new do |s|
88
91
  "lib/glimmer/dsl/web/span_expression.rb",
89
92
  "lib/glimmer/dsl/web/style_element_expression.rb",
90
93
  "lib/glimmer/helpers/glimmer_helper.rb",
94
+ "lib/glimmer/util/debounce.rb",
91
95
  "lib/glimmer/util/proc_tracker.rb",
92
96
  "lib/glimmer/util/url_builder.rb",
93
97
  "lib/glimmer/util/url_query_string_builder.rb",
94
98
  "lib/glimmer/web.rb",
95
99
  "lib/glimmer/web/component.rb",
100
+ "lib/glimmer/web/component/back_link.rb",
96
101
  "lib/glimmer/web/component/component_style_container.rb",
102
+ "lib/glimmer/web/component/page_component.rb",
103
+ "lib/glimmer/web/component/page_component_button.rb",
104
+ "lib/glimmer/web/component/page_component_link.rb",
97
105
  "lib/glimmer/web/element_proxy.rb",
98
106
  "lib/glimmer/web/event_proxy.rb",
99
107
  "lib/glimmer/web/formatting_element_proxy.rb",
@@ -1,24 +1,3 @@
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
1
  require 'glimmer/dsl/static_expression'
23
2
  require 'glimmer/dsl/bind_expression'
24
3
  require 'glimmer/data_binding/model_binding'
@@ -1,24 +1,3 @@
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
1
  require 'glimmer'
23
2
  require 'glimmer/dsl/expression'
24
3
  require 'glimmer/web/component'
@@ -1,24 +1,3 @@
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
1
  require 'glimmer/dsl/expression'
23
2
 
24
3
  module Glimmer
@@ -1,24 +1,3 @@
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
1
  require 'glimmer/dsl/engine'
23
2
  require 'glimmer/dsl/web/element_expression'
24
3
  require 'glimmer/dsl/web/formatting_element_expression'
@@ -1,24 +1,3 @@
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
1
  require 'glimmer/dsl/static_expression'
23
2
  require 'glimmer/dsl/top_level_expression'
24
3
  require 'glimmer/dsl/observe_expression'
@@ -7,6 +7,7 @@ module GlimmerHelper
7
7
  end
8
8
 
9
9
  def glimmer_component(component_asset_path, *component_args)
10
+ normalize_active_record_relation_option_values!(component_args.last)
10
11
  component_file = component_asset_path.split('/').last # TODO support namespaced components
11
12
  component_class_name = component_file.classify # TODO support namespaced components
12
13
  next_id_number = GlimmerHelper.next_id_number
@@ -31,4 +32,24 @@ module GlimmerHelper
31
32
  content_tag(:script, raw(js_script), id: component_script_tag_id, type: 'application/javascript', "data-turbo-eval": "false", "data-component-args": component_args_json)
32
33
  end
33
34
  end
35
+
36
+ private
37
+
38
+ def normalize_active_record_relation_option_values!(option_values)
39
+ option_values&.each do |key, value|
40
+ if value.is_a?(ActiveRecord::Relation)
41
+ models = value.to_a
42
+ models = models.map do |model|
43
+ if model.is_a?(ActiveRecord::Base)
44
+ model.as_json
45
+ else
46
+ model
47
+ end
48
+ end
49
+ option_values[key] = models
50
+ elsif value.is_a?(ActiveRecord::Base)
51
+ option_values[key] = value.as_json
52
+ end
53
+ end
54
+ end
34
55
  end
@@ -0,0 +1,34 @@
1
+ module Glimmer
2
+ module Util
3
+ class Debounce
4
+ INTERVAL_CHECK_IN_MILLISECONDS = 50
5
+
6
+ attr_reader :work
7
+
8
+ def initialize(&work)
9
+ @work = work
10
+ end
11
+
12
+ def call(delay: 300, debounce: true)
13
+ if delay.nil? || delay == 0 || !debounce
14
+ @call_in_progress = @call_request_time = nil
15
+ work.call
16
+ return
17
+ end
18
+ @call_request_time = Time.now
19
+ return if @call_in_progress
20
+
21
+ @call_in_progress = true
22
+ debouncer = lambda do
23
+ if (Time.now - @call_request_time) < (delay / 1000.0)
24
+ Async::Timeout.new(INTERVAL_CHECK_IN_MILLISECONDS, &debouncer)
25
+ else
26
+ @call_in_progress = @call_request_time = nil
27
+ work.call
28
+ end
29
+ end
30
+ Async::Timeout.new(delay, &debouncer)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,24 +1,3 @@
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
1
  require 'delegate'
23
2
 
24
3
  module Glimmer
@@ -1,24 +1,3 @@
1
- # Copyright (c) 2023-2026 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
1
  # TODO consider extracting this class into its own Ruby gem
23
2
  require 'delegate'
24
3
 
@@ -1,24 +1,3 @@
1
- # Copyright (c) 2023-2026 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
1
  # TODO consider extracting this class into its own Ruby gem
23
2
  require 'delegate'
24
3
 
@@ -0,0 +1,16 @@
1
+ require 'glimmer-dsl-web'
2
+
3
+ class BackLink
4
+ include Glimmer::Web::Component
5
+
6
+ attribute :text, default: 'Back'
7
+
8
+ markup {
9
+ a(text, href: '') {
10
+ onclick do |event|
11
+ event.prevent_default
12
+ $$.history.back
13
+ end
14
+ }
15
+ }
16
+ end
@@ -0,0 +1,32 @@
1
+ module PageComponent
2
+ class << self
3
+ def page_url_to_component_mapping
4
+ unless defined?(@@page_url_to_component_mapping)
5
+ @@page_url_to_component_mapping = {}
6
+ end
7
+ @@page_url_to_component_mapping
8
+ end
9
+
10
+ def last_visible_page_components
11
+ unless defined?(@@last_visible_page_components)
12
+ @@last_visible_page_components = []
13
+ end
14
+ @@last_visible_page_components
15
+ end
16
+
17
+ def register_page_component_history_listener
18
+ unless defined?(@@registered_page_component_history_listener)
19
+ @@registered_page_component_history_listener = true
20
+ $$.addEventListener('popstate') do |event|
21
+ page_component = PageComponent.page_url_to_component_mapping[$$.document.location.href]
22
+ if page_component
23
+ visible_page_component = PageComponent.last_visible_page_components.pop
24
+ visible_page_component.markup_root.hide
25
+ page_component.markup_root.show
26
+ PageComponent.last_visible_page_components.push(page_component)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require 'glimmer/web/component/page_component'
2
+
3
+ class PageComponentButton
4
+ include Glimmer::Web::Component
5
+
6
+ attributes :text, :component_class, :component_attributes, :page_url, :css_id, :css_class, :css_style
7
+ attr_reader :original_page_component
8
+
9
+ before_render do
10
+ if self.page_url.start_with?('/')
11
+ self.page_url = "#{$$.document.location.origin}#{self.page_url}"
12
+ end
13
+ @button_tag_attributes = {href: page_url}
14
+ @button_tag_attributes[:id] = css_id if css_id
15
+ @button_tag_attributes[:class] = css_class if css_class
16
+ @button_tag_attributes[:style] = css_style if css_style
17
+ end
18
+
19
+ after_render do
20
+ @original_page_component = root_component
21
+ end
22
+
23
+ markup {
24
+ button(text, **@button_tag_attributes) {
25
+ onclick do |event|
26
+ event.prevent_default
27
+ page_component = nil
28
+ if component_attributes.nil?
29
+ page_component = PageComponent.page_url_to_component_mapping[page_url]
30
+ if page_component
31
+ page_component.markup_root.show
32
+ else
33
+ $$.document.location = page_url
34
+ end
35
+ else
36
+ page_component = component_class.render(component_attributes)
37
+ end
38
+ if page_component
39
+ PageComponent.last_visible_page_components.push(page_component)
40
+ PageComponent.page_url_to_component_mapping[$$.document.location.href] = original_page_component
41
+ PageComponent.page_url_to_component_mapping[page_url] = page_component
42
+ $$.history.pushState({page_component_selector: page_component.markup_root.selector, original_page_component_selector: original_page_component.markup_root.selector}, "title 1", page_url)
43
+ original_page_component.markup_root.hide
44
+ PageComponent.register_page_component_history_listener
45
+ end
46
+ end
47
+ }
48
+ }
49
+ end
@@ -0,0 +1,49 @@
1
+ require 'glimmer/web/component/page_component'
2
+
3
+ class PageComponentLink
4
+ include Glimmer::Web::Component
5
+
6
+ attributes :text, :component_class, :component_attributes, :page_url, :css_id, :css_class, :css_style
7
+ attr_reader :original_page_component
8
+
9
+ before_render do
10
+ if self.page_url.start_with?('/')
11
+ self.page_url = "#{$$.document.location.origin}#{self.page_url}"
12
+ end
13
+ @anchor_tag_attributes = {href: page_url}
14
+ @anchor_tag_attributes[:id] = css_id if css_id
15
+ @anchor_tag_attributes[:class] = css_class if css_class
16
+ @anchor_tag_attributes[:style] = css_style if css_style
17
+ end
18
+
19
+ after_render do
20
+ @original_page_component = root_component
21
+ end
22
+
23
+ markup {
24
+ a(text, **@anchor_tag_attributes) {
25
+ onclick do |event|
26
+ event.prevent_default
27
+ page_component = nil
28
+ if component_attributes.nil?
29
+ page_component = PageComponent.page_url_to_component_mapping[page_url]
30
+ if page_component
31
+ page_component.markup_root.show
32
+ else
33
+ $$.document.location = page_url
34
+ end
35
+ else
36
+ page_component = component_class.render(component_attributes)
37
+ end
38
+ if page_component
39
+ PageComponent.last_visible_page_components.push(page_component)
40
+ PageComponent.page_url_to_component_mapping[$$.document.location.href] = original_page_component
41
+ PageComponent.page_url_to_component_mapping[page_url] = page_component
42
+ $$.history.pushState({page_component_selector: page_component.markup_root.selector, original_page_component_selector: original_page_component.markup_root.selector}, "title 1", page_url)
43
+ original_page_component.markup_root.hide
44
+ PageComponent.register_page_component_history_listener
45
+ end
46
+ end
47
+ }
48
+ }
49
+ end
@@ -1,24 +1,3 @@
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
1
  require 'glimmer'
23
2
  require 'glimmer/error'
24
3
  require 'glimmer/util/proc_tracker'
@@ -79,6 +58,7 @@ module Glimmer
79
58
  def markup(&block)
80
59
  @markup_block = block
81
60
  end
61
+ alias structure markup
82
62
 
83
63
  # TODO in the future support a string value too
84
64
  def style(&block)
@@ -129,6 +109,7 @@ module Glimmer
129
109
  ".#{component_element_class}"
130
110
  end
131
111
  alias component_markup_root_selector component_element_selector
112
+ alias component_structure_root_selector component_element_selector
132
113
 
133
114
  def component_shortcut_element_class
134
115
  self.shortcut_keyword.gsub('_', '-')
@@ -153,6 +134,7 @@ module Glimmer
153
134
  # This module was only created to prevent Glimmer from checking method_missing first
154
135
  module GlimmerSupersedable
155
136
  def method_missing(method_name, *args, &block)
137
+ # TODO think of a way to hide the unnecessary exception noise that is printed to the user in the browser console whenever this is triggered
156
138
  Glimmer::DSL::Engine.interpret(method_name, *args, &block)
157
139
  rescue
158
140
  super(method_name, *args, &block)
@@ -287,6 +269,7 @@ module Glimmer
287
269
 
288
270
  attr_reader :markup_root, :parent, :args, :options, :style_block, :component_style, :slot_elements, :events, :default_slot
289
271
  alias parent_proxy parent
272
+ alias structure_root markup_root
290
273
 
291
274
  def initialize(parent, args, options, &content)
292
275
  Glimmer::Web::Component.add_component(self)
@@ -561,6 +544,10 @@ module Glimmer
561
544
  end
562
545
  "#<#{self.class}:0x#{object_id.to_s(16)} #{markup_root&.keyword}##{markup_root&.element_id} #{attributes}>"
563
546
  end
547
+
548
+ def root_component
549
+ (markup_root&.root_parent || markup_root)&.component
550
+ end
564
551
 
565
552
  private
566
553
 
@@ -1,26 +1,5 @@
1
1
  # backtick_javascript: true
2
2
 
3
- # Copyright (c) 2023-2024 Andy Maleh
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining
6
- # a copy of this software and associated documentation files (the
7
- # "Software"), to deal in the Software without restriction, including
8
- # without limitation the rights to use, copy, modify, merge, publish,
9
- # distribute, sublicense, and/or sell copies of the Software, and to
10
- # permit persons to whom the Software is furnished to do so, subject to
11
- # the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be
14
- # included in all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
3
  require 'glimmer/web/listener_proxy'
25
4
 
26
5
  module Glimmer
@@ -337,6 +316,11 @@ module Glimmer
337
316
  parents_array
338
317
  end
339
318
  alias ancestors parents
319
+
320
+ def root_parent
321
+ parents.last
322
+ end
323
+ alias root_ancesor root_parent
340
324
 
341
325
  def find_ancestor(include_self: false, &condition)
342
326
  current_element_proxy = self
@@ -1,26 +1,5 @@
1
1
  # backtick_javascript: true
2
2
 
3
- # Copyright (c) 2023-2024 Andy Maleh
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining
6
- # a copy of this software and associated documentation files (the
7
- # "Software"), to deal in the Software without restriction, including
8
- # without limitation the rights to use, copy, modify, merge, publish,
9
- # distribute, sublicense, and/or sell copies of the Software, and to
10
- # permit persons to whom the Software is furnished to do so, subject to
11
- # the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be
14
- # included in all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
3
  module Glimmer
25
4
  module Web
26
5
  class EventProxy