glimmer-dsl-web 0.6.8 → 0.6.10

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: 9f078ee2fccbdecc49040923265ba09b4bff1a0c9c0fb7c062c4aae58b68873d
4
- data.tar.gz: 7c3917e649acd80f9f20754b123b8cdd25a8bc435910dbc704d045b3174d2c27
3
+ metadata.gz: 19e269462e5ace48d73d5c76624b4d79f2a37f7679a410526f64aaceef4a0552
4
+ data.tar.gz: 24ccdc20a32122070edd290fc8b41375aac19d730bc974dcf96f89a8104aef63
5
5
  SHA512:
6
- metadata.gz: 6e080034e25b6aff5b70213f6fa991ae5c8e37fe38796703f1863c702c6268a1f9a827f0fd07926a0ca88ff3d952e2fea63ce794cd606395a1faf622d521bdb1
7
- data.tar.gz: 1c8135017efb0ba4b8815040cc8c5a9401360c84ea19d31af4d55f0565988480f8d58066dfe108d5e96d54cf91aeac8a4f9350ad40ccb78d1f6dbe0b1c6c06b1
6
+ metadata.gz: fb309b58ee1543098c7be8fd45dd66c067a21da9898f63dafbb4383ddc4827d42e9301b46cbe7c3e1deaf0fb10cc464538e71ee7b800c4eac78bffaf363b6448
7
+ data.tar.gz: ea766a952146e62707ebf3cba8d8da6e646489b277c0ee5d58790c5e284099e71cbb4a8fc39d334c96a096a5c25c760c12e17e92a411910876260c8a82ac2f6f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.6.10
4
+
5
+ - Support Component Attribute Listeners including non-option attributes (like method-based attributes not generated by `option :someoption` like `attr_accessor :someattr`)
6
+
7
+ ## 0.6.9
8
+
9
+ - Support Component Attribute (option-only) 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)
10
+
3
11
  ## 0.6.8
4
12
 
5
13
  - `Rails::ResourceService` provides `errors` as 3rd argument of `response_handler` block in erroneous web requests.
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.8 (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.10 (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!!!
@@ -17,7 +17,7 @@
17
17
 
18
18
  **Endorsement:** *"I'd like to endorse Andy Maleh’s work (Glimmer DSL for Web). I got introduced to it at RubyConf 2024 and have been playing around with it pretty successfully. What I have found most interesting is that I have been writing inside of a rails app, where I have been running the same code for models and presenters inside of MRI rspec. That way I can write tests that verify behavior of the presenters and models and still see them run successfully in the browser. That allows me to have a very nice cycle of refactoring and being confident in my changes without even running it in browser. I just assume that the binding will work and it usually works perfectly."* - Steve Tuckner on January 9, 2024
19
19
 
20
- You can finally live in pure Rubyland on the Web in both the frontend and backend with [Glimmer DSL for Web](https://rubygems.org/gems/glimmer-dsl-web)! [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for Web enables building Web Frontends (aka SPA: Single Page Applications) using [Ruby in the Browser](https://www.youtube.com/watch?v=4AdcfbI6A4c), as per [Matz's recommendation in his RubyConf 2022 keynote speech to replace JavaScript with Ruby](https://youtu.be/knutsgHTrfQ?t=789). It supports Rails' principle of the One Person Framework by not requiring any extra developers with JavaScript expertise, yet enabling Ruby (Backend) Software Engineers to develop the Frontend with Ruby code that is better than any JavaScript code produced by JS developers. 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](https://martinfowler.com/books/dsl.html) and [TIMTOWTDI](https://en.wiktionary.org/wiki/TMTOWTDI#English)) and the Rails way ([Convention over Configuration](https://rubyonrails.org/doctrine)) in building Isomorphic Ruby on Rails Applications. It provides a Ruby [HTML DSL](#usage) (including full support for [SVG](#hello-svg)), which uniquely enables writing both structure code and logic code in one language. It supports both Unidirectional (One-Way) [Data-Binding](#hello-data-binding) (using `<=`) and Bidirectional (Two-Way) [Data-Binding](#hello-data-binding) (using `<=>`). Dynamic rendering (and re-rendering) of HTML content is also supported via [Content Data-Binding](#hello-content-data-binding). Modular design is supported with [Glimmer Web Components](#hello-component), [Component Slots](#hello-component-slots), and [Component Custom Event Listeners](#hello-component-listeners). And, a Ruby CSS DSL is supported with the included [Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css). To automatically convert legacy HTML & CSS code to Glimmer DSL Ruby code, Software Engineers could use the included [`html_to_glimmer`](https://github.com/AndyObtiva/glimmer-dsl-xml#html-to-glimmer-converter) and [`css_to_glimmer`](https://github.com/AndyObtiva/glimmer-dsl-css#css-to-glimmer-converter) commands. Many [samples](#samples) are demonstrated in the [Rails sample app](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app) (there is a very minimal [Standalone [No Rails] static site sample app](https://github.com/Largo/glimmer-dsl-web-standalone-demo) too).
20
+ You can finally live in pure Rubyland on the Web in both the frontend and backend with [Glimmer DSL for Web](https://rubygems.org/gems/glimmer-dsl-web)! [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for Web enables building Web Frontends (aka SPA: Single Page Applications) using [Ruby in the Browser](https://www.youtube.com/watch?v=4AdcfbI6A4c), as per [Matz's recommendation in his RubyConf 2022 keynote speech to replace JavaScript with Ruby](https://youtu.be/knutsgHTrfQ?t=789). It supports Rails' principle of the One Person Framework by not requiring any extra developers with JavaScript expertise, yet enabling Ruby (Backend) Software Engineers to develop the Frontend with Ruby code that is better than any JavaScript code produced by JS developers. 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](https://martinfowler.com/books/dsl.html) and [TIMTOWTDI](https://en.wiktionary.org/wiki/TMTOWTDI#English)) and the Rails way ([Convention over Configuration](https://rubyonrails.org/doctrine)) in building Isomorphic Ruby on Rails Applications. It provides a Ruby [HTML DSL](#usage) (including full support for [SVG](#hello-svg)), which uniquely enables writing both structure code and logic code in one language. It supports both Unidirectional (One-Way) [Data-Binding](#hello-data-binding) (using `<=`) and Bidirectional (Two-Way) [Data-Binding](#hello-data-binding) (using `<=>`). Dynamic rendering (and re-rendering) of HTML content is also supported via [Content Data-Binding](#hello-content-data-binding). Modular design is supported with [Glimmer Web Components](#hello-component), [Component Slots](#hello-component-slots), Component Attribute Listeners, and [Component Custom Event Listeners](#hello-component-listeners). And, a Ruby CSS DSL is supported with the included [Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css). To automatically convert legacy HTML & CSS code to Glimmer DSL Ruby code, Software Engineers could use the included [`html_to_glimmer`](https://github.com/AndyObtiva/glimmer-dsl-xml#html-to-glimmer-converter) and [`css_to_glimmer`](https://github.com/AndyObtiva/glimmer-dsl-css#css-to-glimmer-converter) commands. Many [samples](#samples) are demonstrated in the [Rails sample app](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app) (there is a very minimal [Standalone [No Rails] static site sample app](https://github.com/Largo/glimmer-dsl-web-standalone-demo) too).
21
21
 
22
22
  You can finally have Ruby developer happiness and productivity in the Frontend! No more wasting time splitting your resources across multiple languages, using badly engineered, over-engineered, or premature-optimization-obsessed JavaScript libraries, fighting JavaScript build issues (e.g. webpack), or rewriting Ruby Backend code in Frontend JavaScript. With [Ruby in the Browser](https://www.youtube.com/watch?v=4AdcfbI6A4c), you can have an exponential jump in development productivity (2x or higher), time-to-release (1/2 or less time), cost (1/2 or cheaper), and maintainability (~50% the code that is simpler and more readable) over JavaScript libraries like React, Angular, Ember, Vue, and Svelte, while being able to reuse Backend Ruby code as is in the Frontend for faster interactions when needed. Also, with Frontend Ruby SPA (Single Page Applications), companies can cut their hiring budget in half by having Backend Ruby Software Engineers do Frontend Development in Ruby! [Ruby in the Browser](https://www.youtube.com/watch?v=4AdcfbI6A4c) finally fulfills every smart highly-productive Rubyist's dream by bringing Ruby productivity fun to Frontend Development, the same productivity fun you had for years and decades in Backend Development.
23
23
 
@@ -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.8'
1411
+ gem 'glimmer-dsl-web', '~> 0.6.10'
1412
1412
  ```
1413
1413
 
1414
1414
  Run:
@@ -1711,12 +1711,27 @@ if Developers would rather not write the Backend by hand.
1711
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| ... }`
1712
1712
 
1713
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.
1714
1716
 
1715
- 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:
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:
1716
1718
 
1717
- `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.
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)
1718
1720
 
1719
1721
  ```ruby
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
1720
1735
  Rails::ResourceService.update(resource: form_contact) do |response, updated_contact, errors|
1721
1736
  if response.ok?
1722
1737
  contacts[edit_index].load_with(updated_contact)
@@ -1727,6 +1742,7 @@ Example from [ContactPresenter](https://github.com/AndyObtiva/sample-glimmer-dsl
1727
1742
  form_contact.errors = errors
1728
1743
  end
1729
1744
  end
1745
+ end
1730
1746
  ```
1731
1747
 
1732
1748
  Note that there are alternative ways of invoking the `Rails::ResourceService.update` call:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.8
1
+ 0.6.10
@@ -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.8 ruby lib
5
+ # stub: glimmer-dsl-web 0.6.10 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.6.8"
9
+ s.version = "0.6.10"
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,15 @@ 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_read_write_attribute?(attribute_name) ||
377
+ has_instance_method?(attribute_name) ||
378
+ has_instance_method?("#{attribute_name}?")
379
+ end
380
+
381
+ def has_option?(option_name)
382
+ normalized_option_name = option_name.to_s.to_sym
383
+ options.keys.include?(normalized_option_name)
375
384
  end
376
385
 
377
386
  def can_add_custom_event_listener?(event)
@@ -435,12 +444,17 @@ module Glimmer
435
444
  @markup_root.set_attribute(attribute_name, *args)
436
445
  end
437
446
  end
447
+
448
+ def has_read_write_attribute?(attribute)
449
+ respond_to?(attribute) && respond_to?("#{attribute}=")
450
+ end
438
451
 
439
452
  # This method ensures it has an instance method not coming from Glimmer DSL
440
453
  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
454
+ # 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)
455
+ respond_to?(method_name) &&
456
+ !markup_root&.respond_to?(method_name) &&
457
+ !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') &&
444
458
  !method(method_name)&.source_location&.first&.include?('glimmer/web/element_proxy.rb')
445
459
  end
446
460
 
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.8
4
+ version: 0.6.10
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