glimmer-dsl-web 0.0.12 → 0.1.1

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: 84438bf8ca94283ebca35c684038f1ba326c9301782508bdf07b7c4e23ecb391
4
+ data.tar.gz: f7246af497c04e9c509457444ac9c17c8617aa881fca82adb4561473f1d18044
5
5
  SHA512:
6
- metadata.gz: 5732c5dca9591d17917fd6dfbd1425eed080f6aa345f6b9fb6bbbd8f3d487ce83428063b9ef974cabab8c2fdd7e6d8799b67e4442c462e6c174a4a81448900c6
7
- data.tar.gz: 34afe2b80aeb727dad38572f81f46f7d442ef2998cb97b94ae92d332364f3ff2da0669203ced36a0484304fbbcbdfb1c7cb30a8b74b49ce42abb329ce333b7de
6
+ metadata.gz: b47263b248b7952d58d9fe8fb03f0614f8c917e025310839f7ab311f33fc31e292fe257ffec8f1c487843eab7814253829c00579ea2132385b4064b75e801890
7
+ data.tar.gz: 6be5e5bab5900605d78977e703d27ac95dac303fa3855d52bd4f7dd4a1e8c8f090d49b95c57a5abe3155dde9adece9a028cfa7afc3872b9fcead2ce1a417676d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.1
4
+
5
+ - Upgrade to opal-jquery 0.5.1 (adds `# backtick_javascript: true` where needed to satisfy new Opal requirement)
6
+ - Upgrade to opal-async 1.4.1 (adds `# backtick_javascript: true` where needed to satisfy new Opal requirement)
7
+ - Update setup instructions to NOT disable Hotwire files, to allow running Hotwire/Turbo side by side with Glimmer DSL for Web (but not in the same pages)
8
+
9
+ ## 0.1.0
10
+
11
+ - Update rendering system to render HTML elements immediately instead of waiting for complete components to be rendered all at once.
12
+ - 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).
13
+ - Fix `Glimmer::Web::Component` `after_render` hook by ensuring it only fires after the component markup has been rendered
14
+
3
15
  ## 0.0.12
4
16
 
5
17
  - 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.1 (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.1'
1148
1150
  ```
1149
1151
 
1150
1152
  Run:
@@ -1189,26 +1191,28 @@ rails db:migrate
1189
1191
  Add the following to `config/routes.rb` inside the `Rails.application.routes.draw` block:
1190
1192
 
1191
1193
  ```ruby
1192
- mount Glimmer::Engine => "/glimmer" # add on top
1193
1194
  root to: 'welcomes#index'
1194
1195
  ```
1195
1196
 
1196
1197
  Clear the file `app/views/welcomes/index.html.erb` completely from all content.
1197
1198
 
1198
- Delete `app/javascript` directory
1199
+ Rename `app/assets/javascript/application.js.rb` file to `app/assets/javascript/opal_application.rb`.
1199
1200
 
1200
1201
  Rename `app/assets/javascript` directory to `app/assets/opal`.
1201
1202
 
1202
- Add the following lines to `app/assets/config/manifest.js` (and delete their `javascript` equivalents):
1203
+ Edit `app/assets/config/manifest.js` and update `//= link_directory ../javascript .js` to `//= link_directory ../opal .js`:
1203
1204
 
1204
1205
  ```js
1205
- //= link_tree ../../opal .js
1206
1206
  //= link_directory ../opal .js
1207
1207
  ```
1208
1208
 
1209
- Rename `app/assets/opal/application.js.rb` to `app/assets/opal/application.rb`.
1209
+ Edit `app/views/layouts/application.html.erb` and update `<%= javascript_include_tag "application", "data-turbolinks-track": "reload" %>` to `<%= javascript_include_tag "opal_application", "data-turbolinks-track": "reload" %>`:
1210
1210
 
1211
- Edit and replace `app/assets/opal/application.rb` content with code below (optionally including a require statement for one of the [samples](#samples) below):
1211
+ ```erb
1212
+ <%= javascript_include_tag "opal_application", "data-turbolinks-track": "reload" %>
1213
+ ```
1214
+
1215
+ Edit and replace `app/assets/opal/opal_application.rb` content with code below (optionally including a require statement for one of the [samples](#samples) below):
1212
1216
 
1213
1217
  ```ruby
1214
1218
  require 'glimmer-dsl-web' # brings opal and other dependencies automatically
@@ -1247,7 +1251,7 @@ Document.ready? do
1247
1251
  label(class: 'greeting') {
1248
1252
  'Hello, World!'
1249
1253
  }
1250
- }.render
1254
+ }
1251
1255
  end
1252
1256
  ```
1253
1257
 
@@ -1298,7 +1302,7 @@ Document.ready? do
1298
1302
  label(class: 'greeting') {
1299
1303
  'Hello, World!'
1300
1304
  }
1301
- }.render
1305
+ }
1302
1306
  end
1303
1307
  ```
1304
1308
 
@@ -1315,6 +1319,7 @@ That produces:
1315
1319
  </div>
1316
1320
  ...
1317
1321
  ```
1322
+
1318
1323
  You may insert a Glimmer component anywhere into a Rails View using `glimmer_component(component_path, *args)` Rails helper. Add `include GlimmerHelper` to `ApplicationHelper` or another Rails helper, and use `<%= glimmer_component("path/to/component", *args) %>` in Views.
1319
1324
 
1320
1325
  To use `glimmer_component`, edit `app/helpers/application_helper.rb` in your Rails application, add `require 'glimmer/helpers/glimmer_helper'` on top and `include GlimmerHelper` inside `module`.
@@ -1331,6 +1336,8 @@ module ApplicationHelper
1331
1336
  end
1332
1337
  ```
1333
1338
 
1339
+ Note that Turbo is disabled on Glimmer elements/components. You can still use Turbo/Hotwire side by side with Glimmer DSL for Web by using one of the two technologies in every page. But, mixing them in the same pages is not recommended at the moment, so any pages loaded with Glimmer DSL for Web must be loaded without Turbo (e.g. by putting "data-turbo"="false" on anchor "a" tag links to Glimmer pages).
1340
+
1334
1341
  If you run into any issues in setup, refer to the [Sample Glimmer DSL for Web Rails 7 App](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails7-app) project (in case I forgot to include some setup steps by mistake).
1335
1342
 
1336
1343
  Otherwise, if you still cannot setup successfully (even with the help of the sample project, or if the sample project stops working), please do not hesitate to report an [Issue request](https://github.com/AndyObtiva/glimmer-dsl-web/issues) or fix and submit a [Pull Request](https://github.com/AndyObtiva/glimmer-dsl-web/pulls).
@@ -1360,7 +1367,7 @@ Disable the `webpacker` gem line in `Gemfile`:
1360
1367
  Add the following to `Gemfile`:
1361
1368
 
1362
1369
  ```ruby
1363
- gem 'glimmer-dsl-web', '~> 0.0.12'
1370
+ gem 'glimmer-dsl-web', '~> 0.1.1'
1364
1371
  ```
1365
1372
 
1366
1373
  Run:
@@ -1405,10 +1412,8 @@ rails db:migrate
1405
1412
  Add the following to `config/routes.rb` inside the `Rails.application.routes.draw` block:
1406
1413
 
1407
1414
  ```ruby
1408
- mount Glimmer::Engine => "/glimmer" # add on top
1409
1415
  root to: 'welcomes#index'
1410
1416
  ```
1411
- ```
1412
1417
 
1413
1418
  Also, delete the following line:
1414
1419
 
@@ -1418,18 +1423,23 @@ Also, delete the following line:
1418
1423
 
1419
1424
  Clear the file `app/views/welcomes/index.html.erb` completely from all content.
1420
1425
 
1426
+ Rename `app/assets/javascript/application.js.rb` file to `app/assets/javascript/opal_application.rb`.
1427
+
1421
1428
  Rename `app/assets/javascript` directory to `app/assets/opal`.
1422
1429
 
1423
- Add the following lines to `app/assets/config/manifest.js` (and delete their `javascript` equivalents):
1430
+ Edit `app/assets/config/manifest.js` and update `//= link_directory ../javascript .js` to `//= link_directory ../opal .js`:
1424
1431
 
1425
1432
  ```js
1426
- //= link_tree ../../opal .js
1427
1433
  //= link_directory ../opal .js
1428
1434
  ```
1429
1435
 
1430
- Rename `app/assets/opal/application.js.rb` to `app/assets/opal/application.rb`.
1436
+ Edit `app/views/layouts/application.html.erb` and update `<%= javascript_include_tag "application", "data-turbolinks-track": "reload" %>` to `<%= javascript_include_tag "opal_application", "data-turbolinks-track": "reload" %>`:
1437
+
1438
+ ```erb
1439
+ <%= javascript_include_tag "opal_application", "data-turbolinks-track": "reload" %>
1440
+ ```
1431
1441
 
1432
- Edit and replace `app/assets/opal/application.rb` content with code below (optionally including a require statement for one of the [samples](#samples) below inside a `Document.ready? do; end` block):
1442
+ Edit and replace `app/assets/opal/opal_application.rb` content with code below (optionally including a require statement for one of the [samples](#samples) below):
1433
1443
 
1434
1444
  ```ruby
1435
1445
  require 'glimmer-dsl-web' # brings opal and other dependencies automatically
@@ -1461,7 +1471,7 @@ Document.ready? do
1461
1471
  label(class: 'greeting') {
1462
1472
  'Hello, World!'
1463
1473
  }
1464
- }.render
1474
+ }
1465
1475
  end
1466
1476
  ```
1467
1477
 
@@ -1506,6 +1516,8 @@ module ApplicationHelper
1506
1516
  end
1507
1517
  ```
1508
1518
 
1519
+ Note that Turbo is disabled on Glimmer elements/components. You can still use Turbo/Hotwire side by side with Glimmer DSL for Web by using one of the two technologies in every page. But, mixing them in the same pages is not recommended at the moment, so any pages loaded with Glimmer DSL for Web must be loaded without Turbo (e.g. by putting "data-turbo"="false" on anchor "a" tag links to Glimmer pages).
1520
+
1509
1521
  **NOT RELEASED OR SUPPORTED YET**
1510
1522
 
1511
1523
  If you run into any issues in setup, refer to the [Sample Glimmer DSL for Web Rails 6 App](https://github.com/AndyObtiva/sample-glimmer-dsl-web-rails6-app) project (in case I forgot to include some setup steps by mistake).
@@ -1616,7 +1628,7 @@ include Glimmer
1616
1628
  Document.ready? do
1617
1629
  div {
1618
1630
  'Hello, World!'
1619
- }.render
1631
+ }
1620
1632
  end
1621
1633
  ```
1622
1634
 
@@ -1638,7 +1650,7 @@ require 'glimmer-dsl-web'
1638
1650
  include Glimmer
1639
1651
 
1640
1652
  Document.ready? do
1641
- div('Hello, World!').render
1653
+ div('Hello, World!')
1642
1654
  end
1643
1655
  ```
1644
1656
 
@@ -1670,7 +1682,7 @@ Document.ready? do
1670
1682
  $$.alert('Hello, Button!')
1671
1683
  end
1672
1684
  }
1673
- }.render
1685
+ }
1674
1686
  end
1675
1687
  ```
1676
1688
 
@@ -1771,7 +1783,7 @@ Document.ready? do
1771
1783
  }
1772
1784
  CSS
1773
1785
  }
1774
- }.render
1786
+ }
1775
1787
  end
1776
1788
  ```
1777
1789
 
@@ -1866,6 +1878,8 @@ class HelloObserver
1866
1878
  end
1867
1879
 
1868
1880
  after_render do
1881
+ @number_input.value = @number_holder.number
1882
+ @range_input.value = @number_holder.number
1869
1883
  # Observe Model attribute @number_holder.number for changes and update View
1870
1884
  # Observer is automatically cleaned up if remove method is called on rendered HelloObserver
1871
1885
  # or its top-level element
@@ -1883,7 +1897,7 @@ class HelloObserver
1883
1897
  markup {
1884
1898
  div {
1885
1899
  div {
1886
- @number_input = input(type: 'number', value: @number_holder.number, min: 0, max: 100) {
1900
+ @number_input = input(type: 'number', min: 0, max: 100) {
1887
1901
  # oninput listener updates Model attribute @number_holder.number
1888
1902
  oninput do
1889
1903
  @number_holder.number = @number_input.value.to_i
@@ -1897,7 +1911,7 @@ class HelloObserver
1897
1911
  }
1898
1912
  }
1899
1913
  div {
1900
- @range_input = input(type: 'range', value: @number_holder.number, min: 0, max: 100) {
1914
+ @range_input = input(type: 'range', min: 0, max: 100) {
1901
1915
  # oninput listener updates Model attribute @number_holder.number
1902
1916
  oninput do
1903
1917
  @number_holder.number = @range_input.value.to_i
@@ -2088,7 +2102,7 @@ Document.ready? do
2088
2102
  computed_by: @address.members + ['state_code'],
2089
2103
  ]
2090
2104
  }
2091
- }.render
2105
+ }
2092
2106
  end
2093
2107
  ```
2094
2108
 
@@ -2223,7 +2237,7 @@ Document.ready? do
2223
2237
  end
2224
2238
  end
2225
2239
  }
2226
- }.render
2240
+ }
2227
2241
  end
2228
2242
  ```
2229
2243
 
@@ -2849,7 +2863,7 @@ Document.ready? do
2849
2863
  CSS
2850
2864
  }
2851
2865
  }
2852
- }.render
2866
+ }
2853
2867
  end
2854
2868
  ```
2855
2869
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.1.1
@@ -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.1 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.1".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 = [
@@ -79,8 +79,8 @@ Gem::Specification.new do |s|
79
79
  s.add_runtime_dependency(%q<glimmer-dsl-css>.freeze, ["~> 1.2.2".freeze])
80
80
  s.add_runtime_dependency(%q<opal>.freeze, ["= 1.8.2".freeze])
81
81
  s.add_runtime_dependency(%q<opal-rails>.freeze, ["= 2.0.3".freeze])
82
- s.add_runtime_dependency(%q<opal-async>.freeze, ["~> 1.4.0".freeze])
83
- s.add_runtime_dependency(%q<opal-jquery>.freeze, ["~> 0.5.0".freeze])
82
+ s.add_runtime_dependency(%q<opal-async>.freeze, ["~> 1.4.1".freeze])
83
+ s.add_runtime_dependency(%q<opal-jquery>.freeze, ["~> 0.5.1".freeze])
84
84
  s.add_runtime_dependency(%q<to_collection>.freeze, [">= 2.0.1".freeze, "< 3.0.0".freeze])
85
85
  s.add_development_dependency(%q<puts_debuggerer>.freeze, [">= 0".freeze])
86
86
  s.add_development_dependency(%q<rake>.freeze, [">= 10.1.0".freeze, "< 14.0.0".freeze])
@@ -7,24 +7,27 @@ module GlimmerHelper
7
7
  end
8
8
 
9
9
  def glimmer_component(component_asset_path, *component_args)
10
- component_file = component_asset_path.split('/').last
11
- component_class_name = component_file.classify
10
+ component_file = component_asset_path.split('/').last # TODO support namespaced components
11
+ component_class_name = component_file.classify # TODO support namespaced components
12
12
  next_id_number = GlimmerHelper.next_id_number
13
13
  component_id = "glimmer_component_#{next_id_number}"
14
14
  component_script_container_id = "glimmer_component_script_container_#{next_id_number}"
15
15
  component_args_json = JSON.dump(component_args)
16
- opal_script = <<~Opal
16
+ opal_script = <<~OPAL
17
17
  require 'glimmer-dsl-web'
18
18
  component_args_json = '#{component_args_json}'
19
19
  component_args = JSON.parse(component_args_json)
20
20
  component_args << {} if !component_args.last.is_a?(Hash)
21
21
  component_args.last[:parent] = "##{component_id}"
22
22
  #{component_class_name}.render(*component_args)
23
- Opal
24
- content_tag(:div, id: component_script_container_id, class: ['glimmer_component_script_container', "#{component_file}_script_container"]) do
23
+ OPAL
24
+ js_script = <<~JAVASCRIPT
25
+ Opal.eval(`#{opal_script}`)
26
+ JAVASCRIPT
27
+ content_tag(:div, id: component_script_container_id, class: ['glimmer_component_script_container', "#{component_file}_script_container"], 'data-turbo': 'false') do
25
28
  content_tag(:div, '', id: component_id, class: ['glimmer_component', component_file]) +
26
29
  javascript_include_tag(component_asset_path, "data-turbolinks-track": "reload") +
27
- content_tag(:script, raw(opal_script), type: 'text/ruby')
30
+ content_tag(:script, raw(js_script), type: 'application/javascript', "data-turbo-eval": "false")
28
31
  end
29
32
  end
30
33
  end
@@ -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)
@@ -243,7 +253,6 @@ module Glimmer
243
253
  brand_new = @dom.nil? || old_element.empty? || !options[:parent].to_s.empty? || brand_new
244
254
  build_dom(layout: !custom_parent_dom_element) # TODO handle custom parent layout by passing parent instead of parent dom element
245
255
  if brand_new
246
- # TODO make a method attach to allow subclasses to override if needed
247
256
  attach(the_parent_dom_element)
248
257
  else
249
258
  reattach(old_element)
@@ -253,8 +262,10 @@ module Glimmer
253
262
  handle_observation_request(keyword, event_listener)
254
263
  end
255
264
  end
256
- children.each do |child|
257
- child.render
265
+ unless render_after_create?
266
+ children.each do |child|
267
+ child.render
268
+ end
258
269
  end
259
270
  @rendered = true
260
271
  unless skip_content_on_render_blocks?
@@ -262,6 +273,10 @@ module Glimmer
262
273
  content(&content_block)
263
274
  end
264
275
  end
276
+ # TODO replace following line with a method call like (`notify_listeners('on_render')`)
277
+ listeners_for('on_render').each do |listener|
278
+ listener.original_event_listener.call(EventProxy.new(listener: listener))
279
+ end
265
280
  end
266
281
  alias rerender render
267
282
 
@@ -320,6 +335,7 @@ module Glimmer
320
335
  end
321
336
  html_options[:class] ||= ''
322
337
  html_options[:class] = "#{html_options[:class]} #{body_class}".strip
338
+ html_options['data-turbo'] = 'false' if parent.nil?
323
339
  html_options
324
340
  end
325
341
 
@@ -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.1
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
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.4.0
89
+ version: 1.4.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.4.0
96
+ version: 1.4.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: opal-jquery
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.5.0
103
+ version: 0.5.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.5.0
110
+ version: 0.5.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: to_collection
113
113
  requirement: !ruby/object:Gem::Requirement