quince 0.4.2 → 0.5.0

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: 896b010bef61ab4914a5cf09ad07c94d2840063788c6637422dfe6544c9bda3c
4
- data.tar.gz: e3c39708bc888257d56ae5463619dca5bc65ace9070537af7a488e5457ffd9a4
3
+ metadata.gz: 8a30e10c958d56fc7a73d2515d200cae1080d407e2a19e132827b2b77837b6bb
4
+ data.tar.gz: 2f43465799409bb6a7336879189d35bfcfcd259b8637a1eec546826317034436
5
5
  SHA512:
6
- metadata.gz: 7693d8919c8bc2f7af200afade98c9300131bf054a9a2614c9c3c80fa0eb90d2c153a092246bb7cf5b23661da2f57fde9038a712970ddecea45938eca4e4bcd5
7
- data.tar.gz: da44b43b26aeeab5fe75579877e6e233e4425bf1befc12685ccdcc39aac445c617e16d2f28d571d1623afd1adc960db52a10918f39fc1922587e38c2aa736147
6
+ metadata.gz: 86e5e960621d4e6ecde1ce2cf07486596b00e64aeb8ddecf0c82d7c2ac9c3818ee2f367256e1a1539af86a1eee534af572cd45c94d2ed8676d5bd4d9867543f9
7
+ data.tar.gz: 0360b4ed00cba7ec1604c1bd42d79a8fce65b065b409a0dcb4539816980de92a33bf1c181d8f09f7542699edac24508684d01e2ad05cd08630b5c14c5e06f433
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quince (0.4.2)
4
+ quince (0.5.0)
5
5
  oj (~> 3.13)
6
6
  typed_struct (>= 0.1.4)
7
7
 
@@ -9,7 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  diff-lcs (1.4.4)
12
- oj (3.13.7)
12
+ oj (3.13.9)
13
13
  rake (13.0.6)
14
14
  rbs (1.6.2)
15
15
  rspec (3.10.0)
@@ -4,14 +4,14 @@ require_relative "types"
4
4
 
5
5
  module Quince
6
6
  module HtmlTagComponents
7
- referrer_policy = Rbs("'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url' | Quince::Types::Undefined")
7
+ referrer_policy = Rbs("'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url' | nil")
8
8
  form_method = Rbs(
9
- '"get" | "post" | "GET" | "POST" | :GET | :POST | :get | :post | Quince::Types::Undefined'
9
+ '"get" | "post" | "GET" | "POST" | :GET | :POST | :get | :post | nil'
10
10
  )
11
11
  t = Quince::Types
12
12
  opt_string_sym = Rbs("#{t::OptionalString} | Symbol")
13
13
  opt_bool = t::OptionalBoolean
14
- opt_callback = Rbs("Quince::Callback::Interface | Quince::Types::Undefined")
14
+ opt_callback = Rbs("Quince::Callback::Interface | nil")
15
15
  value = opt_string_sym # for now
16
16
 
17
17
  ATTRIBUTES_BY_ELEMENT = {
@@ -58,7 +58,7 @@ module Quince
58
58
  formnovalidate: opt_bool,
59
59
  formtarget: opt_string_sym,
60
60
  name: opt_string_sym,
61
- type: Rbs("'submit' | 'reset' | 'button' | Quince::Types::Undefined"),
61
+ type: Rbs("'submit' | 'reset' | 'button' | nil"),
62
62
  value: value,
63
63
  }.freeze,
64
64
  "Canvas" => {
@@ -128,7 +128,7 @@ module Quince
128
128
  allowfullscreen: opt_bool,
129
129
  allowtransparency: opt_bool,
130
130
  height: opt_string_sym,
131
- loading: Rbs('"eager" | "lazy" | Quince::Types::Undefined'),
131
+ loading: Rbs('"eager" | "lazy" | nil'),
132
132
  name: opt_string_sym,
133
133
  referrerpolicy: referrer_policy,
134
134
  sandbox: opt_string_sym,
@@ -192,7 +192,7 @@ module Quince
192
192
  "Ol" => {
193
193
  reversed: opt_bool,
194
194
  start: opt_string_sym,
195
- type: Rbs("'1' | 'a' | 'A' | 'i' | 'I' | Quince::Types::Undefined"),
195
+ type: Rbs("'1' | 'a' | 'A' | 'i' | 'I' | nil"),
196
196
  }.freeze,
197
197
  "Optgroup" => {
198
198
  disabled: opt_bool,
@@ -270,7 +270,7 @@ module Quince
270
270
  }.freeze,
271
271
  "Tbody" => {}.freeze,
272
272
  "Td" => {
273
- align: Rbs('"left" | "center" | "right" | "justify" | "char" | Quince::Types::Undefined'),
273
+ align: Rbs('"left" | "center" | "right" | "justify" | "char" | nil'),
274
274
  colspan: opt_string_sym,
275
275
  headers: opt_string_sym,
276
276
  rowspan: opt_string_sym,
@@ -278,7 +278,7 @@ module Quince
278
278
  abbr: opt_string_sym,
279
279
  height: opt_string_sym,
280
280
  width: opt_string_sym,
281
- valign: Rbs('"top" | "middle" | "bottom" | "baseline" | Quince::Types::Undefined'),
281
+ valign: Rbs('"top" | "middle" | "bottom" | "baseline" | nil'),
282
282
  }.freeze,
283
283
  "Textarea" => {
284
284
  autocomplete: opt_string_sym,
@@ -300,7 +300,7 @@ module Quince
300
300
  }.freeze,
301
301
  "Tfoot" => {}.freeze,
302
302
  "Th" => {
303
- align: Rbs('"left" | "center" | "right" | "justify" | "char" | Quince::Types::Undefined'),
303
+ align: Rbs('"left" | "center" | "right" | "justify" | "char" | nil'),
304
304
  colspan: opt_string_sym,
305
305
  headers: opt_string_sym,
306
306
  rowspan: opt_string_sym,
@@ -364,10 +364,10 @@ module Quince
364
364
  "Hr" => {}.freeze,
365
365
  "Img" => {
366
366
  alt: opt_string_sym,
367
- crossorigin: Rbs('"anonymous" | "use-credentials" | "" | Quince::Types::Undefined'),
368
- decoding: Rbs('"async" | "auto" | "sync" | Quince::Types::Undefined'),
367
+ crossorigin: Rbs('"anonymous" | "use-credentials" | "" | nil'),
368
+ decoding: Rbs('"async" | "auto" | "sync" | nil'),
369
369
  height: Rbs("#{opt_string_sym} | Integer"),
370
- loading: Rbs('"eager" | "lazy" | Quince::Types::Undefined'),
370
+ loading: Rbs('"eager" | "lazy" | nil'),
371
371
  referrerpolicy: referrer_policy,
372
372
  sizes: opt_string_sym,
373
373
  src: opt_string_sym,
@@ -479,5 +479,3 @@ module Quince
479
479
  }.freeze
480
480
  end
481
481
  end
482
-
483
- Undefined = Quince::Types::Undefined
@@ -9,7 +9,6 @@ module Quince
9
9
 
10
10
  def Props(**kw)
11
11
  self.const_set "Props", TypedStruct.new(
12
- { default: Quince::Types::Undefined },
13
12
  Quince::Component::PARENT_SELECTOR_ATTR => String,
14
13
  Quince::Component::SELF_SELECTOR => String,
15
14
  **kw,
@@ -17,10 +16,7 @@ module Quince
17
16
  end
18
17
 
19
18
  def State(**kw)
20
- st = kw.empty? ? nil : TypedStruct.new(
21
- { default: Quince::Types::Undefined },
22
- **kw,
23
- )
19
+ st = kw.empty? ? nil : TypedStruct.new(**kw)
24
20
  self.const_set "State", st
25
21
  end
26
22
 
@@ -33,13 +29,13 @@ module Quince
33
29
  route: route,
34
30
  ) do |params|
35
31
  instance = Quince::Serialiser.deserialise(CGI.unescapeHTML(params[:component]))
36
- Quince::Component.class_variable_set :@@params, params
32
+ Quince::Component.class_variable_set :@@params, params[:params]
37
33
  render_with = if params[:rerender]
38
- instance.instance_variable_set :@state_container, params[:stateContainer]
39
- params[:rerender][:method].to_sym
40
- else
41
- :render
42
- end
34
+ instance.instance_variable_set :@state_container, params[:stateContainer]
35
+ params[:rerender][:method].to_sym
36
+ else
37
+ :render
38
+ end
43
39
  instance.instance_variable_set :@render_with, render_with
44
40
  instance.instance_variable_set :@callback_event, params[:event]
45
41
  if @exposed_actions.member? action
@@ -68,7 +64,11 @@ module Quince
68
64
 
69
65
  def initialize_props(const, id, **props)
70
66
  if const.const_defined?("Props")
71
- const::Props.new(PARENT_SELECTOR_ATTR => id, **props, SELF_SELECTOR => id)
67
+ const::Props.new(
68
+ PARENT_SELECTOR_ATTR => id,
69
+ **props,
70
+ SELF_SELECTOR => id
71
+ )
72
72
  end
73
73
  end
74
74
  end
@@ -102,11 +102,12 @@ module Quince
102
102
  SELF_SELECTOR = :"data-quid"
103
103
 
104
104
  def html_parent_selector
105
- "[#{PARENT_SELECTOR_ATTR}='#{__id}']".freeze
105
+ id = props ? props[SELF_SELECTOR] : __id
106
+ "[#{PARENT_SELECTOR_ATTR}='#{id}']".freeze
106
107
  end
107
108
 
108
109
  def html_self_selector
109
- "[#{SELF_SELECTOR}='#{props[SELF_SELECTOR]}']".freeze
110
+ "[#{SELF_SELECTOR}='#{__id}']".freeze
110
111
  end
111
112
  end
112
113
  end
@@ -49,13 +49,13 @@ module Quince
49
49
  internal = Quince::Serialiser.serialise receiver
50
50
  fn_name = "_Q_#{key}_#{receiver.send(:__id)}"
51
51
  rerender = value.rerender
52
- state_container = html_self_selector
52
+ state_container = selector
53
53
  push_params_state = value.push_params_state.to_json
54
54
  code = CALLBACK_ERB_INSTANCE.result(binding)
55
55
  return %Q{#{key}="#{CGI.escape_html(code)}" data-qu-#{key}-state="#{CGI.escapeHTML(internal)}"}
56
56
  when true
57
57
  return key
58
- when false, nil, Quince::Types::Undefined
58
+ when false, nil
59
59
  return nil
60
60
  else
61
61
  raise "prop type not yet implemented #{value}"
@@ -124,10 +124,3 @@ module Quince
124
124
 
125
125
  Quince::Component.include HtmlTagComponents
126
126
  end
127
-
128
- # tmp hack
129
- class TypedStruct < Struct
130
- def to_json(*args)
131
- to_h.to_json(*args)
132
- end
133
- end
@@ -23,12 +23,30 @@ module Quince
23
23
  Object.send :private, :expose
24
24
  end
25
25
 
26
- def define_constructor(const, constructor_name = const.to_s)
26
+ def define_constructor(const, constructor_name = nil)
27
+ if const.name
28
+ parts = const.name.split("::")
29
+ parent_namespace = Object.const_get(parts[0...-1].join("::")) if parts.length > 1
30
+ constructor_name ||= parts.last
31
+ end
32
+ constructor_name ||= const.to_s
33
+
27
34
  HtmlTagComponents.instance_eval do
28
- define_method(constructor_name) do |*children, **props, &block_children|
29
- new_props = { **props, Quince::Component::PARENT_SELECTOR_ATTR => __id }
35
+ mthd = lambda do |*children, **props, &block_children|
36
+ new_props = {
37
+ **props,
38
+ Quince::Component::PARENT_SELECTOR_ATTR => __id,
39
+ }
30
40
  const.create(*children, **new_props, &block_children)
31
41
  end
42
+
43
+ if parent_namespace
44
+ parent_namespace.instance_exec do
45
+ define_method(constructor_name, &mthd)
46
+ end
47
+ else
48
+ define_method(constructor_name, &mthd)
49
+ end
32
50
  end
33
51
  end
34
52
 
@@ -62,8 +80,10 @@ module Quince
62
80
 
63
81
  scr = to_html(HtmlTagComponents::Script.create(<<~JS, type: "text/javascript"))
64
82
  var stateContainer = document.querySelector(`#{selector}`);
83
+ console.log('yes');
65
84
  stateContainer.dataset.quOn#{event}State = #{updated_state};
66
85
  JS
86
+ output = output.render if output.is_a?(Component)
67
87
 
68
88
  output += (output.is_a?(String) ? scr : [scr])
69
89
  end
@@ -76,3 +96,10 @@ module Quince
76
96
  end
77
97
  end
78
98
  end
99
+
100
+ ############## TODO #############
101
+ # I think you should be able to know when a component is the first to be called in a render method,
102
+ # so you should be able to attach some props to it behind the scenes. Then any consumers of this
103
+ # state just have to know the selector, so they can read from it before passing it to the back end.
104
+ #
105
+ # Also, the front end needs to be updated such that script tags from the back end are always read
data/lib/quince/types.rb CHANGED
@@ -1,13 +1,8 @@
1
1
  module Quince
2
2
  module Types
3
- class Base; end
4
-
5
3
  # precompiled helper types
6
- OptionalString = Rbs("String | Quince::Types::Undefined").freeze
7
- OptionalBoolean = Rbs("true | false | Quince::Types::Undefined").freeze
8
-
9
- # no functional value for now, other than constants
10
- Undefined = Class.new(Base).new.freeze
11
- Any = Class.new(Base).new.freeze
4
+ OptionalString = Rbs("String?").freeze
5
+ OptionalBoolean = Rbs("true | false | nil").freeze
6
+ Any = Rbs("untyped").freeze
12
7
  end
13
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Quince
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quince
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Johansen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typed_struct