snabberb 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/examples/rack/Gemfile.lock +4 -4
- data/examples/roda/Gemfile.lock +6 -6
- data/examples/roda/{app → assets/js}/application.rb +15 -4
- data/examples/roda/{app → assets/js}/polyfill.js +0 -1
- data/examples/roda/build/.keep +0 -0
- data/examples/roda/config.ru +25 -22
- data/lib/snabberb/version.rb +1 -1
- data/opal/snabberb/component.rb +3 -3
- metadata +6 -6
- data/examples/roda/app/requires.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6a868a7ec1133bc5e3617bde205e2f0a84041aa2ce6f97269e2fddafeb8497f
|
4
|
+
data.tar.gz: 92cf990366dea913a45f51154152e81d250574470664015547d71cb7f1f953f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee9ee7329921aa01e1f98f3db5c4d00e17450234753cb97dca55ffc932eb5223f7cc64fe4f856104741e0bea6524f3fec2de080521fd0c72123c346493558d9
|
7
|
+
data.tar.gz: 10356451c19e97f22922256fd24f9e6fdbd5ec6247056cfdc4e5eed3bd07fb5d0a9ebd36063ff827ac1a203df15183948734b0847997786eb6d067032e24f2ba
|
data/.gitignore
CHANGED
data/examples/rack/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
snabberb (0.2.
|
4
|
+
snabberb (0.2.1)
|
5
5
|
opal (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -11,12 +11,12 @@ GEM
|
|
11
11
|
c_lexer (2.6.4.1.1)
|
12
12
|
ast (~> 2.4.0)
|
13
13
|
parser (= 2.6.4.1)
|
14
|
-
opal (1.0.
|
14
|
+
opal (1.0.2)
|
15
15
|
ast (>= 2.3.0)
|
16
16
|
parser (~> 2.6)
|
17
17
|
parser (2.6.4.1)
|
18
18
|
ast (~> 2.4.0)
|
19
|
-
rack (2.0
|
19
|
+
rack (2.1.0)
|
20
20
|
|
21
21
|
PLATFORMS
|
22
22
|
ruby
|
@@ -28,4 +28,4 @@ DEPENDENCIES
|
|
28
28
|
snabberb!
|
29
29
|
|
30
30
|
BUNDLED WITH
|
31
|
-
2.
|
31
|
+
2.1.2
|
data/examples/roda/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
snabberb (0.2.
|
4
|
+
snabberb (0.2.1)
|
5
5
|
opal (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,9 +14,9 @@ GEM
|
|
14
14
|
concurrent-ruby (1.1.5)
|
15
15
|
execjs (2.7.0)
|
16
16
|
libv8 (7.3.492.27.1)
|
17
|
-
mini_racer (0.2.
|
17
|
+
mini_racer (0.2.9)
|
18
18
|
libv8 (>= 6.9.411)
|
19
|
-
opal (1.0.
|
19
|
+
opal (1.0.2)
|
20
20
|
ast (>= 2.3.0)
|
21
21
|
parser (~> 2.6)
|
22
22
|
opal-sprockets (0.4.8.1.0.3.7)
|
@@ -25,8 +25,8 @@ GEM
|
|
25
25
|
tilt (>= 1.4)
|
26
26
|
parser (2.6.4.1)
|
27
27
|
ast (~> 2.4.0)
|
28
|
-
rack (2.0
|
29
|
-
roda (3.
|
28
|
+
rack (2.1.0)
|
29
|
+
roda (3.27.0)
|
30
30
|
rack
|
31
31
|
sprockets (3.7.2)
|
32
32
|
concurrent-ruby (~> 1.0)
|
@@ -46,4 +46,4 @@ DEPENDENCIES
|
|
46
46
|
snabberb!
|
47
47
|
|
48
48
|
BUNDLED WITH
|
49
|
-
2.
|
49
|
+
2.1.2
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'compiled-opal'
|
4
|
+
require 'polyfill'
|
5
|
+
require 'snabberb'
|
3
6
|
require 'set'
|
4
7
|
|
5
8
|
class Tile < Snabberb::Component
|
@@ -18,6 +21,7 @@ class Hex < Snabberb::Component
|
|
18
21
|
|
19
22
|
needs :x
|
20
23
|
needs :y
|
24
|
+
needs :id
|
21
25
|
needs :selected, default: Set.new, store: true
|
22
26
|
|
23
27
|
def translation
|
@@ -50,6 +54,7 @@ class Hex < Snabberb::Component
|
|
50
54
|
transform: transform,
|
51
55
|
fill: selected ? 'yellow' : 'white',
|
52
56
|
stroke: 'black',
|
57
|
+
id: @id,
|
53
58
|
},
|
54
59
|
style: { cursor: 'pointer' },
|
55
60
|
on: { click: onclick }
|
@@ -66,9 +71,14 @@ class Map < Snabberb::Component
|
|
66
71
|
def render
|
67
72
|
hexes = @size_x.times.flat_map do |x|
|
68
73
|
@size_y.times.map do |y|
|
69
|
-
|
74
|
+
row = y
|
75
|
+
column = x
|
76
|
+
|
77
|
+
next nil if (row.even? && column.even?) || (row.odd? && column.odd?)
|
78
|
+
|
79
|
+
h(Hex, id: "#{row},#{column}", x: x, y: y)
|
70
80
|
end
|
71
|
-
end
|
81
|
+
end.compact
|
72
82
|
|
73
83
|
container_style = {
|
74
84
|
width: '100%',
|
@@ -76,9 +86,10 @@ class Map < Snabberb::Component
|
|
76
86
|
overflow: 'auto',
|
77
87
|
}
|
78
88
|
|
89
|
+
# adding 44 and 21 helps with lower size_x and size_y values
|
79
90
|
svg_style = {
|
80
|
-
width: "#{@size_x * 50}px",
|
81
|
-
height: "#{@size_y * 80}px",
|
91
|
+
width: "#{44 + (@size_x * 50)}px",
|
92
|
+
height: "#{21 + (@size_y * 80)}px",
|
82
93
|
}
|
83
94
|
|
84
95
|
h(:div, { props: { id: 'map_id' }, style: container_style }, [
|
File without changes
|
data/examples/roda/config.ru
CHANGED
@@ -2,37 +2,40 @@
|
|
2
2
|
|
3
3
|
require 'execjs'
|
4
4
|
require 'opal'
|
5
|
-
require 'opal/sprockets'
|
6
5
|
require 'roda'
|
7
|
-
require 'sprockets'
|
8
6
|
require 'snabberb'
|
7
|
+
require 'tilt/opal'
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
Opal.
|
13
|
-
|
9
|
+
class OpalTemplate < Opal::TiltTemplate
|
10
|
+
def evaluate(_scope, _locals)
|
11
|
+
builder = Opal::Builder.new(stubs: 'opal')
|
12
|
+
builder.append_paths('assets/js')
|
13
|
+
builder.append_paths('build')
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
opal_path = 'build/compiled-opal.js'
|
16
|
+
File.write(opal_path, Opal::Builder.build('opal')) unless File.exist?(opal_path)
|
17
17
|
|
18
|
-
|
18
|
+
content = builder.build(file).to_s
|
19
|
+
map_json = builder.source_map.to_json
|
20
|
+
"#{content}\n#{to_data_uri_comment(map_json)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_data_uri_comment(map_json)
|
24
|
+
"//# sourceMappingURL=data:application/json;base64,#{Base64.encode64(map_json).delete("\n")}"
|
25
|
+
end
|
26
|
+
end
|
19
27
|
|
20
|
-
|
21
|
-
Opal.paths.each { |p| environment.append_path(p) }
|
28
|
+
Tilt.register 'rb', OpalTemplate
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
)
|
30
|
+
class App < Roda
|
31
|
+
plugin :public
|
32
|
+
plugin :assets, js: 'application.rb'
|
33
|
+
compile_assets
|
34
|
+
context = ExecJS.compile(File.read("#{assets_opts[:compiled_js_path]}.#{assets_opts[:compiled]['js']}.js"))
|
29
35
|
|
30
36
|
route do |r|
|
31
37
|
r.public
|
32
|
-
|
33
|
-
r.on 'assets' do
|
34
|
-
r.run environment
|
35
|
-
end
|
38
|
+
r.assets
|
36
39
|
|
37
40
|
r.root do
|
38
41
|
context.eval(
|
@@ -40,7 +43,7 @@ class App < Roda
|
|
40
43
|
'Index',
|
41
44
|
'Map',
|
42
45
|
'map_id',
|
43
|
-
javascript_include_tags:
|
46
|
+
javascript_include_tags: assets(:js),
|
44
47
|
size_x: 30,
|
45
48
|
size_y: 30,
|
46
49
|
)
|
data/lib/snabberb/version.rb
CHANGED
data/opal/snabberb/component.rb
CHANGED
@@ -107,9 +107,9 @@ module Snabberb
|
|
107
107
|
@root.node = node
|
108
108
|
end
|
109
109
|
|
110
|
-
# Store a value and trigger and update.
|
110
|
+
# Store a value and trigger and update unless skip is true.
|
111
111
|
# If called with no arguments, return the store object.
|
112
|
-
def store(key = nil, value = nil)
|
112
|
+
def store(key = nil, value = nil, skip: false)
|
113
113
|
return @store if key.nil?
|
114
114
|
raise "Cannot store key '#{key}' since it is not a stored need of #{self.class}." unless stores?(key)
|
115
115
|
|
@@ -119,7 +119,7 @@ module Snabberb
|
|
119
119
|
instance_variable_set(ivar, value)
|
120
120
|
@root.instance_variable_set(ivar, value) if !root? && @root.stores?(key)
|
121
121
|
|
122
|
-
update
|
122
|
+
update unless skip
|
123
123
|
end
|
124
124
|
|
125
125
|
def class_needs
|
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.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2020-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -136,9 +136,9 @@ files:
|
|
136
136
|
- examples/roda/Gemfile
|
137
137
|
- examples/roda/Gemfile.lock
|
138
138
|
- examples/roda/README.md
|
139
|
-
- examples/roda/
|
140
|
-
- examples/roda/
|
141
|
-
- examples/roda/
|
139
|
+
- examples/roda/assets/js/application.rb
|
140
|
+
- examples/roda/assets/js/polyfill.js
|
141
|
+
- examples/roda/build/.keep
|
142
142
|
- examples/roda/config.ru
|
143
143
|
- examples/roda/roda_example.png
|
144
144
|
- lib/snabberb.rb
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
177
|
+
rubygems_version: 3.1.2
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: A simple Opal view framework based on Snabbdom.
|