snabberb 0.2.2 → 0.2.3

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: a6a868a7ec1133bc5e3617bde205e2f0a84041aa2ce6f97269e2fddafeb8497f
4
- data.tar.gz: 92cf990366dea913a45f51154152e81d250574470664015547d71cb7f1f953f8
3
+ metadata.gz: b15637622254f2080520c2d7f9eab0506f3f8e1241bf9a0ab34e85c9416ef778
4
+ data.tar.gz: 0a52f88337e6539c8224ccb0b0aff4a4d686958af759b315a0366f35aa79509b
5
5
  SHA512:
6
- metadata.gz: fee9ee7329921aa01e1f98f3db5c4d00e17450234753cb97dca55ffc932eb5223f7cc64fe4f856104741e0bea6524f3fec2de080521fd0c72123c346493558d9
7
- data.tar.gz: 10356451c19e97f22922256fd24f9e6fdbd5ec6247056cfdc4e5eed3bd07fb5d0a9ebd36063ff827ac1a203df15183948734b0847997786eb6d067032e24f2ba
6
+ metadata.gz: 7a6b654ac78a9debd4ef0cdfae6d20ef753056c48fdafd54b1ed96626fd4e2d68f1157aa43bcb078796a39ebb92eb3de0d8d5c34ac9e679dec8ebcca968ca322
7
+ data.tar.gz: 54a35672f3495b40e3208d60cf3cd20c3d26b4f74deac105fddea42595c076fa82ea360df25e4609b17ad221f41051d7f74a89b3115d2df529bd041e42defce0
data/README.md CHANGED
@@ -45,6 +45,8 @@ TextBox.html(text: 'hello world')
45
45
 
46
46
  [Roda App with HTML Prerendering](examples/roda)
47
47
 
48
+ [18xx Board Game Engine](https://github.com/tobymao/18xx)
49
+
48
50
  ## Usage
49
51
 
50
52
  ### Creating DOM Elements With h
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- snabberb (0.2.1)
4
+ snabberb (0.2.2)
5
5
  opal (~> 1.0)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snabberb
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
data/lib/snabberb.rb CHANGED
@@ -7,14 +7,44 @@ require 'snabberb/version'
7
7
  Opal.append_path(File.expand_path('../opal', __dir__))
8
8
 
9
9
  module Snabberb
10
+ def self.wrap(obj)
11
+ case obj
12
+ when Hash
13
+ wrap_h(obj)
14
+ when Array
15
+ wrap_a(obj)
16
+ when String
17
+ wrap_s(obj)
18
+ else
19
+ obj
20
+ end
21
+ end
22
+
23
+ def self.wrap_s(str)
24
+ JSON.generate(str)
25
+ end
26
+
27
+ def self.wrap_a(array)
28
+ "[#{array.map { |v| wrap(v) }.join(',')}]"
29
+ end
30
+
31
+ def self.wrap_h(hash)
32
+ args = hash.flat_map do |k, v|
33
+ [wrap_s(k), wrap(v)]
34
+ end.join(',')
35
+
36
+ "Opal.hash(#{args})"
37
+ end
38
+
10
39
  def self.prerender_script(layout, application, application_id, javascript_include_tags: '', **needs)
11
- needs = JSON.generate(needs)
40
+ needs = wrap(needs)
41
+ attach_func = wrap_s("Opal.$$.#{application}.$attach(\"#{application_id}\", #{needs})")
12
42
 
13
43
  <<~JS
14
44
  Opal.$$.#{layout}.$html(Opal.hash({
15
- application: Opal.$$.#{application}.$new(null, Opal.hash(#{needs})).$render(),
45
+ application: Opal.$$.#{application}.$new(null, #{needs}).$render(),
16
46
  javascript_include_tags: '#{javascript_include_tags.gsub("\n", '')}',
17
- attach_func: 'Opal.$$.#{application}.$attach("#{application_id}", Opal.hash(#{needs}))'
47
+ attach_func: #{attach_func}
18
48
  }))
19
49
  JS
20
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snabberb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Mao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-15 00:00:00.000000000 Z
11
+ date: 2020-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal