snabberb 0.2.4 → 0.4.2
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 +4 -4
- data/.rubocop.yml +7 -0
- data/README.md +8 -0
- data/examples/roda/Gemfile.lock +1 -1
- data/lib/snabberb.rb +17 -3
- data/lib/snabberb/version.rb +1 -1
- data/opal/snabberb/component.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 369d9786428f032c2c1469feb43f8e9945a64f321ae6e43cec71d79f4aaf5df2
|
4
|
+
data.tar.gz: 8f6e1288c3255f2348a4507935666a83c5935f2c7d095596c174edd146b87b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee8dd3445a8f30df166e099d0e4ec2b5982787c307f4bdac7457b61195fd907940e75fb63c6cb0cccc870cc8ca32360615c12bdbc5aef2ad2b5ce747385c55d1
|
7
|
+
data.tar.gz: 716c08332f52cb7751506e4add860fee6be25fb546f66e31dfb6d794796a65a47bb01a78e10ceb2f2a9873e6cef050fba2ec2f93cb40e0368571a507a1fb3a8a
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -150,6 +150,14 @@ Snabberb.prerender_script('LayoutClass', 'ApplicationClass', 'application_id', j
|
|
150
150
|
|
151
151
|
A detailed example can be found [in the Roda example](examples/roda).
|
152
152
|
|
153
|
+
### Generating HTML from a File
|
154
|
+
|
155
|
+
You can generate HTML from a component with a file.
|
156
|
+
|
157
|
+
Snabberb.html\_script('path/to/my\_component.rb', **needs)
|
158
|
+
|
159
|
+
This reads in the ruby file at the path and generates javascript that calls html on the CamelCased version of the file name.
|
160
|
+
|
153
161
|
## Installation
|
154
162
|
|
155
163
|
Add this line to your application's Gemfile:
|
data/examples/roda/Gemfile.lock
CHANGED
data/lib/snabberb.rb
CHANGED
@@ -13,12 +13,12 @@ module Snabberb
|
|
13
13
|
wrap_h(obj)
|
14
14
|
when Array
|
15
15
|
wrap_a(obj)
|
16
|
-
when Numeric
|
16
|
+
when Numeric, TrueClass, FalseClass
|
17
17
|
obj
|
18
18
|
when nil
|
19
19
|
'Opal.nil'
|
20
20
|
else
|
21
|
-
wrap_s(obj)
|
21
|
+
wrap_s(obj.to_s)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -38,10 +38,24 @@ module Snabberb
|
|
38
38
|
"Opal.hash(#{args})"
|
39
39
|
end
|
40
40
|
|
41
|
+
# takes in a file and needs
|
42
|
+
# calls html on the CamelCased version of the file with the needs
|
43
|
+
def self.html_script(file, **needs)
|
44
|
+
klass = file.split('/').last
|
45
|
+
.split('.').first
|
46
|
+
.split('_').map(&:capitalize).join
|
47
|
+
|
48
|
+
script = <<~RUBY
|
49
|
+
#{File.read(file)}
|
50
|
+
#{klass}.html(`#{wrap(needs)}`)
|
51
|
+
RUBY
|
52
|
+
|
53
|
+
Opal.compile(script).strip.chomp(';')
|
54
|
+
end
|
55
|
+
|
41
56
|
def self.prerender_script(layout, application, application_id, javascript_include_tags: '', **needs)
|
42
57
|
needs = wrap(needs)
|
43
58
|
attach_func = wrap_s("Opal.$$.#{application}.$attach(\"#{application_id}\", #{needs})")
|
44
|
-
puts attach_func
|
45
59
|
|
46
60
|
<<~JS
|
47
61
|
Opal.$$.#{layout}.$html(Opal.hash({
|
data/lib/snabberb/version.rb
CHANGED
data/opal/snabberb/component.rb
CHANGED
@@ -139,7 +139,7 @@ module Snabberb
|
|
139
139
|
def init_needs(needs)
|
140
140
|
class_needs.each do |key, opts|
|
141
141
|
ivar = "@#{key}"
|
142
|
-
if @store.key?(key)
|
142
|
+
if @store.key?(key) && opts[:store]
|
143
143
|
instance_variable_set(ivar, @store[key])
|
144
144
|
elsif needs.key?(key)
|
145
145
|
@store[key] = needs[key] if opts[:store] && !@store.key?(key)
|
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.4.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-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|