glimmer-dsl-web 0.1.1 → 0.2.2

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: 84438bf8ca94283ebca35c684038f1ba326c9301782508bdf07b7c4e23ecb391
4
- data.tar.gz: f7246af497c04e9c509457444ac9c17c8617aa881fca82adb4561473f1d18044
3
+ metadata.gz: 528b824876642a7d3cabb52d76ba8a93f55273443f0a4a25a308f14d80460bc4
4
+ data.tar.gz: db5ba4f41d4f863074bd7d5e291b9b753995fb056612f763945ea4ad10ed2c7d
5
5
  SHA512:
6
- metadata.gz: b47263b248b7952d58d9fe8fb03f0614f8c917e025310839f7ab311f33fc31e292fe257ffec8f1c487843eab7814253829c00579ea2132385b4064b75e801890
7
- data.tar.gz: 6be5e5bab5900605d78977e703d27ac95dac303fa3855d52bd4f7dd4a1e8c8f090d49b95c57a5abe3155dde9adece9a028cfa7afc3872b9fcead2ce1a417676d
6
+ metadata.gz: 820828cc1d4f45fbc23df7e1296f71e24959fe811e5b380470cbc8126484ffe9bef70351eb4534777e7398f1bcd30363e30172ebe33b1828871318603fe5a906
7
+ data.tar.gz: 52a96a0c75fc7cc57b8e6938784f75079f3b5caf3d4b5a49801604b8061aec73518a23576a7ab6346937f8d4899c70b0b6efa33faf9ae1d35c75cbded956101a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.2
4
+
5
+ - Fix bug in content data-binding that was caused by recent performance optimizations (+ fix Hello, Content Data-Binding! sample)
6
+ - Fix bug in rendering formatting elements that was caused by recent performance optimizations (+ fix Hello, Paragraph! sample)
7
+
8
+ ## 0.2.1
9
+
10
+ - Optimize performance (~800% faster):
11
+ - Optimize performance (~20% faster than 0.2.0) by not using glimmer-dsl-xml for rendering dom elements in the frontend as it is more suitable for backend rendering and we already have a separate dsl for the frontend
12
+ - Optimize performance (~287% faster than previous bullet point) by adding Glimmer shortcut methods for all HTML element DSL keywords
13
+ - Optimize performance (~235% faster than previous bullet point) by not selecting ElementProxy subclass dynamically for each element, yet always using ElementProxy
14
+
15
+ ## 0.2.0
16
+
17
+ - Support `style` element content as Glimmer DSL for CSS syntax (Ruby Programmable CSS) as an alternative to a CSS `String`
18
+
3
19
  ## 0.1.1
4
20
 
5
21
  - Upgrade to opal-jquery 0.5.1 (adds `# backtick_javascript: true` where needed to satisfy new Opal requirement)
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.1.1 (Beta)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Web 0.2.2 (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)
@@ -131,6 +131,7 @@ Document.ready? do
131
131
 
132
132
  # CSS Styles
133
133
  style {
134
+ # CSS can be included as a String as done below, or as Glimmer DSL for CSS syntax (Ruby code) as done in other samples
134
135
  <<~CSS
135
136
  input {
136
137
  margin: 5px;
@@ -392,15 +393,15 @@ Document.ready? do
392
393
  }
393
394
  }
394
395
 
396
+ # Programmable CSS using Glimmer DSL for CSS
395
397
  style {
396
- <<~CSS
397
- #{address_div.selector} * {
398
- margin: 5px;
399
- }
400
- #{address_div.selector} input, #{address_div.selector} select {
401
- grid-column: 2;
402
- }
403
- CSS
398
+ # `r` is an alias for `rule`, generating a CSS rule
399
+ r("#{address_div.selector} *") {
400
+ margin '5px'
401
+ }
402
+ r("#{address_div.selector} input, #{address_div.selector} select") {
403
+ grid_column '2'
404
+ }
404
405
  }
405
406
  }
406
407
 
@@ -528,20 +529,18 @@ Document.ready? do
528
529
  }
529
530
 
530
531
  style {
531
- <<~CSS
532
- #{address_div.selector} {
533
- margin: 10px 0;
534
- }
535
- #{address_div.selector} * {
536
- margin: 5px;
537
- }
538
- #{address_div.selector} label {
539
- grid-column: 1;
540
- }
541
- #{address_div.selector} input, #{address_div.selector} select {
542
- grid-column: 2;
543
- }
544
- CSS
532
+ r(address_div.selector) {
533
+ margin '10px 0'
534
+ }
535
+ r("#{address_div.selector} *") {
536
+ margin '5px'
537
+ }
538
+ r("#{address_div.selector} label") {
539
+ grid_column '1'
540
+ }
541
+ r("#{address_div.selector} input, #{address_div.selector} select") {
542
+ grid_column '2'
543
+ }
545
544
  }
546
545
  }
547
546
  }
@@ -708,14 +707,12 @@ class AddressForm
708
707
  }
709
708
 
710
709
  style {
711
- <<~CSS
712
- #{address_div.selector} * {
713
- margin: 5px;
714
- }
715
- #{address_div.selector} input, #{address_div.selector} select {
716
- grid-column: 2;
717
- }
718
- CSS
710
+ r("#{address_div.selector} *") {
711
+ margin '5px'
712
+ }
713
+ r("#{address_div.selector} input, #{address_div.selector} select") {
714
+ grid_column '2'
715
+ }
719
716
  }
720
717
  }
721
718
 
@@ -957,14 +954,12 @@ class AddressForm
957
954
  }
958
955
 
959
956
  style {
960
- <<~CSS
961
- #{address_div.selector} * {
962
- margin: 5px;
963
- }
964
- #{address_div.selector} input, #{address_div.selector} select {
965
- grid-column: 2;
966
- }
967
- CSS
957
+ r("#{address_div.selector} *") {
958
+ margin '5px'
959
+ }
960
+ r("#{address_div.selector} input, #{address_div.selector} select") {
961
+ grid_column '2'
962
+ }
968
963
  }
969
964
  }
970
965
 
@@ -1146,7 +1141,7 @@ rails new glimmer_app_server
1146
1141
  Add the following to `Gemfile`:
1147
1142
 
1148
1143
  ```
1149
- gem 'glimmer-dsl-web', '~> 0.1.1'
1144
+ gem 'glimmer-dsl-web', '~> 0.2.2'
1150
1145
  ```
1151
1146
 
1152
1147
  Run:
@@ -1367,7 +1362,7 @@ Disable the `webpacker` gem line in `Gemfile`:
1367
1362
  Add the following to `Gemfile`:
1368
1363
 
1369
1364
  ```ruby
1370
- gem 'glimmer-dsl-web', '~> 0.1.1'
1365
+ gem 'glimmer-dsl-web', '~> 0.2.2'
1371
1366
  ```
1372
1367
 
1373
1368
  Run:
@@ -1764,6 +1759,7 @@ Document.ready? do
1764
1759
 
1765
1760
  # CSS Styles
1766
1761
  style {
1762
+ # CSS can be included as a String as done below, or as Glimmer DSL for CSS syntax (Ruby code) as done in other samples
1767
1763
  <<~CSS
1768
1764
  input {
1769
1765
  margin: 5px;
@@ -2082,14 +2078,12 @@ Document.ready? do
2082
2078
  }
2083
2079
 
2084
2080
  style {
2085
- <<~CSS
2086
- #{address_div.selector} * {
2087
- margin: 5px;
2088
- }
2089
- #{address_div.selector} input, #{address_div.selector} select {
2090
- grid-column: 2;
2091
- }
2092
- CSS
2081
+ r("#{address_div.selector} *") {
2082
+ margin '5px'
2083
+ }
2084
+ r("#{address_div.selector} input, #{address_div.selector} select") {
2085
+ grid_column '2'
2086
+ }
2093
2087
  }
2094
2088
  }
2095
2089
 
@@ -2217,20 +2211,18 @@ Document.ready? do
2217
2211
  }
2218
2212
 
2219
2213
  style {
2220
- <<~CSS
2221
- #{address_div.selector} {
2222
- margin: 10px 0;
2223
- }
2224
- #{address_div.selector} * {
2225
- margin: 5px;
2226
- }
2227
- #{address_div.selector} label {
2228
- grid-column: 1;
2229
- }
2230
- #{address_div.selector} input, #{address_div.selector} select {
2231
- grid-column: 2;
2232
- }
2233
- CSS
2214
+ r(address_div.selector) {
2215
+ margin '10px 0'
2216
+ }
2217
+ r("#{address_div.selector} *") {
2218
+ margin '5px'
2219
+ }
2220
+ r("#{address_div.selector} label") {
2221
+ grid_column '1'
2222
+ }
2223
+ r("#{address_div.selector} input, #{address_div.selector} select") {
2224
+ grid_column '2'
2225
+ }
2234
2226
  }
2235
2227
  }
2236
2228
  }
@@ -2397,14 +2389,12 @@ class AddressForm
2397
2389
  }
2398
2390
 
2399
2391
  style {
2400
- <<~CSS
2401
- #{address_div.selector} * {
2402
- margin: 5px;
2403
- }
2404
- #{address_div.selector} input, #{address_div.selector} select {
2405
- grid-column: 2;
2406
- }
2407
- CSS
2392
+ r("#{address_div.selector} *") {
2393
+ margin '5px'
2394
+ }
2395
+ r("#{address_div.selector} input, #{address_div.selector} select") {
2396
+ grid_column '2'
2397
+ }
2408
2398
  }
2409
2399
  }
2410
2400
 
@@ -2646,14 +2636,12 @@ class AddressForm
2646
2636
  }
2647
2637
 
2648
2638
  style {
2649
- <<~CSS
2650
- #{address_div.selector} * {
2651
- margin: 5px;
2652
- }
2653
- #{address_div.selector} input, #{address_div.selector} select {
2654
- grid-column: 2;
2655
- }
2656
- CSS
2639
+ r("#{address_div.selector} *") {
2640
+ margin '5px'
2641
+ }
2642
+ r("#{address_div.selector} input, #{address_div.selector} select") {
2643
+ grid_column '2'
2644
+ }
2657
2645
  }
2658
2646
  }
2659
2647
 
@@ -2850,17 +2838,15 @@ Document.ready? do
2850
2838
  }
2851
2839
 
2852
2840
  style {
2853
- <<~CSS
2854
- #{container_div.selector} * {
2855
- margin: 5px;
2856
- }
2857
- #{container_div.selector} label {
2858
- grid-column: 1;
2859
- }
2860
- #{container_div.selector} input {
2861
- grid-column: 2;
2862
- }
2863
- CSS
2841
+ r("#{container_div.selector} *") {
2842
+ margin '5px'
2843
+ }
2844
+ r("#{container_div.selector} label") {
2845
+ grid_column '1'
2846
+ }
2847
+ r("#{container_div.selector} input") {
2848
+ grid_column '2'
2849
+ }
2864
2850
  }
2865
2851
  }
2866
2852
  }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.2
@@ -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.1.1 ruby lib
5
+ # stub: glimmer-dsl-web 0.2.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.1.1".freeze
9
+ s.version = "0.2.2".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-08"
14
+ s.date = "2024-01-09"
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 = [
@@ -58,6 +58,7 @@ Gem::Specification.new do |s|
58
58
  "lib/glimmer/dsl/web/property_expression.rb",
59
59
  "lib/glimmer/dsl/web/select_expression.rb",
60
60
  "lib/glimmer/dsl/web/shine_data_binding_expression.rb",
61
+ "lib/glimmer/dsl/web/style_expression.rb",
61
62
  "lib/glimmer/helpers/glimmer_helper.rb",
62
63
  "lib/glimmer/util/proc_tracker.rb",
63
64
  "lib/glimmer/web.rb",
@@ -76,7 +77,7 @@ Gem::Specification.new do |s|
76
77
 
77
78
  s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 2.7.6".freeze])
78
79
  s.add_runtime_dependency(%q<glimmer-dsl-xml>.freeze, ["~> 1.3.2".freeze])
79
- s.add_runtime_dependency(%q<glimmer-dsl-css>.freeze, ["~> 1.2.2".freeze])
80
+ s.add_runtime_dependency(%q<glimmer-dsl-css>.freeze, ["~> 1.2.3".freeze])
80
81
  s.add_runtime_dependency(%q<opal>.freeze, ["= 1.8.2".freeze])
81
82
  s.add_runtime_dependency(%q<opal-rails>.freeze, ["= 2.0.3".freeze])
82
83
  s.add_runtime_dependency(%q<opal-async>.freeze, ["~> 1.4.1".freeze])
@@ -24,8 +24,9 @@ require 'glimmer/dsl/web/element_expression'
24
24
  require 'glimmer/dsl/web/formatting_element_expression'
25
25
  require 'glimmer/dsl/web/listener_expression'
26
26
  require 'glimmer/dsl/web/property_expression'
27
- require 'glimmer/dsl/web/p_expression'
28
- require 'glimmer/dsl/web/select_expression'
27
+ # require 'glimmer/dsl/web/p_expression'
28
+ # require 'glimmer/dsl/web/select_expression'
29
+ require 'glimmer/dsl/web/style_expression'
29
30
  require 'glimmer/dsl/web/bind_expression'
30
31
  require 'glimmer/dsl/web/data_binding_expression'
31
32
  require 'glimmer/dsl/web/content_data_binding_expression'
@@ -16,3 +16,14 @@ module Glimmer
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ module Glimmer
21
+ # Optimize performance through shortcut methods for all HTML elements that circumvent the DSL chain of responsibility
22
+ element_expression = Glimmer::DSL::Web::ElementExpression.new
23
+ (Glimmer::Web::ElementProxy::ELEMENT_KEYWORDS - ['style']).each do |keyword|
24
+ Glimmer::DSL::Engine.static_expressions[keyword] ||= Concurrent::Hash.new
25
+ element_expression_dsl = element_expression.class.dsl
26
+ Glimmer::DSL::Engine.static_expressions[keyword][element_expression_dsl] = element_expression
27
+ Glimmer.send(:define_method, keyword, &Glimmer::DSL::Engine::STATIC_EXPRESSION_METHOD_FACTORY.call(keyword))
28
+ end
29
+ end
@@ -8,7 +8,7 @@ module Glimmer
8
8
  include ParentExpression
9
9
 
10
10
  def interpret(parent, keyword, *args, &block)
11
- Glimmer::Web::ElementProxy.for(keyword, parent, args, block)
11
+ Glimmer::Web::ElementProxy.new(keyword, parent, args, block)
12
12
  end
13
13
 
14
14
  def add_content(parent, keyword, *args, &block)
@@ -0,0 +1,27 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/web/general_element_expression'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module Web
7
+ class StyleExpression < StaticExpression
8
+ include GeneralElementExpression
9
+ include Glimmer
10
+
11
+ def add_content(parent, keyword, *args, &block)
12
+ if parent.rendered? || parent.skip_content_on_render_blocks?
13
+ return_value = css(&block).to_s
14
+ return_value = super(parent, keyword, *args, &block) if return_value.to_s.empty?
15
+ if return_value.is_a?(String) && parent.dom_element.text.to_s.empty?
16
+ parent.add_text_content(return_value)
17
+ end
18
+ parent.post_add_content
19
+ return_value
20
+ else
21
+ parent.add_content_on_render(&block)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -31,11 +31,14 @@ module Glimmer
31
31
  ELEMENT_KEYWORDS.include?(keyword.to_s)
32
32
  end
33
33
 
34
+ # NOTE: Avoid using this method until we start supporting ElementProxy subclasses
35
+ # in which case, we must cache them to avoid the slow performance of element_type
34
36
  # Factory Method that translates a Glimmer DSL keyword into a ElementProxy object
35
37
  def for(keyword, parent, args, block)
36
38
  element_type(keyword).new(keyword, parent, args, block)
37
39
  end
38
40
 
41
+ # NOTE: Avoid using this method for now as it has slow performance
39
42
  # returns Ruby proxy class (type) that would handle this keyword
40
43
  def element_type(keyword)
41
44
  class_name_main = "#{keyword.camelcase(:upper)}Proxy"
@@ -67,6 +70,19 @@ module Glimmer
67
70
  def widget_handling_listener
68
71
  @@widget_handling_listener
69
72
  end
73
+
74
+ def render_html(element, attributes, content = nil)
75
+ attributes = attributes.reduce('') do |output, option_pair|
76
+ attribute, value = option_pair
77
+ value = value.to_s.sub('"', '&quot;').sub("'", '&apos;')
78
+ output += " #{attribute}=\"#{value}\""
79
+ end
80
+ if content.nil?
81
+ "<#{element}#{attributes} />"
82
+ else
83
+ "<#{element}#{attributes}>#{content}</#{element}>"
84
+ end
85
+ end
70
86
  end
71
87
 
72
88
  include Glimmer
@@ -74,18 +90,18 @@ module Glimmer
74
90
  Event = Struct.new(:widget, keyword_init: true)
75
91
 
76
92
  ELEMENT_KEYWORDS = [
77
- "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b",
78
- "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br",
79
- "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data",
80
- "datalist", "dd", "decorator", "del", "details", "dfn", "dir", "div", "dl", "dt",
81
- "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame",
93
+ "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio",
94
+ "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body",
95
+ "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "data",
96
+ "datalist", "dd", "decorator", "details", "dfn", "dir", "div", "dl", "dt",
97
+ "element", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame",
82
98
  "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup",
83
- "hr", "html", "i", "iframe", "img", "input", "ins", "isindex", "kbd", "keygen",
84
- "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "menu",
99
+ "hr", "html", "iframe", "img", "input", "isindex", "kbd", "keygen",
100
+ "label", "legend", "li", "link", "listing", "main", "map", "marquee", "menu",
85
101
  "menuitem", "meta", "meter", "nav", "nobr", "noframes", "noscript", "object", "ol", "optgroup",
86
102
  "option", "output", "p", "param", "plaintext", "pre", "progress", "q", "rp", "rt",
87
- "ruby", "s", "samp", "script", "section", "select", "shadow", "small", "source", "spacer",
88
- "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td",
103
+ "ruby", "s", "samp", "script", "section", "select", "shadow", "source", "spacer",
104
+ "span", "strike", "style", "summary", "table", "tbody", "td",
89
105
  "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt",
90
106
  "u", "ul", "var", "video", "wbr", "xmp",
91
107
  ]
@@ -249,8 +265,7 @@ module Glimmer
249
265
  @parent = nil
250
266
  end
251
267
  the_parent_dom_element = custom_parent_dom_element || parent_dom_element
252
- old_element = dom_element
253
- brand_new = @dom.nil? || old_element.empty? || !options[:parent].to_s.empty? || brand_new
268
+ brand_new ||= @dom.nil? || !options[:parent].to_s.empty? || (old_element = dom_element).empty?
254
269
  build_dom(layout: !custom_parent_dom_element) # TODO handle custom parent layout by passing parent instead of parent dom element
255
270
  if brand_new
256
271
  attach(the_parent_dom_element)
@@ -310,19 +325,16 @@ module Glimmer
310
325
 
311
326
  def build_dom(layout: true)
312
327
  # TODO consider passing parent element instead and having table item include a table cell widget only for opal
313
- @dom = nil
314
328
  @dom = dom # TODO unify how to build dom for most widgets based on element, id, and name (class)
315
- @dom
316
329
  end
317
330
 
318
331
  def dom
319
332
  # TODO auto-convert known glimmer attributes like parent to data attributes like data-parent
320
333
  # TODO check if we need to avoid rendering content block if no content is available
321
- @dom ||= html {
322
- send(keyword, html_options) {
323
- args.first if args.first.is_a?(String)
324
- }
325
- }.to_s
334
+ @dom ||= begin
335
+ content = args.first if args.first.is_a?(String)
336
+ ElementProxy.render_html(keyword, html_options, content)
337
+ end
326
338
  end
327
339
 
328
340
  def html_options
@@ -21,6 +21,8 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
+ require 'glimmer/web/element_proxy'
25
+
24
26
  module Glimmer
25
27
  module Web
26
28
  class FormattingElementProxy
@@ -43,10 +45,7 @@ module Glimmer
43
45
  content = args.first.to_s
44
46
  end
45
47
  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
48
+ ElementProxy.render_html(keyword, attribute_hash, content)
50
49
  end
51
50
  end
52
51
 
@@ -158,14 +158,12 @@ class AddressForm
158
158
  }
159
159
 
160
160
  style {
161
- <<~CSS
162
- #{address_div.selector} * {
163
- margin: 5px;
164
- }
165
- #{address_div.selector} input, #{address_div.selector} select {
166
- grid-column: 2;
167
- }
168
- CSS
161
+ r("#{address_div.selector} *") {
162
+ margin '5px'
163
+ }
164
+ r("#{address_div.selector} input, #{address_div.selector} select") {
165
+ grid_column '2'
166
+ }
169
167
  }
170
168
  }
171
169
 
@@ -117,20 +117,18 @@ Document.ready? do
117
117
  }
118
118
 
119
119
  style {
120
- <<~CSS
121
- #{address_div.selector} {
122
- margin: 10px 0;
123
- }
124
- #{address_div.selector} * {
125
- margin: 5px;
126
- }
127
- #{address_div.selector} label {
128
- grid-column: 1;
129
- }
130
- #{address_div.selector} input, #{address_div.selector} select {
131
- grid-column: 2;
132
- }
133
- CSS
120
+ r(address_div.selector) {
121
+ margin '10px 0'
122
+ }
123
+ r("#{address_div.selector} *") {
124
+ margin '5px'
125
+ }
126
+ r("#{address_div.selector} label") {
127
+ grid_column '1'
128
+ }
129
+ r("#{address_div.selector} input, #{address_div.selector} select") {
130
+ grid_column '2'
131
+ }
134
132
  }
135
133
  }
136
134
  }
@@ -156,15 +156,15 @@ Document.ready? do
156
156
  }
157
157
  }
158
158
 
159
+ # Programmable CSS using Glimmer DSL for CSS
159
160
  style {
160
- <<~CSS
161
- #{address_div.selector} * {
162
- margin: 5px;
163
- }
164
- #{address_div.selector} input, #{address_div.selector} select {
165
- grid-column: 2;
166
- }
167
- CSS
161
+ # `r` is an alias for `rule`, generating a CSS rule
162
+ r("#{address_div.selector} *") {
163
+ margin '5px'
164
+ }
165
+ r("#{address_div.selector} input, #{address_div.selector} select") {
166
+ grid_column '2'
167
+ }
168
168
  }
169
169
  }
170
170
 
@@ -79,6 +79,7 @@ Document.ready? do
79
79
 
80
80
  # CSS Styles
81
81
  style {
82
+ # CSS can be included as a String as done below, or as Glimmer DSL for CSS syntax (Ruby code) as done in other samples
82
83
  <<~CSS
83
84
  input {
84
85
  margin: 5px;
@@ -135,14 +135,12 @@ class AddressForm
135
135
  }
136
136
 
137
137
  style {
138
- <<~CSS
139
- #{address_div.selector} * {
140
- margin: 5px;
141
- }
142
- #{address_div.selector} input, #{address_div.selector} select {
143
- grid-column: 2;
144
- }
145
- CSS
138
+ r("#{address_div.selector} *") {
139
+ margin '5px'
140
+ }
141
+ r("#{address_div.selector} input, #{address_div.selector} select") {
142
+ grid_column '2'
143
+ }
146
144
  }
147
145
  }
148
146
 
@@ -100,17 +100,15 @@ Document.ready? do
100
100
  }
101
101
 
102
102
  style {
103
- <<~CSS
104
- #{container_div.selector} * {
105
- margin: 5px;
106
- }
107
- #{container_div.selector} label {
108
- grid-column: 1;
109
- }
110
- #{container_div.selector} input {
111
- grid-column: 2;
112
- }
113
- CSS
103
+ r("#{container_div.selector} *") {
104
+ margin '5px'
105
+ }
106
+ r("#{container_div.selector} label") {
107
+ grid_column '1'
108
+ }
109
+ r("#{container_div.selector} input") {
110
+ grid_column '2'
111
+ }
114
112
  }
115
113
  }
116
114
  }
@@ -77,7 +77,6 @@ else
77
77
 
78
78
  require 'glimmer/dsl/web/dsl'
79
79
  require 'glimmer/config/opal_logger'
80
- require 'glimmer-dsl-xml'
81
80
  require 'glimmer-dsl-css'
82
81
 
83
82
  Glimmer::Config.loop_max_count = 50 # TODO consider disabling if preferred
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.1.1
4
+ version: 0.2.2
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-08 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.2.2
47
+ version: 1.2.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.2.2
54
+ version: 1.2.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: opal
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -287,6 +287,7 @@ files:
287
287
  - lib/glimmer/dsl/web/property_expression.rb
288
288
  - lib/glimmer/dsl/web/select_expression.rb
289
289
  - lib/glimmer/dsl/web/shine_data_binding_expression.rb
290
+ - lib/glimmer/dsl/web/style_expression.rb
290
291
  - lib/glimmer/helpers/glimmer_helper.rb
291
292
  - lib/glimmer/util/proc_tracker.rb
292
293
  - lib/glimmer/web.rb