glimmer-dsl-web 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaaa7092a643511c072a409a2b771b34db6b2aa0859adc5b200e5aba0869590e
4
- data.tar.gz: 15ba8d9639037fa17104cb997a449f42e79703ae9ec4992f21b8a7551d3b09f0
3
+ metadata.gz: 5c9bd6a7f085751de551a8eada611f25b6462c32f31019ebc31e296a98a7dbe7
4
+ data.tar.gz: cde631c346fddf15d48c52b85643f4f436761b059ccca0a8909cca56fdc7676e
5
5
  SHA512:
6
- metadata.gz: 5732c5dca9591d17917fd6dfbd1425eed080f6aa345f6b9fb6bbbd8f3d487ce83428063b9ef974cabab8c2fdd7e6d8799b67e4442c462e6c174a4a81448900c6
7
- data.tar.gz: 34afe2b80aeb727dad38572f81f46f7d442ef2998cb97b94ae92d332364f3ff2da0669203ced36a0484304fbbcbdfb1c7cb30a8b74b49ce42abb329ce333b7de
6
+ metadata.gz: 036cbe077a6378e6fb18cf10060074b4a071b20f4293960ded842458069c4dfb5bc041eb909f0b7b3cfbb809f73a41605f2b97f101b338f1ee616e52f00445c3
7
+ data.tar.gz: 4441339edfaf2724324e4aa30c19b2afc7e0e9d673add6130882e1c3220e278a1be1d21be126bf9b8aaa7568c62a0c59ecbce9ca2d1103183263ae17deb2d15e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.0
4
+
5
+ - Update rendering system to render HTML elements immediately instead of waiting for complete components to be rendered all at once.
6
+ - Support `render: false` option in any element or component to avoid rendering when building the elements/components (including a Component#create alternative to Component#render that defers rendering if needed).
7
+ - Fix `Glimmer::Web::Component` `after_render` hook by ensuring it only fires after the component markup has been rendered
8
+
3
9
  ## 0.0.12
4
10
 
5
11
  - Treat HTML text formatting elements differently (e.g. `b`, `i`, `strong`, `em`, `sub`, `sup`, `del`, `ins`, `small`, `mark`) by not appending to their parent content, yet having them generate a String with `to_s` that can be embedded in a `String` that is the text content of another normal element like `p` or `div`.
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.0.12 (Early Alpha)
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.1.0 (Beta)
2
2
  ## Ruby in the Browser Web GUI Frontend Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-web.svg)](http://badge.fury.io/rb/glimmer-dsl-web)
4
4
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -17,7 +17,7 @@ include Glimmer
17
17
  Document.ready? do
18
18
  div {
19
19
  'Hello, World!'
20
- }.render
20
+ }
21
21
  end
22
22
  ```
23
23
 
@@ -49,7 +49,7 @@ Document.ready? do
49
49
  $$.alert('Hello, Button!')
50
50
  end
51
51
  }
52
- }.render
52
+ }
53
53
  end
54
54
  ```
55
55
 
@@ -150,7 +150,7 @@ Document.ready? do
150
150
  }
151
151
  CSS
152
152
  }
153
- }.render
153
+ }
154
154
  end
155
155
  ```
156
156
 
@@ -245,6 +245,8 @@ class HelloObserver
245
245
  end
246
246
 
247
247
  after_render do
248
+ @number_input.value = @number_holder.number
249
+ @range_input.value = @number_holder.number
248
250
  # Observe Model attribute @number_holder.number for changes and update View
249
251
  # Observer is automatically cleaned up if remove method is called on rendered HelloObserver
250
252
  # or its top-level element
@@ -262,7 +264,7 @@ class HelloObserver
262
264
  markup {
263
265
  div {
264
266
  div {
265
- @number_input = input(type: 'number', value: @number_holder.number, min: 0, max: 100) {
267
+ @number_input = input(type: 'number', min: 0, max: 100) {
266
268
  # oninput listener updates Model attribute @number_holder.number
267
269
  oninput do
268
270
  @number_holder.number = @number_input.value.to_i
@@ -276,7 +278,7 @@ class HelloObserver
276
278
  }
277
279
  }
278
280
  div {
279
- @range_input = input(type: 'range', value: @number_holder.number, min: 0, max: 100) {
281
+ @range_input = input(type: 'range', min: 0, max: 100) {
280
282
  # oninput listener updates Model attribute @number_holder.number
281
283
  oninput do
282
284
  @number_holder.number = @range_input.value.to_i
@@ -411,7 +413,7 @@ Document.ready? do
411
413
  computed_by: @address.members + ['state_code'],
412
414
  ]
413
415
  }
414
- }.render
416
+ }
415
417
  end
416
418
  ```
417
419
 
@@ -546,7 +548,7 @@ Document.ready? do
546
548
  end
547
549
  end
548
550
  }
549
- }.render
551
+ }
550
552
  end
551
553
  ```
552
554
 
@@ -1073,7 +1075,7 @@ Screenshot:
1073
1075
 
1074
1076
  --
1075
1077
 
1076
- NOTE: Glimmer DSL for Web is an Early Alpha project. If you want it developed faster, please [open an issue report](https://github.com/AndyObtiva/glimmer-dsl-web/issues/new). I have completed some GitHub project features much faster before due to [issue reports](https://github.com/AndyObtiva/glimmer-dsl-web/issues) and [pull requests](https://github.com/AndyObtiva/glimmer-dsl-web/pulls). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
1078
+ NOTE: Glimmer DSL for Web is a Beta project. If you want it developed faster, please [open an issue report](https://github.com/AndyObtiva/glimmer-dsl-web/issues/new). I have completed some GitHub project features much faster before due to [issue reports](https://github.com/AndyObtiva/glimmer-dsl-web/issues) and [pull requests](https://github.com/AndyObtiva/glimmer-dsl-web/pulls). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still a Beta, so the more feedback and issues you report the better.
1077
1079
 
1078
1080
  Learn more about the differences between various [Glimmer](https://github.com/AndyObtiva/glimmer) DSLs by looking at:
1079
1081
 
@@ -1081,7 +1083,7 @@ Learn more about the differences between various [Glimmer](https://github.com/An
1081
1083
 
1082
1084
  ## Table of Contents
1083
1085
 
1084
- - [Glimmer DSL for Web](#-glimmer-dsl-for-opal-alpha-pure-ruby-web-gui)
1086
+ - [Glimmer DSL for Web](#)
1085
1087
  - [Prerequisites](#prerequisites)
1086
1088
  - [Setup](#setup)
1087
1089
  - [Usage](#usage)
@@ -1121,7 +1123,7 @@ Learn more about the differences between various [Glimmer](https://github.com/An
1121
1123
 
1122
1124
  ## Setup
1123
1125
 
1124
- (NOTE: Keep in mind this is an Early Alpha. If you run into issues, try to go back to a [previous revision](https://rubygems.org/gems/glimmer-dsl-web/versions). Also, there is a slight chance any issues you encounter are fixed in master or some other branch that you could check out instead)
1126
+ (NOTE: Keep in mind this is a Beta. If you run into issues, try to go back to a [previous revision](https://rubygems.org/gems/glimmer-dsl-web/versions). Also, there is a slight chance any issues you encounter are fixed in master or some other branch that you could check out instead)
1125
1127
 
1126
1128
  The [glimmer-dsl-web](https://rubygems.org/gems/glimmer-dsl-web) gem is a [Rails Engine](https://guides.rubyonrails.org/engines.html) gem that includes assets.
1127
1129
 
@@ -1144,7 +1146,7 @@ rails new glimmer_app_server
1144
1146
  Add the following to `Gemfile`:
1145
1147
 
1146
1148
  ```
1147
- gem 'glimmer-dsl-web', '~> 0.0.12'
1149
+ gem 'glimmer-dsl-web', '~> 0.1.0'
1148
1150
  ```
1149
1151
 
1150
1152
  Run:
@@ -1247,7 +1249,7 @@ Document.ready? do
1247
1249
  label(class: 'greeting') {
1248
1250
  'Hello, World!'
1249
1251
  }
1250
- }.render
1252
+ }
1251
1253
  end
1252
1254
  ```
1253
1255
 
@@ -1298,7 +1300,7 @@ Document.ready? do
1298
1300
  label(class: 'greeting') {
1299
1301
  'Hello, World!'
1300
1302
  }
1301
- }.render
1303
+ }
1302
1304
  end
1303
1305
  ```
1304
1306
 
@@ -1360,7 +1362,7 @@ Disable the `webpacker` gem line in `Gemfile`:
1360
1362
  Add the following to `Gemfile`:
1361
1363
 
1362
1364
  ```ruby
1363
- gem 'glimmer-dsl-web', '~> 0.0.12'
1365
+ gem 'glimmer-dsl-web', '~> 0.1.0'
1364
1366
  ```
1365
1367
 
1366
1368
  Run:
@@ -1461,7 +1463,7 @@ Document.ready? do
1461
1463
  label(class: 'greeting') {
1462
1464
  'Hello, World!'
1463
1465
  }
1464
- }.render
1466
+ }
1465
1467
  end
1466
1468
  ```
1467
1469
 
@@ -1616,7 +1618,7 @@ include Glimmer
1616
1618
  Document.ready? do
1617
1619
  div {
1618
1620
  'Hello, World!'
1619
- }.render
1621
+ }
1620
1622
  end
1621
1623
  ```
1622
1624
 
@@ -1638,7 +1640,7 @@ require 'glimmer-dsl-web'
1638
1640
  include Glimmer
1639
1641
 
1640
1642
  Document.ready? do
1641
- div('Hello, World!').render
1643
+ div('Hello, World!')
1642
1644
  end
1643
1645
  ```
1644
1646
 
@@ -1670,7 +1672,7 @@ Document.ready? do
1670
1672
  $$.alert('Hello, Button!')
1671
1673
  end
1672
1674
  }
1673
- }.render
1675
+ }
1674
1676
  end
1675
1677
  ```
1676
1678
 
@@ -1771,7 +1773,7 @@ Document.ready? do
1771
1773
  }
1772
1774
  CSS
1773
1775
  }
1774
- }.render
1776
+ }
1775
1777
  end
1776
1778
  ```
1777
1779
 
@@ -1866,6 +1868,8 @@ class HelloObserver
1866
1868
  end
1867
1869
 
1868
1870
  after_render do
1871
+ @number_input.value = @number_holder.number
1872
+ @range_input.value = @number_holder.number
1869
1873
  # Observe Model attribute @number_holder.number for changes and update View
1870
1874
  # Observer is automatically cleaned up if remove method is called on rendered HelloObserver
1871
1875
  # or its top-level element
@@ -1883,7 +1887,7 @@ class HelloObserver
1883
1887
  markup {
1884
1888
  div {
1885
1889
  div {
1886
- @number_input = input(type: 'number', value: @number_holder.number, min: 0, max: 100) {
1890
+ @number_input = input(type: 'number', min: 0, max: 100) {
1887
1891
  # oninput listener updates Model attribute @number_holder.number
1888
1892
  oninput do
1889
1893
  @number_holder.number = @number_input.value.to_i
@@ -1897,7 +1901,7 @@ class HelloObserver
1897
1901
  }
1898
1902
  }
1899
1903
  div {
1900
- @range_input = input(type: 'range', value: @number_holder.number, min: 0, max: 100) {
1904
+ @range_input = input(type: 'range', min: 0, max: 100) {
1901
1905
  # oninput listener updates Model attribute @number_holder.number
1902
1906
  oninput do
1903
1907
  @number_holder.number = @range_input.value.to_i
@@ -2088,7 +2092,7 @@ Document.ready? do
2088
2092
  computed_by: @address.members + ['state_code'],
2089
2093
  ]
2090
2094
  }
2091
- }.render
2095
+ }
2092
2096
  end
2093
2097
  ```
2094
2098
 
@@ -2223,7 +2227,7 @@ Document.ready? do
2223
2227
  end
2224
2228
  end
2225
2229
  }
2226
- }.render
2230
+ }
2227
2231
  end
2228
2232
  ```
2229
2233
 
@@ -2849,7 +2853,7 @@ Document.ready? do
2849
2853
  CSS
2850
2854
  }
2851
2855
  }
2852
- }.render
2856
+ }
2853
2857
  end
2854
2858
  ```
2855
2859
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.1.0
@@ -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.0.12 ruby lib
5
+ # stub: glimmer-dsl-web 0.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.0.12".freeze
9
+ s.version = "0.1.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]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2024-01-07"
14
+ s.date = "2024-01-08"
15
15
  s.description = "Glimmer DSL for Web (Ruby in the Browser Web GUI Frontend Library) enables building Web GUI 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 library in existence. The library follows the Ruby way (with DSLs and TIMTOWTDI) and the Rails way (Convention over Configuration) while supporting 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. And, modular design is supported with Glimmer Web Components. You can finally live in pure Rubyland on the Web in both the frontend and backend with Glimmer DSL for Web! This library relies on Opal Ruby.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -93,10 +93,17 @@ module Glimmer
93
93
  self.name.underscore.gsub('::', '__').split('__').last
94
94
  end
95
95
 
96
+ # Creates component without rendering
97
+ def create(*args)
98
+ args << {} unless args.last.is_a?(Hash)
99
+ args.last[:render] = false
100
+ rendered_component = send(keyword, *args)
101
+ rendered_component
102
+ end
103
+
104
+ # Creates and renders component
96
105
  def render(*args)
97
106
  rendered_component = send(keyword, *args)
98
- options = args.last.is_a?(Hash) ? args.last.slice(:parent, :custom_parent_dom_element, :brand_new) : {}
99
- rendered_component.render(**options)
100
107
  rendered_component
101
108
  end
102
109
  end
@@ -204,10 +211,15 @@ module Glimmer
204
211
  markup_block = self.class.instance_variable_get("@markup_block")
205
212
  raise Glimmer::Error, 'Invalid Glimmer web component for having no markup! Please define markup block!' if markup_block.nil?
206
213
  @markup_root = instance_exec(&markup_block)
207
- @markup_root.options[:parent] = options[:parent] if options[:parent]
214
+ @markup_root.options[:parent] = options[:parent] if !options[:parent].nil?
208
215
  @parent ||= @markup_root.parent
209
216
  raise Glimmer::Error, 'Invalid Glimmer web component for having an empty markup! Please fill markup block!' if @markup_root.nil?
210
- execute_hooks('after_render')
217
+ if options[:render] != false
218
+ execute_hooks('after_render')
219
+ else
220
+ on_render_listener = proc { execute_hooks('after_render') }
221
+ @markup_root.handle_observation_request('on_render', on_render_listener)
222
+ end
211
223
 
212
224
  # TODO adapt for web
213
225
  observer_registration_cleanup_listener = proc do
@@ -109,16 +109,25 @@ module Glimmer
109
109
  @keyword = keyword
110
110
  @parent = parent
111
111
  @options = args.last.is_a?(Hash) ? args.last.symbolize_keys : {}
112
+ if parent.nil?
113
+ options[:parent] ||= Component.interpretation_stack.last&.options&.[](:parent)
114
+ options[:render] ||= Component.interpretation_stack.last&.options&.[](:render)
115
+ end
112
116
  @args = args
113
117
  @block = block
114
118
  @children = []
115
119
  @parent&.post_initialize_child(self)
120
+ render if !@rendered && render_after_create?
121
+ end
122
+
123
+ def render_after_create?
124
+ options[:render] != false && (@parent.nil? || @parent.render_after_create?)
116
125
  end
117
126
 
118
127
  # Executes for the parent of a child that just got added
119
128
  def post_initialize_child(child)
120
129
  @children << child
121
- child.render
130
+ child.render if !render_after_create?
122
131
  end
123
132
 
124
133
  # Executes for the parent of a child that just got removed
@@ -128,6 +137,7 @@ module Glimmer
128
137
 
129
138
  # Executes at the closing of a parent widget curly braces after all children/properties have been added/set
130
139
  def post_add_content
140
+ # TODO double check every place we should call this method
131
141
  # No Op
132
142
  end
133
143
 
@@ -215,7 +225,7 @@ module Glimmer
215
225
  def parent_selector
216
226
  @parent&.selector
217
227
  end
218
-
228
+
219
229
  def parent_dom_element
220
230
  if parent_selector
221
231
  Document.find(parent_selector)
@@ -253,8 +263,10 @@ module Glimmer
253
263
  handle_observation_request(keyword, event_listener)
254
264
  end
255
265
  end
256
- children.each do |child|
257
- child.render
266
+ unless render_after_create?
267
+ children.each do |child|
268
+ child.render
269
+ end
258
270
  end
259
271
  @rendered = true
260
272
  unless skip_content_on_render_blocks?
@@ -262,6 +274,10 @@ module Glimmer
262
274
  content(&content_block)
263
275
  end
264
276
  end
277
+ # TODO replace following line with a method call like (`notify_listeners('on_render')`)
278
+ listeners_for('on_render').each do |listener|
279
+ listener.original_event_listener.call(EventProxy.new(listener: listener))
280
+ end
265
281
  end
266
282
  alias rerender render
267
283
 
@@ -1,3 +1,5 @@
1
+ # backtick_javascript: true
2
+
1
3
  # Copyright (c) 2023-2024 Andy Maleh
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining
@@ -30,5 +30,5 @@ Document.ready? do
30
30
  $$.alert('Hello, Button!')
31
31
  end
32
32
  }
33
- }.render
33
+ }
34
34
  end
@@ -137,5 +137,5 @@ Document.ready? do
137
137
  end
138
138
  end
139
139
  }
140
- }.render
140
+ }
141
141
  end
@@ -177,5 +177,5 @@ Document.ready? do
177
177
  computed_by: @address.members + ['state_code'],
178
178
  ]
179
179
  }
180
- }.render
180
+ }
181
181
  end
@@ -98,5 +98,5 @@ Document.ready? do
98
98
  }
99
99
  CSS
100
100
  }
101
- }.render
101
+ }
102
102
  end
@@ -113,5 +113,5 @@ Document.ready? do
113
113
  CSS
114
114
  }
115
115
  }
116
- }.render
116
+ }
117
117
  end
@@ -37,6 +37,8 @@ class HelloObserver
37
37
  end
38
38
 
39
39
  after_render do
40
+ @number_input.value = @number_holder.number
41
+ @range_input.value = @number_holder.number
40
42
  # Observe Model attribute @number_holder.number for changes and update View
41
43
  # Observer is automatically cleaned up if remove method is called on rendered HelloObserver
42
44
  # or its top-level element
@@ -54,7 +56,7 @@ class HelloObserver
54
56
  markup {
55
57
  div {
56
58
  div {
57
- @number_input = input(type: 'number', value: @number_holder.number, min: 0, max: 100) {
59
+ @number_input = input(type: 'number', min: 0, max: 100) {
58
60
  # oninput listener updates Model attribute @number_holder.number
59
61
  oninput do
60
62
  @number_holder.number = @number_input.value.to_i
@@ -68,7 +70,7 @@ class HelloObserver
68
70
  }
69
71
  }
70
72
  div {
71
- @range_input = input(type: 'range', value: @number_holder.number, min: 0, max: 100) {
73
+ @range_input = input(type: 'range', min: 0, max: 100) {
72
74
  # oninput listener updates Model attribute @number_holder.number
73
75
  oninput do
74
76
  @number_holder.number = @range_input.value.to_i
@@ -26,5 +26,5 @@ include Glimmer
26
26
  Document.ready? do
27
27
  div {
28
28
  'Hello, World!'
29
- }.render
29
+ }
30
30
  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.0.12
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-07 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer