glimmer-dsl-web 0.10.4 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64fc435ce1a727a890882f43c0851f932f699a610fbfea88041e0606f1fac8b7
4
- data.tar.gz: da253a9bccb769f519c20f53810410360cd45034722fbe5083f2847c8e5f3080
3
+ metadata.gz: bb3e190dffb57fefc4c23410228b80e5de34131933904fab857e5d29707449de
4
+ data.tar.gz: 179affcfe00cb768f8d73058f91ff2a14091b9a26632122825bb1a4ad40ea660
5
5
  SHA512:
6
- metadata.gz: f67ac1fc2adadfd190106296d70fec7aa267368a7d33660836dde5198f9e4ad05942674707758ae10293c9c2213ad7031fd0f9ab9fc8a0ca75dd7cb8f1a75fa4
7
- data.tar.gz: aa2115656cc49ec3eafe7f2717051dd6fda8bec038906fcbc574d25265a094231b7409ecd2c49ada131515365729f2bf6fc0331bc5cbe68e07b69cb35967307c
6
+ metadata.gz: aeeab5675891c33b5024c3f815827efa4e06c605d116e673cb97631940a5a2e55d3cd014d07744c4e8c82510f8c593a9fbcd7e56871348cfb646d27f3136164f
7
+ data.tar.gz: fedc6227c24dfa601a51bee7de2b2f3f40ce022ec85894f6fdc732bb433aa0c1d3621def13671173d411f9b141121add014c60b5691f42f2e0a1a253aac5dd06
data/CHANGELOG.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.10.5
4
+
5
+ - Support `parent.before {}` & `parent.after {}` on `ElementProxy` and `Glimmer::Web::Component`, to insert elements before or after the parent element.
6
+ - Fixed issue with how `insert_at` was mistakenly adding a newly inserted element to the parent's parent's children
7
+ - Update Hello, Mutation! sample with "Insert before" and "Insert after" functionality
8
+ - Update Hello, Mutation Content Data-Binding! sample with "Insert before" and "Insert after" functionality
9
+
3
10
  ## 0.10.4
4
11
 
5
- - Support `parent.insert_at(index) {}` on `ElementProxy` and `Glimmer::Web::Component`, which is a method that inserts elements to the content of a parent element at a specified index
12
+ - Support `parent.insert_at(index) {}` on `ElementProxy` and `Glimmer::Web::Component`, which is a method that inserts elements to the content of a parent element at a specified index.
6
13
  - Support `parent.insert(index) {}` alias for `parent.insert_at(index) {}`
7
14
  - Update Hello, Mutation! sample with "Insert list item" functionality
8
15
  - Update Hello, Mutation Content Data-Binding! sample with "Insert list item" functionality
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.10.4 (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.10.5 (Beta)
2
2
  ## Ruby-in-the-Browser Web Frontend Framework
3
3
  ### The "Rails" of Frontend Frameworks!!! ([Fukuoka Award Winning](https://andymaleh.blogspot.com/2025/01/glimmer-dsl-for-web-wins-in-fukuoka.html))
4
4
  #### Finally, Ruby Developer Productivity, Happiness, and Fun in the Frontend!!!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.4
1
+ 0.10.5
@@ -2,11 +2,11 @@
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.10.4 ruby lib
5
+ # stub: glimmer-dsl-web 0.10.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-web".freeze
9
- s.version = "0.10.4".freeze
9
+ s.version = "0.10.5".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]
@@ -521,6 +521,14 @@ module Glimmer
521
521
  end
522
522
  alias insert insert_at
523
523
 
524
+ def before(bulk_render: false, &block)
525
+ @markup_root.before(bulk_render:, &block)
526
+ end
527
+
528
+ def after(bulk_render: false, &block)
529
+ @markup_root.after(bulk_render:, &block)
530
+ end
531
+
524
532
  def remove_all_listeners
525
533
  data_bindings.each do |option_binding, model_binding|
526
534
  option_binding.unregister_all_observables
@@ -224,11 +224,11 @@ module Glimmer
224
224
 
225
225
  # Executes for the parent of a child that just got added
226
226
  def post_initialize_child(child)
227
- case parent&.add_child_mutation
227
+ case self.add_child_mutation # TODO this is where the problem is.. It's an append instead of an insert_at
228
228
  when :prepend
229
229
  @children.prepend(child)
230
230
  when :insert_at
231
- @children.insert(parent&.insert_index, child)
231
+ @children.insert(self.insert_index, child)
232
232
  else # append
233
233
  @children << child
234
234
  end
@@ -602,6 +602,18 @@ module Glimmer
602
602
  end
603
603
  alias insert insert_at
604
604
 
605
+ def before(bulk_render: false, &block)
606
+ return if parent.nil?
607
+ parent_insert_index = parent.children.index(self)
608
+ parent.content(bulk_render:, add_child_mutation: :insert_at, insert_index: parent_insert_index, &block)
609
+ end
610
+
611
+ def after(bulk_render: false, &block)
612
+ return if parent.nil?
613
+ parent_insert_index = parent.children.index(self) + 1
614
+ parent.content(bulk_render:, add_child_mutation: :insert_at, insert_index: parent_insert_index, &block)
615
+ end
616
+
605
617
  # Subclasses must override with their own mappings
606
618
  def observation_request_to_event_mapping
607
619
  {}
@@ -4,8 +4,12 @@ unless Object.const_defined?(:HelloMutation) # this is only needed in sample sel
4
4
  class HelloMutation
5
5
  include Glimmer::Web::Component
6
6
 
7
+ before_render do
8
+ @action_buttons = []
9
+ end
10
+
7
11
  after_render do
8
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = true
12
+ toggle_action_buttons_disabled(true)
9
13
  end
10
14
 
11
15
  markup {
@@ -20,44 +24,38 @@ unless Object.const_defined?(:HelloMutation) # this is only needed in sample sel
20
24
  @input = input(placeholder: 'Enter list item content') {
21
25
  oninput do
22
26
  if @input.value.to_s.strip == ''
23
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = true
27
+ toggle_action_buttons_disabled(true)
24
28
  else
25
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = false
29
+ toggle_action_buttons_disabled(false)
26
30
  end
27
31
  end
28
32
  }
29
33
 
30
- @append_button = button('Append list item') {
34
+ @action_buttons << button('Append list item') {
31
35
  onclick do
32
36
  @list.append {
33
- li { @input.value }
37
+ new_li
34
38
  }
35
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = true
36
- @input.value = ''
37
- @input.focus
39
+ reset_input_and_button_enablement
38
40
  end
39
41
  }
40
42
 
41
- @prepend_button = button('Prepend list item') {
43
+ @action_buttons << button('Prepend list item') {
42
44
  onclick do
43
45
  @list.prepend {
44
- li { @input.value }
46
+ new_li
45
47
  }
46
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = true
47
- @input.value = ''
48
- @input.focus
48
+ reset_input_and_button_enablement
49
49
  end
50
50
  }
51
51
 
52
- @insert_button = button('Insert list item') {
52
+ @action_buttons << button('Insert list item') {
53
53
  onclick do
54
54
  index = [@insert_index_input.value.to_i, @list.children.size].min
55
55
  @list.insert_at(index) {
56
- li { @input.value }
56
+ new_li
57
57
  }
58
- @append_button.disabled = @prepend_button.disabled = @insert_button.disabled = true
59
- @input.value = ''
60
- @input.focus
58
+ reset_input_and_button_enablement
61
59
  end
62
60
  }
63
61
 
@@ -86,8 +84,55 @@ unless Object.const_defined?(:HelloMutation) # this is only needed in sample sel
86
84
  r('.actions label[for=insert-index-input]') {
87
85
  margin_left -5
88
86
  }
87
+
88
+ r('ul li') {
89
+ height 22.5
90
+ }
91
+
92
+ r('ul li button') {
93
+ display :none
94
+ margin_left 5
95
+ }
96
+
97
+ r('ul li:hover button') {
98
+ display :initial
99
+ }
89
100
  }
90
101
  end
102
+
103
+ private
104
+
105
+ def new_li
106
+ li { |current_li|
107
+ span { @input.value }
108
+ @action_buttons << button('Insert before') {
109
+ onclick do
110
+ current_li.before {
111
+ new_li
112
+ }
113
+ reset_input_and_button_enablement
114
+ end
115
+ }
116
+ @action_buttons << button('Insert after') {
117
+ onclick do
118
+ current_li.after {
119
+ new_li
120
+ }
121
+ reset_input_and_button_enablement
122
+ end
123
+ }
124
+ }
125
+ end
126
+
127
+ def reset_input_and_button_enablement
128
+ toggle_action_buttons_disabled(true)
129
+ @input.value = ''
130
+ @input.focus
131
+ end
132
+
133
+ def toggle_action_buttons_disabled(disabled)
134
+ @action_buttons.each { |action_button| action_button.disabled = disabled }
135
+ end
91
136
  end
92
137
 
93
138
  Document.ready? do
@@ -96,8 +96,26 @@ unless Object.const_defined?(:HelloMutationContentDataBinding) # this is only ne
96
96
 
97
97
  ul {
98
98
  content(@list_presenter, :list) {
99
- @list_presenter.list.each do |list_item|
100
- li { list_item }
99
+ @list_presenter.list.each_with_index do |list_item, index|
100
+ li { |current_li|
101
+ span { list_item }
102
+ button('Insert before') {
103
+ disabled <= [@list_presenter, :edit_list_disabled?, computed_by: :new_list_item]
104
+
105
+ onclick do
106
+ @list_presenter.insert_index = index
107
+ @list_presenter.insert_list_item
108
+ end
109
+ }
110
+ button('Insert after') {
111
+ disabled <= [@list_presenter, :edit_list_disabled?, computed_by: :new_list_item]
112
+
113
+ onclick do
114
+ @list_presenter.insert_index = index + 1
115
+ @list_presenter.insert_list_item
116
+ end
117
+ }
118
+ }
101
119
  end
102
120
  }
103
121
  }
@@ -116,6 +134,19 @@ unless Object.const_defined?(:HelloMutationContentDataBinding) # this is only ne
116
134
  r('.actions label[for=insert-index-input]') {
117
135
  margin_left -5
118
136
  }
137
+
138
+ r('ul li') {
139
+ height 22.5
140
+ }
141
+
142
+ r('ul li button') {
143
+ display :none
144
+ margin_left 5
145
+ }
146
+
147
+ r('ul li:hover button') {
148
+ display :initial
149
+ }
119
150
  }
120
151
  end
121
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh