glimmer-dsl-web 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +209 -8
- data/VERSION +1 -1
- data/glimmer-dsl-web.gemspec +7 -4
- data/lib/glimmer/dsl/web/dsl.rb +2 -0
- data/lib/glimmer/dsl/web/formatting_element_expression.rb +19 -0
- data/lib/glimmer/web/element_proxy.rb +1 -0
- data/lib/glimmer/web/formatting_element_proxy.rb +56 -0
- data/lib/glimmer-dsl-web/samples/hello/hello_observer.rb +3 -1
- data/lib/glimmer-dsl-web/samples/hello/hello_paragraph.rb +67 -0
- metadata +16 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaaa7092a643511c072a409a2b771b34db6b2aa0859adc5b200e5aba0869590e
|
4
|
+
data.tar.gz: 15ba8d9639037fa17104cb997a449f42e79703ae9ec4992f21b8a7551d3b09f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5732c5dca9591d17917fd6dfbd1425eed080f6aa345f6b9fb6bbbd8f3d487ce83428063b9ef974cabab8c2fdd7e6d8799b67e4442c462e6c174a4a81448900c6
|
7
|
+
data.tar.gz: 34afe2b80aeb727dad38572f81f46f7d442ef2998cb97b94ae92d332364f3ff2da0669203ced36a0484304fbbcbdfb1c7cb30a8b74b49ce42abb329ce333b7de
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.12
|
4
|
+
|
5
|
+
- 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`.
|
6
|
+
- Treat `span` as a special text formatting element if included inside a `p` and as a normal element outside a `p`.
|
7
|
+
- Hello, Paragraph! Sample: `require 'glimmer-dsl-web/samples/hello/hello_paragraph'`
|
8
|
+
|
3
9
|
## 0.0.11
|
4
10
|
|
5
11
|
- Support element custom event listener: `on_remove`
|
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.
|
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)
|
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)
|
@@ -245,7 +245,9 @@ class HelloObserver
|
|
245
245
|
end
|
246
246
|
|
247
247
|
after_render do
|
248
|
-
#
|
248
|
+
# Observe Model attribute @number_holder.number for changes and update View
|
249
|
+
# Observer is automatically cleaned up if remove method is called on rendered HelloObserver
|
250
|
+
# or its top-level element
|
249
251
|
observe(@number_holder, :number) do
|
250
252
|
number_string = @number_holder.number.to_s
|
251
253
|
@number_input.value = number_string unless @number_input.value == number_string
|
@@ -978,6 +980,99 @@ Screenshot:
|
|
978
980
|
|
979
981
|
![Hello, glimmer_component Rails Helper!](/images/glimmer-dsl-web-samples-hello-hello-component.png)
|
980
982
|
|
983
|
+
**Hello, Paragraph!**
|
984
|
+
|
985
|
+
To facilitate building formatted textual paragraphs in Ruby, the Glimmer GUI DSL is advanced enough to behave differently when using HTML formatting elements: `<br>`, `<strong>`, `<em>`, `<br>`, `<i>`, `<sub>`, `<sup>`, `<del>`, `<ins>`, `<small>`, `<mark>`
|
986
|
+
|
987
|
+
Instead of returning Ruby objects that are nested as children within their parent, the Glimmer GUI DSL returns `String` objects directly that can be concatenated to or embedded within other `String` objects via interpolation.
|
988
|
+
|
989
|
+
This enables writing code like:
|
990
|
+
|
991
|
+
`p {"#{strong('Yesterday, ')}Robert suggested adding a new #{em('feature')} to our software product.#{br}}`
|
992
|
+
|
993
|
+
That is close to how it is written in HTML, albeit briefer in Ruby:
|
994
|
+
|
995
|
+
`<p><strong>Yesterday, </strong>Robert suggested adding a new <em>feature</em> to our software product.<br></p>`
|
996
|
+
|
997
|
+
Formatting elements just like regular elements can accept text content as their first argument or as their block return value. So, the code above could equally be written as follows:
|
998
|
+
|
999
|
+
`p {"#{strong{'Yesterday, '}}Robert suggested adding a new #{em{'feature'}} to our software product.#{br}}`
|
1000
|
+
|
1001
|
+
This enables seggregating formatting element attributes if desired, as in this example:
|
1002
|
+
|
1003
|
+
`p {"#{strong(class: 'very-string'){'Yesterday, '}}Robert suggested adding a new #{em(class: 'very-emphasized'){'feature'}} to our software product.#{br}}`
|
1004
|
+
|
1005
|
+
Another way of writing the same code is to pass the text content as the first argument, before attributes:
|
1006
|
+
|
1007
|
+
|
1008
|
+
`p {"#{strong('Yesterday, ', class: 'very-string')}Robert suggested adding a new #{em('feature', class: 'very-emphasized')} to our software product.#{br}}`
|
1009
|
+
|
1010
|
+
One last bit of info to keep in mind is that `<span>` generally generates a normal element, except when used inside a `<p>`'s content block, in which case it is assumed to be used for formatting, so
|
1011
|
+
it returns a `String` to enable code like this:
|
1012
|
+
|
1013
|
+
`p {"#{span('Yesterday, ', style: 'text-decoration: underline;')}Robert suggested adding a new #{em('feature', class: 'very-emphasized')} to our software product.#{br}}`
|
1014
|
+
|
1015
|
+
In any case, below is a full example leveraging the Glimmer GUI DSL alternative approach when utilizing formatting elements underneath a paragraph.
|
1016
|
+
|
1017
|
+
Glimmer GUI code:
|
1018
|
+
|
1019
|
+
```ruby
|
1020
|
+
require 'glimmer-dsl-web'
|
1021
|
+
|
1022
|
+
class HelloParagraph
|
1023
|
+
include Glimmer::Web::Component
|
1024
|
+
|
1025
|
+
markup {
|
1026
|
+
div {
|
1027
|
+
h1(class: 'title') {
|
1028
|
+
'Flying Cars Become 100% Safe with AI Powered Balance!'
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
p(class: 'intro') {"
|
1032
|
+
In the early 2030's, #{em('flying cars')} became affordable after their prices dropped
|
1033
|
+
below #{small(del('$100,000'))}#{ins('$80,000')} as a result of the innovations of #{strong('Travel-X')}. Still, that did not
|
1034
|
+
make #{em('flying cars')} any popular due to the extreme difficulty in piloting such flying vehicles for the average
|
1035
|
+
person, making it very tough to pass the tests for getting a piloting license given the learning curve.
|
1036
|
+
"}
|
1037
|
+
|
1038
|
+
p {"
|
1039
|
+
That said, #{b('Travel-X')} has recently come up with a new feature for their flagship #{i('flying car')},
|
1040
|
+
the Ptero#{sub(1)}#{sup('TM')}, which relies on AI#{sub(2)} to automatically balance the flying cars in mid-air,
|
1041
|
+
thus significantly facilitating their piloting by the average consumer.
|
1042
|
+
"}
|
1043
|
+
|
1044
|
+
p(class: 'conclusion') {"
|
1045
|
+
That Ptero#{sup('TM')} will be so stable and well balanced while flying that the consumer will be able to drive
|
1046
|
+
as if it is a plain old car, with the only difference being vertical elevation, the control of which will be handled
|
1047
|
+
automatically by AI. The Ptero#{sup('TM')} will debut for #{span(style: 'text-decoration: underline dashed;'){'$79,000'}}.
|
1048
|
+
"}
|
1049
|
+
|
1050
|
+
h2(class: 'legend-title') {
|
1051
|
+
mark('Legend:')
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
p(class: 'legend') {"
|
1055
|
+
#{strong("1- Ptero:")} Pterosaur is flying dinosaur species#{br}
|
1056
|
+
#{strong("2- AI:")} Artificial Intelligence#{br}
|
1057
|
+
"}
|
1058
|
+
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
Document.ready? do
|
1064
|
+
HelloParagraph.render
|
1065
|
+
end
|
1066
|
+
```
|
1067
|
+
|
1068
|
+
Screenshot:
|
1069
|
+
|
1070
|
+
--
|
1071
|
+
|
1072
|
+
![Hello, Paragraph!](/images/glimmer-dsl-web-samples-hello-hello-paragraph.png)
|
1073
|
+
|
1074
|
+
--
|
1075
|
+
|
981
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.
|
982
1077
|
|
983
1078
|
Learn more about the differences between various [Glimmer](https://github.com/AndyObtiva/glimmer) DSLs by looking at:
|
@@ -987,8 +1082,6 @@ Learn more about the differences between various [Glimmer](https://github.com/An
|
|
987
1082
|
## Table of Contents
|
988
1083
|
|
989
1084
|
- [Glimmer DSL for Web](#-glimmer-dsl-for-opal-alpha-pure-ruby-web-gui)
|
990
|
-
- [Principles](#principles)
|
991
|
-
- [Background](#background)
|
992
1085
|
- [Prerequisites](#prerequisites)
|
993
1086
|
- [Setup](#setup)
|
994
1087
|
- [Usage](#usage)
|
@@ -1004,8 +1097,11 @@ Learn more about the differences between various [Glimmer](https://github.com/An
|
|
1004
1097
|
- [Hello, Content Data-Binding!](#hello-content-data-binding)
|
1005
1098
|
- [Hello, Component!](#hello-content-data-binding)
|
1006
1099
|
- [Hello, glimmer_component Rails Helper!](#hello-glimmer_component-rails-helper)
|
1100
|
+
- [Hello, Paragraph!](#hello-paragraph)
|
1007
1101
|
- [Hello, Input (Date/Time)!](#hello-input-datetime)
|
1008
1102
|
- [Button Counter](#button-counter)
|
1103
|
+
- [Design Principles](#design-principles)
|
1104
|
+
- [Supporting Libraries](#supporting-libraries)
|
1009
1105
|
- [Glimmer Process](#glimmer-process)
|
1010
1106
|
- [Help](#help)
|
1011
1107
|
- [Issues](#issues)
|
@@ -1048,7 +1144,7 @@ rails new glimmer_app_server
|
|
1048
1144
|
Add the following to `Gemfile`:
|
1049
1145
|
|
1050
1146
|
```
|
1051
|
-
gem 'glimmer-dsl-web', '~> 0.0.
|
1147
|
+
gem 'glimmer-dsl-web', '~> 0.0.12'
|
1052
1148
|
```
|
1053
1149
|
|
1054
1150
|
Run:
|
@@ -1264,7 +1360,7 @@ Disable the `webpacker` gem line in `Gemfile`:
|
|
1264
1360
|
Add the following to `Gemfile`:
|
1265
1361
|
|
1266
1362
|
```ruby
|
1267
|
-
gem 'glimmer-dsl-web', '~> 0.0.
|
1363
|
+
gem 'glimmer-dsl-web', '~> 0.0.12'
|
1268
1364
|
```
|
1269
1365
|
|
1270
1366
|
Run:
|
@@ -1770,7 +1866,9 @@ class HelloObserver
|
|
1770
1866
|
end
|
1771
1867
|
|
1772
1868
|
after_render do
|
1773
|
-
#
|
1869
|
+
# Observe Model attribute @number_holder.number for changes and update View
|
1870
|
+
# Observer is automatically cleaned up if remove method is called on rendered HelloObserver
|
1871
|
+
# or its top-level element
|
1774
1872
|
observe(@number_holder, :number) do
|
1775
1873
|
number_string = @number_holder.number.to_s
|
1776
1874
|
@number_input.value = number_string unless @number_input.value == number_string
|
@@ -2559,6 +2657,98 @@ Screenshot:
|
|
2559
2657
|
|
2560
2658
|
![Hello, glimmer_component Rails Helper!](/images/glimmer-dsl-web-samples-hello-hello-component.png)
|
2561
2659
|
|
2660
|
+
#### Hello, Paragraph!
|
2661
|
+
|
2662
|
+
To facilitate building formatted textual paragraphs in Ruby, the Glimmer GUI DSL is advanced enough to behave differently when using HTML formatting elements: `<br>`, `<strong>`, `<em>`, `<br>`, `<i>`, `<sub>`, `<sup>`, `<del>`, `<ins>`, `<small>`, `<mark>`
|
2663
|
+
|
2664
|
+
Instead of returning Ruby objects that are nested as children within their parent, the Glimmer GUI DSL returns `String` objects directly that can be concatenated to or embedded within other `String` objects via interpolation.
|
2665
|
+
|
2666
|
+
This enables writing code like:
|
2667
|
+
|
2668
|
+
`p {"#{strong('Yesterday, ')}Robert suggested adding a new #{em('feature')} to our software product.#{br}}`
|
2669
|
+
|
2670
|
+
That is close to how it is written in HTML, albeit briefer in Ruby:
|
2671
|
+
|
2672
|
+
`<p><strong>Yesterday, </strong>Robert suggested adding a new <em>feature</em> to our software product.<br></p>`
|
2673
|
+
|
2674
|
+
Formatting elements just like regular elements can accept text content as their first argument or as their block return value. So, the code above could equally be written as follows:
|
2675
|
+
|
2676
|
+
`p {"#{strong{'Yesterday, '}}Robert suggested adding a new #{em{'feature'}} to our software product.#{br}}`
|
2677
|
+
|
2678
|
+
This enables seggregating formatting element attributes if desired, as in this example:
|
2679
|
+
|
2680
|
+
`p {"#{strong(class: 'very-string'){'Yesterday, '}}Robert suggested adding a new #{em(class: 'very-emphasized'){'feature'}} to our software product.#{br}}`
|
2681
|
+
|
2682
|
+
Another way of writing the same code is to pass the text content as the first argument, before attributes:
|
2683
|
+
|
2684
|
+
|
2685
|
+
`p {"#{strong('Yesterday, ', class: 'very-string')}Robert suggested adding a new #{em('feature', class: 'very-emphasized')} to our software product.#{br}}`
|
2686
|
+
|
2687
|
+
One last bit of info to keep in mind is that `<span>` generally generates a normal element, except when used inside a `<p>`'s content block, in which case it is assumed to be used for formatting, so
|
2688
|
+
it returns a `String` to enable code like this:
|
2689
|
+
|
2690
|
+
`p {"#{span('Yesterday, ', style: 'text-decoration: underline;')}Robert suggested adding a new #{em('feature', class: 'very-emphasized')} to our software product.#{br}}`
|
2691
|
+
|
2692
|
+
In any case, below is a full example leveraging the Glimmer GUI DSL alternative approach when utilizing formatting elements underneath a paragraph.
|
2693
|
+
|
2694
|
+
Glimmer GUI code:
|
2695
|
+
|
2696
|
+
```ruby
|
2697
|
+
require 'glimmer-dsl-web'
|
2698
|
+
|
2699
|
+
class HelloParagraph
|
2700
|
+
include Glimmer::Web::Component
|
2701
|
+
|
2702
|
+
markup {
|
2703
|
+
div {
|
2704
|
+
h1(class: 'title') {
|
2705
|
+
'Flying Cars Become 100% Safe with AI Powered Balance!'
|
2706
|
+
}
|
2707
|
+
|
2708
|
+
p(class: 'intro') {"
|
2709
|
+
In the early 2030's, #{em('flying cars')} became affordable after their prices dropped
|
2710
|
+
below #{small(del('$100,000'))}#{ins('$80,000')} as a result of the innovations of #{strong('Travel-X')}. Still, that did not
|
2711
|
+
make #{em('flying cars')} any popular due to the extreme difficulty in piloting such flying vehicles for the average
|
2712
|
+
person, making it very tough to pass the tests for getting a piloting license given the learning curve.
|
2713
|
+
"}
|
2714
|
+
|
2715
|
+
p {"
|
2716
|
+
That said, #{b('Travel-X')} has recently come up with a new feature for their flagship #{i('flying car')},
|
2717
|
+
the Ptero#{sub(1)}#{sup('TM')}, which relies on AI#{sub(2)} to automatically balance the flying cars in mid-air,
|
2718
|
+
thus significantly facilitating their piloting by the average consumer.
|
2719
|
+
"}
|
2720
|
+
|
2721
|
+
p(class: 'conclusion') {"
|
2722
|
+
That Ptero#{sup('TM')} will be so stable and well balanced while flying that the consumer will be able to drive
|
2723
|
+
as if it is a plain old car, with the only difference being vertical elevation, the control of which will be handled
|
2724
|
+
automatically by AI. The Ptero#{sup('TM')} will debut for #{span(style: 'text-decoration: underline dashed;'){'$79,000'}}.
|
2725
|
+
"}
|
2726
|
+
|
2727
|
+
h2(class: 'legend-title') {
|
2728
|
+
mark('Legend:')
|
2729
|
+
}
|
2730
|
+
|
2731
|
+
p(class: 'legend') {"
|
2732
|
+
#{strong("1- Ptero:")} Pterosaur is flying dinosaur species#{br}
|
2733
|
+
#{strong("2- AI:")} Artificial Intelligence#{br}
|
2734
|
+
"}
|
2735
|
+
|
2736
|
+
}
|
2737
|
+
}
|
2738
|
+
end
|
2739
|
+
|
2740
|
+
Document.ready? do
|
2741
|
+
HelloParagraph.render
|
2742
|
+
end
|
2743
|
+
```
|
2744
|
+
|
2745
|
+
Screenshot:
|
2746
|
+
|
2747
|
+
--
|
2748
|
+
|
2749
|
+
![Hello, Paragraph!](/images/glimmer-dsl-web-samples-hello-hello-paragraph.png)
|
2750
|
+
|
2751
|
+
--
|
2562
2752
|
|
2563
2753
|
#### Hello, Input (Date/Time)!
|
2564
2754
|
|
@@ -2744,7 +2934,18 @@ Screenshot:
|
|
2744
2934
|
|
2745
2935
|
![Button Counter](/images/glimmer-dsl-web-samples-regular-button-counter.gif)
|
2746
2936
|
|
2747
|
-
##
|
2937
|
+
## Design Principles
|
2938
|
+
|
2939
|
+
- The Ruby Way (including TIMTOWTDI: There Is More Than One Way To Do It)
|
2940
|
+
- The Rails Way Convention over Configuration via smart defaults and automation of low-level details
|
2941
|
+
- Requiring the least amount of syntax possible to build highly interactive web pages
|
2942
|
+
- Declarative syntax that visually maps to the DOM (Document Object Model) hierarchy
|
2943
|
+
- Ability to mix declarative and imperative code conveniently in one language
|
2944
|
+
- Computers serve Software Engineers (not Software Engineers serve Computers)
|
2945
|
+
- Think only about real world concepts directly relevant to web page interaction
|
2946
|
+
- Modular Software Design (e.g. support for Components)
|
2947
|
+
|
2948
|
+
## Supporting Libraries
|
2748
2949
|
|
2749
2950
|
Here is a list of notable 3rd party gems used by Glimmer DSL for Web:
|
2750
2951
|
- [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML & HTML in pure Ruby.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/glimmer-dsl-web.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
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.
|
5
|
+
# stub: glimmer-dsl-web 0.0.12 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-web".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.12".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-
|
15
|
-
s.description = "Glimmer DSL for Web (Ruby in the Browser Web GUI Frontend Library)
|
14
|
+
s.date = "2024-01-07"
|
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 = [
|
18
18
|
"CHANGELOG.md",
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/glimmer-dsl-web/samples/hello/hello_glimmer_component_helper/address_form.rb",
|
39
39
|
"lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb",
|
40
40
|
"lib/glimmer-dsl-web/samples/hello/hello_observer.rb",
|
41
|
+
"lib/glimmer-dsl-web/samples/hello/hello_paragraph.rb",
|
41
42
|
"lib/glimmer-dsl-web/samples/hello/hello_world.rb",
|
42
43
|
"lib/glimmer-dsl-web/samples/regular/button_counter.rb",
|
43
44
|
"lib/glimmer-dsl-web/vendor/jquery.js",
|
@@ -49,6 +50,7 @@ Gem::Specification.new do |s|
|
|
49
50
|
"lib/glimmer/dsl/web/data_binding_expression.rb",
|
50
51
|
"lib/glimmer/dsl/web/dsl.rb",
|
51
52
|
"lib/glimmer/dsl/web/element_expression.rb",
|
53
|
+
"lib/glimmer/dsl/web/formatting_element_expression.rb",
|
52
54
|
"lib/glimmer/dsl/web/general_element_expression.rb",
|
53
55
|
"lib/glimmer/dsl/web/listener_expression.rb",
|
54
56
|
"lib/glimmer/dsl/web/observe_expression.rb",
|
@@ -62,6 +64,7 @@ Gem::Specification.new do |s|
|
|
62
64
|
"lib/glimmer/web/component.rb",
|
63
65
|
"lib/glimmer/web/element_proxy.rb",
|
64
66
|
"lib/glimmer/web/event_proxy.rb",
|
67
|
+
"lib/glimmer/web/formatting_element_proxy.rb",
|
65
68
|
"lib/glimmer/web/listener_proxy.rb"
|
66
69
|
]
|
67
70
|
s.homepage = "http://github.com/AndyObtiva/glimmer-dsl-web".freeze
|
data/lib/glimmer/dsl/web/dsl.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
|
22
22
|
require 'glimmer/dsl/engine'
|
23
23
|
require 'glimmer/dsl/web/element_expression'
|
24
|
+
require 'glimmer/dsl/web/formatting_element_expression'
|
24
25
|
require 'glimmer/dsl/web/listener_expression'
|
25
26
|
require 'glimmer/dsl/web/property_expression'
|
26
27
|
require 'glimmer/dsl/web/p_expression'
|
@@ -44,6 +45,7 @@ module Glimmer
|
|
44
45
|
property
|
45
46
|
content_data_binding
|
46
47
|
shine_data_binding
|
48
|
+
formatting_element
|
47
49
|
element
|
48
50
|
]
|
49
51
|
)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'glimmer/dsl/expression'
|
2
|
+
|
3
|
+
require 'glimmer/web/formatting_element_proxy'
|
4
|
+
|
5
|
+
module Glimmer
|
6
|
+
module DSL
|
7
|
+
module Web
|
8
|
+
class FormattingElementExpression < Expression
|
9
|
+
def can_interpret?(parent, keyword, *args, &block)
|
10
|
+
Glimmer::Web::FormattingElementProxy.keyword_supported?(keyword, parent: parent)
|
11
|
+
end
|
12
|
+
|
13
|
+
def interpret(parent, keyword, *args, &block)
|
14
|
+
Glimmer::Web::FormattingElementProxy.format(keyword, *args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -302,6 +302,7 @@ module Glimmer
|
|
302
302
|
|
303
303
|
def dom
|
304
304
|
# TODO auto-convert known glimmer attributes like parent to data attributes like data-parent
|
305
|
+
# TODO check if we need to avoid rendering content block if no content is available
|
305
306
|
@dom ||= html {
|
306
307
|
send(keyword, html_options) {
|
307
308
|
args.first if args.first.is_a?(String)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# backtick_javascript: true
|
2
|
+
|
3
|
+
# Copyright (c) 2023-2024 Andy Maleh
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module Web
|
26
|
+
class FormattingElementProxy
|
27
|
+
class << self
|
28
|
+
include Glimmer
|
29
|
+
|
30
|
+
def keyword_supported?(keyword, parent: nil)
|
31
|
+
keyword = keyword.to_s
|
32
|
+
(
|
33
|
+
FORMATTING_ELEMENT_KEYWORDS.include?(keyword) ||
|
34
|
+
(parent&.keyword == 'p' && keyword == 'span')
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def format(keyword, *args, &block)
|
39
|
+
content = nil
|
40
|
+
if block_given?
|
41
|
+
content = block.call.to_s
|
42
|
+
elsif args.any? && !args.first.is_a?(Hash)
|
43
|
+
content = args.first.to_s
|
44
|
+
end
|
45
|
+
attribute_hash = args.last.is_a?(Hash) ? args.last : {}
|
46
|
+
content_block = proc { content } unless content.nil?
|
47
|
+
html {
|
48
|
+
send(keyword, attribute_hash, &content_block)
|
49
|
+
}.to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
FORMATTING_ELEMENT_KEYWORDS = %w[b i strong em sub sup del ins small mark br]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -37,7 +37,9 @@ class HelloObserver
|
|
37
37
|
end
|
38
38
|
|
39
39
|
after_render do
|
40
|
-
#
|
40
|
+
# Observe Model attribute @number_holder.number for changes and update View
|
41
|
+
# Observer is automatically cleaned up if remove method is called on rendered HelloObserver
|
42
|
+
# or its top-level element
|
41
43
|
observe(@number_holder, :number) do
|
42
44
|
number_string = @number_holder.number.to_s
|
43
45
|
@number_input.value = number_string unless @number_input.value == number_string
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2023-2024 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer-dsl-web'
|
23
|
+
|
24
|
+
class HelloParagraph
|
25
|
+
include Glimmer::Web::Component
|
26
|
+
|
27
|
+
markup {
|
28
|
+
div {
|
29
|
+
h1(class: 'title') {
|
30
|
+
'Flying Cars Become 100% Safe with AI Powered Balance!'
|
31
|
+
}
|
32
|
+
|
33
|
+
p(class: 'intro') {"
|
34
|
+
In the early 2030's, #{em('flying cars')} became affordable after their prices dropped
|
35
|
+
below #{small(del('$100,000'))}#{ins('$80,000')} as a result of the innovations of #{strong('Travel-X')}. Still, that did not
|
36
|
+
make #{em('flying cars')} any popular due to the extreme difficulty in piloting such flying vehicles for the average
|
37
|
+
person, making it very tough to pass the tests for getting a piloting license given the learning curve.
|
38
|
+
"}
|
39
|
+
|
40
|
+
p {"
|
41
|
+
That said, #{b('Travel-X')} has recently come up with a new feature for their flagship #{i('flying car')},
|
42
|
+
the Ptero#{sub(1)}#{sup('TM')}, which relies on AI#{sub(2)} to automatically balance the flying cars in mid-air,
|
43
|
+
thus significantly facilitating their piloting by the average consumer.
|
44
|
+
"}
|
45
|
+
|
46
|
+
p(class: 'conclusion') {"
|
47
|
+
That Ptero#{sup('TM')} will be so stable and well balanced while flying that the consumer will be able to drive
|
48
|
+
as if it is a plain old car, with the only difference being vertical elevation, the control of which will be handled
|
49
|
+
automatically by AI. The Ptero#{sup('TM')} will debut for #{span(style: 'text-decoration: underline dashed;'){'$79,000'}}.
|
50
|
+
"}
|
51
|
+
|
52
|
+
h2(class: 'legend-title') {
|
53
|
+
mark('Legend:')
|
54
|
+
}
|
55
|
+
|
56
|
+
p(class: 'legend') {"
|
57
|
+
#{strong("1- Ptero:")} Pterosaur is flying dinosaur species#{br}
|
58
|
+
#{strong("2- AI:")} Artificial Intelligence#{br}
|
59
|
+
"}
|
60
|
+
|
61
|
+
}
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
Document.ready? do
|
66
|
+
HelloParagraph.render
|
67
|
+
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.
|
4
|
+
version: 0.0.12
|
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-
|
11
|
+
date: 2024-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -230,10 +230,17 @@ dependencies:
|
|
230
230
|
- - "~>"
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: 0.8.0.alpha2
|
233
|
-
description: Glimmer DSL for Web (Ruby in the Browser Web GUI Frontend Library)
|
234
|
-
|
235
|
-
|
236
|
-
|
233
|
+
description: Glimmer DSL for Web (Ruby in the Browser Web GUI Frontend Library) enables
|
234
|
+
building Web GUI frontends using Ruby in the Browser, as per Matz's recommendation
|
235
|
+
in his RubyConf 2022 keynote speech to replace JavaScript with Ruby. It aims at
|
236
|
+
providing the simplest, most intuitive, most straight-forward, and most productive
|
237
|
+
frontend library in existence. The library follows the Ruby way (with DSLs and TIMTOWTDI)
|
238
|
+
and the Rails way (Convention over Configuration) while supporting both Unidirectional
|
239
|
+
(One-Way) Data-Binding (using <=) and Bidirectional (Two-Way) Data-Binding (using
|
240
|
+
<=>). Dynamic rendering (and re-rendering) of HTML content is also supported via
|
241
|
+
Content Data-Binding. And, modular design is supported with Glimmer Web Components.
|
242
|
+
You can finally live in pure Rubyland on the Web in both the frontend and backend
|
243
|
+
with Glimmer DSL for Web! This library relies on Opal Ruby.
|
237
244
|
email: andy.am@gmail.com
|
238
245
|
executables: []
|
239
246
|
extensions: []
|
@@ -260,6 +267,7 @@ files:
|
|
260
267
|
- lib/glimmer-dsl-web/samples/hello/hello_glimmer_component_helper/address_form.rb
|
261
268
|
- lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb
|
262
269
|
- lib/glimmer-dsl-web/samples/hello/hello_observer.rb
|
270
|
+
- lib/glimmer-dsl-web/samples/hello/hello_paragraph.rb
|
263
271
|
- lib/glimmer-dsl-web/samples/hello/hello_world.rb
|
264
272
|
- lib/glimmer-dsl-web/samples/regular/button_counter.rb
|
265
273
|
- lib/glimmer-dsl-web/vendor/jquery.js
|
@@ -271,6 +279,7 @@ files:
|
|
271
279
|
- lib/glimmer/dsl/web/data_binding_expression.rb
|
272
280
|
- lib/glimmer/dsl/web/dsl.rb
|
273
281
|
- lib/glimmer/dsl/web/element_expression.rb
|
282
|
+
- lib/glimmer/dsl/web/formatting_element_expression.rb
|
274
283
|
- lib/glimmer/dsl/web/general_element_expression.rb
|
275
284
|
- lib/glimmer/dsl/web/listener_expression.rb
|
276
285
|
- lib/glimmer/dsl/web/observe_expression.rb
|
@@ -284,6 +293,7 @@ files:
|
|
284
293
|
- lib/glimmer/web/component.rb
|
285
294
|
- lib/glimmer/web/element_proxy.rb
|
286
295
|
- lib/glimmer/web/event_proxy.rb
|
296
|
+
- lib/glimmer/web/formatting_element_proxy.rb
|
287
297
|
- lib/glimmer/web/listener_proxy.rb
|
288
298
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-web
|
289
299
|
licenses:
|