glimmer-dsl-web 0.6.7 → 0.6.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a4d424a8d5ab44e419d2d859f2b0338bb676e84ab37756ef4721eee3cd70ae4
4
- data.tar.gz: e19ad5b31ccc3a47838fa7a2e0ab0b30367fd342a4a9706d478c3702c8c03175
3
+ metadata.gz: c255e190aed253bf44917907d1fa39c17b71f795054dedb33ca6912b9c798562
4
+ data.tar.gz: 7448c70a081144086a1f0c9545c3e3f4dc8e17e0e03df4c1126f1a1b054e605d
5
5
  SHA512:
6
- metadata.gz: eaa0f67301b67ba15a624c1a13f65f2bad31632a35940e9f767a70708919bec49ef740fceae499c3b49ba13c4e491cb575e6479ea4b2c276625bdaad71d677b8
7
- data.tar.gz: 1d0f911b8748b454580c16eb56d28d8f1adc763a93559d42cde84037f2a224264ec813306cf28c28cf71ea698a635120e5f343b7202e3d025a1a9ef16a052658
6
+ metadata.gz: f39baaa90a81e981b57c9012ba6c2e07de039f340427075e5b08f988ac068e1dc6ccebe0213c23d4c7c86269b1bc80598065ac6f6478f8fa425e25304b1e6abd
7
+ data.tar.gz: 443bc0a99fed33be65e134077a26dfa1b19334b5d7a77ade6b0f7132f6efa256c1efc84571f97452c07d71077d8badbef6c7f0de2cad1add0a8e3d3342aad162
data/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.6.9
4
+
5
+ - Support Component Option Listeners (nest a `on_some_attribute_update { ... }` listener inside the content block of a consumed Glimmer Web Component for any attribute/option on the Component, like `on_full_name_update` listener for `full_name` attribute update)
6
+
7
+ ## 0.6.8
8
+
9
+ - `Rails::ResourceService` provides `errors` as 3rd argument of `response_handler` block in erroneous web requests.
10
+ - Refactor/simplify code of Contact Manager sample with `Rails::ResourceService` enhancements to provide `errors` as `response_handler` 3rd argument
11
+
3
12
  ## 0.6.7
4
13
 
5
- - `Rails::ResourceService` builds resource models using `resource_class` and provides `resources`/`resource` as 2nd argument of `response_handler` blocks in index/show/create/update calls.
14
+ - `Rails::ResourceService` builds resource models using `resource_class` and provides `resources`/`resource` as 2nd argument of `response_handler` block in index/show/create/update calls.
6
15
  - Refactor/simplify code of Contact Manager sample with `Rails::ResourceService` enhancements to provide resource models in `response_handler` 2nd argument
7
16
 
8
17
  ## 0.6.6
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.6.7 (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.6.9 (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!!!
@@ -1408,7 +1408,7 @@ rails new glimmer_app_server
1408
1408
  Add the following to `Gemfile`:
1409
1409
 
1410
1410
  ```
1411
- gem 'glimmer-dsl-web', '~> 0.6.7'
1411
+ gem 'glimmer-dsl-web', '~> 0.6.9'
1412
1412
  ```
1413
1413
 
1414
1414
  Run:
@@ -1703,29 +1703,54 @@ you can use [Rails::ResourceService](/lib/rails/resource_service.rb) (`require '
1703
1703
  the `Rails::ResourceService` class source code to find out what its API is. It can work with a basic Rails Scaffold of a Resource
1704
1704
  if Developers would rather not write the Backend by hand.
1705
1705
 
1706
- Example from [ContactPresenter](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app/blob/master/app/assets/opal/contact_manager/presenters/contact_presenter.rb) in the [Contact Manager](#contact-manager) sample:
1706
+ `Rails::ResourceService` API:
1707
+ - `index(resource: nil, resource_class: nil, singular_resource_name: nil, plural_resource_name: nil, index_resource_url: nil, params: nil) { |response| ... }`
1708
+ - `show(resource: nil, resource_class: nil, resource_id: nil, singular_resource_name: nil, plural_resource_name: nil, show_resource_url: nil, params: nil) { |response| ... }`
1709
+ - `create(resource: nil, resource_class: nil, resource_attributes: nil, singular_resource_name: nil, plural_resource_name: nil, create_resource_url: nil, params: nil) { |response, created_resource, errors| ... }`
1710
+ - `update(resource: nil, resource_class: nil, resource_id: nil, resource_attributes: nil, singular_resource_name: nil, plural_resource_name: nil, update_resource_url: nil, params: nil) { |response, updated_resource, errors| ... }`
1711
+ - `destroy(resource: nil, resource_class: nil, resource_id: nil, singular_resource_name: nil, plural_resource_name: nil, destroy_resource_url: nil, params: nil) { |response| ... }`
1707
1712
 
1708
- `form_contact` is an instance of the [Contact](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app/blob/master/app/assets/opal/contact_manager/models/contact.rb) class.
1713
+ `Rails::ResourceService` follows the 'Convention over Configuration' Rails principle as it auto-derives the URL to call based on the `resource` class and data.
1714
+ `resource` can be a Ruby class with attribute method declarations or `attr_accessor` declarations, or a Ruby `Struct` class.
1715
+ `Rails::ResourceService` is flexible enough to work with all options.
1716
+
1717
+ Examples from [ContactPresenter](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app/blob/master/app/assets/opal/contact_manager/presenters/contact_presenter.rb) in the [Contact Manager](#contact-manager) sample:
1718
+
1719
+ (note: `form_contact` is an instance of the [Contact](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app/blob/master/app/assets/opal/contact_manager/models/contact.rb) class)
1709
1720
 
1710
1721
  ```ruby
1711
- Rails::ResourceService.update(resource: form_contact) do |response, updated_contact|
1722
+ def add_contact
1723
+ Rails::ResourceService.create(resource: form_contact) do |response, created_contact, errors|
1724
+ if response.ok?
1725
+ contacts << created_contact
1726
+ form_contact.reset
1727
+ form_contact.errors = nil
1728
+ else
1729
+ form_contact.errors = errors
1730
+ end
1731
+ end
1732
+ end
1733
+
1734
+ def update_contact
1735
+ Rails::ResourceService.update(resource: form_contact) do |response, updated_contact, errors|
1712
1736
  if response.ok?
1713
1737
  contacts[edit_index].load_with(updated_contact)
1714
1738
  self.edit_index = nil
1715
1739
  form_contact.reset
1716
1740
  form_contact.errors = nil
1717
1741
  else
1718
- form_contact.errors = JSON.parse(response.body)
1742
+ form_contact.errors = errors
1719
1743
  end
1720
1744
  end
1745
+ end
1721
1746
  ```
1722
1747
 
1723
1748
  Note that there are alternative ways of invoking the `Rails::ResourceService.update` call:
1724
- - `Rails::ResourceService.update(resource: form_contact) { |response| ... }`
1725
- - `Rails::ResourceService.update(resource_class: Contact, resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...}) { |response| ... }`
1726
- - `Rails::ResourceService.update(singular_resource_name: 'contact', resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...}) { |response| ... }`
1727
- - `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", resource_attributes: {first_name: form_contact.first_name, ...}) { |response| ... }`
1728
- - `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", params: {contact: {first_name: form_contact.first_name, ...}}) { |response| ... }`
1749
+ - `Rails::ResourceService.update(resource: form_contact) { |response, resource, errors| ... }`
1750
+ - `Rails::ResourceService.update(resource_class: Contact, resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...}) { |response, resource, errors| ... }`
1751
+ - `Rails::ResourceService.update(singular_resource_name: 'contact', resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...}) { |response, resource, errors| ... }`
1752
+ - `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", resource_attributes: {first_name: form_contact.first_name, ...}) { |response, resource, errors| ... }`
1753
+ - `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", params: {contact: {first_name: form_contact.first_name, ...}}) { |response, resource, errors| ... }`
1729
1754
 
1730
1755
  ## Supported Glimmer DSL Keywords
1731
1756
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.6.9
@@ -2,16 +2,16 @@
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.6.7 ruby lib
5
+ # stub: glimmer-dsl-web 0.6.9 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.6.7"
9
+ s.version = "0.6.9"
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]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2025-02-18"
14
+ s.date = "2025-02-23"
15
15
  s.description = "Glimmer DSL for Web (Ruby in the Browser Web Frontend Framework) enables building Web Frontends using Ruby in the Browser, as per Matz's recommendation in his RubyConf 2022 keynote speech to replace JavaScript with Ruby. It aims at providing the simplest, most intuitive, most straight-forward, and most productive frontend framework in existence. The framework follows the Ruby way (with DSLs and TIMTOWTDI) and the Rails way (Convention over Configuration) in building Isomorphic Ruby on Rails Applications. It provides a Ruby HTML DSL, which uniquely enables writing both structure code and logic code in one language. It supports both Unidirectional (One-Way) Data-Binding (using <=) and Bidirectional (Two-Way) Data-Binding (using <=>). Dynamic rendering (and re-rendering) of HTML content is also supported via Content Data-Binding. Modular design is supported with Glimmer Web Components, Component Slots, and Component Custom Event Listeners. And, a Ruby CSS DSL is supported with the included Glimmer DSL for CSS. Many samples are demonstrated in the Rails sample app (there is a very minimal Standalone [No Rails] sample app too). You can finally live in pure Rubyland on the Web in both the frontend and backend with Glimmer DSL for Web! This gem relies on Opal Ruby.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -278,6 +278,8 @@ module Glimmer
278
278
  end
279
279
  # <- end of class methods
280
280
 
281
+ REGEX_LISTENER_OPTION_UPDATE = /^on_(.)+_update$/
282
+
281
283
  attr_reader :markup_root, :parent, :args, :options, :style_block, :component_style, :slot_elements, :events, :default_slot
282
284
  alias parent_proxy parent
283
285
 
@@ -290,7 +292,6 @@ module Glimmer
290
292
  options = args
291
293
  args = []
292
294
  end
293
- options ||= {}
294
295
  @slot_elements = {}
295
296
  @args = args
296
297
  options ||= {}
@@ -342,8 +343,8 @@ module Glimmer
342
343
  def can_handle_observation_request?(observation_request)
343
344
  observation_request = observation_request.to_s
344
345
  result = false
345
- if observation_request.start_with?('on_update_') # TODO change to on_someprop_update & document this feature
346
- property = observation_request.sub(/^on_update_/, '')
346
+ if observation_request.match(REGEX_LISTENER_OPTION_UPDATE)
347
+ property = observation_request.sub(/^on_/, '').sub(/_update$/, '')
347
348
  result = can_add_observer?(property)
348
349
  elsif observation_request.start_with?('on_')
349
350
  event = observation_request.sub(/^on_/, '')
@@ -354,8 +355,8 @@ module Glimmer
354
355
 
355
356
  def handle_observation_request(observation_request, block)
356
357
  observation_request = observation_request.to_s
357
- if observation_request.start_with?('on_update_')
358
- property = observation_request.sub(/^on_update_/, '') # TODO look into eliminating duplication from above
358
+ if observation_request.match(REGEX_LISTENER_OPTION_UPDATE)
359
+ property = observation_request.sub(/^on_/, '').sub(/_update$/, '')
359
360
  add_observer(DataBinding::Observer.proc(&block), property) if can_add_observer?(property)
360
361
  elsif observation_request.start_with?('on_')
361
362
  event = observation_request.sub(/^on_/, '') # TODO look into eliminating duplication from above
@@ -371,7 +372,14 @@ module Glimmer
371
372
  end
372
373
 
373
374
  def can_add_attribute_observer?(attribute_name)
374
- has_instance_method?(attribute_name) || has_instance_method?("#{attribute_name}?")
375
+ has_option?(attribute_name) ||
376
+ has_instance_method?(attribute_name) ||
377
+ has_instance_method?("#{attribute_name}?")
378
+ end
379
+
380
+ def has_option?(option_name)
381
+ normalized_option_name = option_name.to_s.to_sym
382
+ options.keys.include?(normalized_option_name)
375
383
  end
376
384
 
377
385
  def can_add_custom_event_listener?(event)
@@ -438,9 +446,10 @@ module Glimmer
438
446
 
439
447
  # This method ensures it has an instance method not coming from Glimmer DSL
440
448
  def has_instance_method?(method_name)
441
- respond_to?(method_name) and
442
- !markup_root&.respond_to?(method_name) and
443
- !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') and
449
+ # TODO this carryover code from other Glimmer DSLs doesn't seem to be needed in this DSL (and probably doesn't work in Opal anyways)
450
+ respond_to?(method_name) &&
451
+ !markup_root&.respond_to?(method_name) &&
452
+ !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') &&
444
453
  !method(method_name)&.source_location&.first&.include?('glimmer/web/element_proxy.rb')
445
454
  end
446
455
 
@@ -41,11 +41,15 @@ module Rails
41
41
  plural_resource_name ||= "#{singular_resource_name}s"
42
42
  create_resource_url ||= "/#{plural_resource_name}.json"
43
43
  HTTP.post(create_resource_url, payload: create_update_resource_params(resource:, resource_class:, resource_attributes:, singular_resource_name:, params: params.to_h)) do |response|
44
- if response.ok? && !resource_class.nil?
45
- resource_response_object = Native(response.body)
46
- resource = build_resource_from_response_object(resource_class:, resource_response_object:)
44
+ if response.ok?
45
+ if !resource_class.nil?
46
+ resource_response_object = Native(response.body)
47
+ resource = build_resource_from_response_object(resource_class:, resource_response_object:)
48
+ end
49
+ else
50
+ errors = JSON.parse(response.body)
47
51
  end
48
- response_handler.call(response, resource)
52
+ response_handler.call(response, resource, errors)
49
53
  end
50
54
  end
51
55
 
@@ -56,11 +60,15 @@ module Rails
56
60
  plural_resource_name ||= "#{singular_resource_name}s"
57
61
  update_resource_url ||= "/#{plural_resource_name}/#{resource_id}.json"
58
62
  HTTP.patch(update_resource_url, payload: create_update_resource_params(resource:, resource_class:, resource_attributes:, singular_resource_name:, params: params.to_h)) do |response|
59
- if response.ok? && !resource_class.nil?
60
- resource_response_object = Native(response.body)
61
- resource = build_resource_from_response_object(resource_class:, resource_response_object:)
63
+ if response.ok?
64
+ if !resource_class.nil?
65
+ resource_response_object = Native(response.body)
66
+ resource = build_resource_from_response_object(resource_class:, resource_response_object:)
67
+ end
68
+ else
69
+ errors = JSON.parse(response.body)
62
70
  end
63
- response_handler.call(response, resource)
71
+ response_handler.call(response, resource, errors)
64
72
  end
65
73
  end
66
74
 
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.6.7
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-18 00:00:00.000000000 Z
11
+ date: 2025-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer