glimmer-dsl-web 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +8 -11
- data/VERSION +1 -1
- data/glimmer-dsl-web.gemspec +3 -3
- data/lib/rails/resource_service.rb +35 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a4d424a8d5ab44e419d2d859f2b0338bb676e84ab37756ef4721eee3cd70ae4
|
4
|
+
data.tar.gz: e19ad5b31ccc3a47838fa7a2e0ab0b30367fd342a4a9706d478c3702c8c03175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaa0f67301b67ba15a624c1a13f65f2bad31632a35940e9f767a70708919bec49ef740fceae499c3b49ba13c4e491cb575e6479ea4b2c276625bdaad71d677b8
|
7
|
+
data.tar.gz: 1d0f911b8748b454580c16eb56d28d8f1adc763a93559d42cde84037f2a224264ec813306cf28c28cf71ea698a635120e5f343b7202e3d025a1a9ef16a052658
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.6.7
|
4
|
+
|
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.
|
6
|
+
- Refactor/simplify code of Contact Manager sample with `Rails::ResourceService` enhancements to provide resource models in `response_handler` 2nd argument
|
7
|
+
|
3
8
|
## 0.6.6
|
4
9
|
|
5
|
-
- `Rails::ResourceService` supports index/show/create/update/
|
10
|
+
- `Rails::ResourceService` supports index/show/create/update/destroy REST API calls for any Rails resources
|
6
11
|
- Support being able to set or data-bind `title` property on HTML elements
|
7
12
|
- Restrict use of `title` tag to within a `head` element only
|
13
|
+
- Contact Manager Sample: https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app/blob/master/app/assets/opal/contact_manager.rb
|
8
14
|
|
9
15
|
## 0.6.5
|
10
16
|
|
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.
|
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)
|
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.
|
1411
|
+
gem 'glimmer-dsl-web', '~> 0.6.7'
|
1412
1412
|
```
|
1413
1413
|
|
1414
1414
|
Run:
|
@@ -1708,11 +1708,8 @@ Example from [ContactPresenter](https://github.com/AndyObtiva/sample-glimmer-dsl
|
|
1708
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.
|
1709
1709
|
|
1710
1710
|
```ruby
|
1711
|
-
Rails::ResourceService.update(resource: form_contact) do |response|
|
1711
|
+
Rails::ResourceService.update(resource: form_contact) do |response, updated_contact|
|
1712
1712
|
if response.ok?
|
1713
|
-
updated_contact_response_body = Native(response.body)
|
1714
|
-
updated_contact = form_contact.clone
|
1715
|
-
updated_contact.updated_at = updated_contact_response_body.updated_at
|
1716
1713
|
contacts[edit_index].load_with(updated_contact)
|
1717
1714
|
self.edit_index = nil
|
1718
1715
|
form_contact.reset
|
@@ -1724,11 +1721,11 @@ Example from [ContactPresenter](https://github.com/AndyObtiva/sample-glimmer-dsl
|
|
1724
1721
|
```
|
1725
1722
|
|
1726
1723
|
Note that there are alternative ways of invoking the `Rails::ResourceService.update` call:
|
1727
|
-
- `Rails::ResourceService.update(resource: form_contact)`
|
1728
|
-
- `Rails::ResourceService.update(resource_class: Contact, resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...})`
|
1729
|
-
- `Rails::ResourceService.update(singular_resource_name: 'contact', resource_id: form_contact.id, resource_attributes: {first_name: form_contact.first_name, ...})`
|
1730
|
-
- `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", resource_attributes: {first_name: form_contact.first_name, ...})`
|
1731
|
-
- `Rails::ResourceService.update(update_resource_url: "/contacts/#{form_contact.id}.json", params: {contact: {first_name: form_contact.first_name, ...}})`
|
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| ... }`
|
1732
1729
|
|
1733
1730
|
## Supported Glimmer DSL Keywords
|
1734
1731
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.7
|
data/glimmer-dsl-web.gemspec
CHANGED
@@ -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.
|
5
|
+
# stub: glimmer-dsl-web 0.6.7 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-web".freeze
|
9
|
-
s.version = "0.6.
|
9
|
+
s.version = "0.6.7"
|
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-
|
14
|
+
s.date = "2025-02-18"
|
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 = [
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rails
|
2
|
-
# ResourceService supports index/show/create/update/
|
2
|
+
# ResourceService supports index/show/create/update/destroy REST API calls for any Rails resources
|
3
3
|
# Automatically loads the authenticity token from meta[name=csrf-token] content attribute
|
4
4
|
# Assumes a resource or resource class that matches the name of a Backend ActiveRecord Model (e.g. Contact class or instance)
|
5
5
|
class ResourceService
|
@@ -11,7 +11,13 @@ module Rails
|
|
11
11
|
singular_resource_name ||= singular_resource_name_for_resource_class(resource_class)
|
12
12
|
plural_resource_name ||= "#{singular_resource_name}s"
|
13
13
|
index_resource_url ||= "/#{plural_resource_name}.json"
|
14
|
-
HTTP.get(index_resource_url, payload: index_show_destroy_resource_params(params: params.to_h)
|
14
|
+
HTTP.get(index_resource_url, payload: index_show_destroy_resource_params(params: params.to_h)) do |response|
|
15
|
+
if response.ok? && !resource_class.nil?
|
16
|
+
resource_response_objects = Native(response.body)
|
17
|
+
resources = resource_response_objects.map { |resource_response_object| build_resource_from_response_object(resource_class:, resource_response_object:) }
|
18
|
+
end
|
19
|
+
response_handler.call(response, resources)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def show(resource: nil, resource_class: nil, resource_id: nil, singular_resource_name: nil, plural_resource_name: nil, show_resource_url: nil, params: nil, &response_handler)
|
@@ -20,7 +26,13 @@ module Rails
|
|
20
26
|
singular_resource_name ||= singular_resource_name_for_resource_class(resource_class)
|
21
27
|
plural_resource_name ||= "#{singular_resource_name}s"
|
22
28
|
show_resource_url ||= "/#{plural_resource_name}/#{resource_id}.json"
|
23
|
-
HTTP.get(show_resource_url, payload: index_show_destroy_resource_params(params: params.to_h)
|
29
|
+
HTTP.get(show_resource_url, payload: index_show_destroy_resource_params(params: params.to_h)) do |response|
|
30
|
+
if response.ok? && !resource_class.nil?
|
31
|
+
resource_response_object = Native(response.body)
|
32
|
+
resource = build_resource_from_response_object(resource_class:, resource_response_object:)
|
33
|
+
end
|
34
|
+
response_handler.call(response, resource)
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
38
|
def create(resource: nil, resource_class: nil, resource_attributes: nil, singular_resource_name: nil, plural_resource_name: nil, create_resource_url: nil, params: nil, &response_handler)
|
@@ -28,7 +40,13 @@ module Rails
|
|
28
40
|
singular_resource_name ||= singular_resource_name_for_resource_class(resource_class)
|
29
41
|
plural_resource_name ||= "#{singular_resource_name}s"
|
30
42
|
create_resource_url ||= "/#{plural_resource_name}.json"
|
31
|
-
HTTP.post(create_resource_url, payload: create_update_resource_params(resource:, resource_class:, resource_attributes:, singular_resource_name:, params: params.to_h)
|
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:)
|
47
|
+
end
|
48
|
+
response_handler.call(response, resource)
|
49
|
+
end
|
32
50
|
end
|
33
51
|
|
34
52
|
def 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_handler)
|
@@ -37,7 +55,13 @@ module Rails
|
|
37
55
|
singular_resource_name ||= singular_resource_name_for_resource_class(resource_class)
|
38
56
|
plural_resource_name ||= "#{singular_resource_name}s"
|
39
57
|
update_resource_url ||= "/#{plural_resource_name}/#{resource_id}.json"
|
40
|
-
HTTP.patch(update_resource_url, payload: create_update_resource_params(resource:, resource_class:, resource_attributes:, singular_resource_name:, params: params.to_h)
|
58
|
+
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:)
|
62
|
+
end
|
63
|
+
response_handler.call(response, resource)
|
64
|
+
end
|
41
65
|
end
|
42
66
|
|
43
67
|
def destroy(resource: nil, resource_class: nil, resource_id: nil, singular_resource_name: nil, plural_resource_name: nil, destroy_resource_url: nil, params: nil, &response_handler)
|
@@ -71,6 +95,12 @@ module Rails
|
|
71
95
|
return nil if resource_class.nil?
|
72
96
|
resource_class.to_s.split('::').last.downcase
|
73
97
|
end
|
98
|
+
|
99
|
+
def build_resource_from_response_object(resource_class:, resource_response_object:)
|
100
|
+
resource = resource_class.new
|
101
|
+
resource_response_object.each { |attribute, value| resource.send("#{attribute}=", value) rescue nil }
|
102
|
+
resource
|
103
|
+
end
|
74
104
|
end
|
75
105
|
end
|
76
106
|
end
|
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.
|
4
|
+
version: 0.6.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: 2025-02-
|
11
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|