snabberb 0.2.4 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fc1b684696419ba26366b26922802d661635f8452743719193df207e598d60f
4
- data.tar.gz: 47d16aa7f91e1701edbe569774152cde79eeda6a662b6e4db01d4ff284de17a7
3
+ metadata.gz: 369d9786428f032c2c1469feb43f8e9945a64f321ae6e43cec71d79f4aaf5df2
4
+ data.tar.gz: 8f6e1288c3255f2348a4507935666a83c5935f2c7d095596c174edd146b87b82
5
5
  SHA512:
6
- metadata.gz: 91194ec6fe066a29737216a032414e6b5783caac41e6a149a5c39dfc33129c4c4b3de18b93645268941c1c6eb7c28bca20c5ffbdf714fc37e20eb6fba16fbd9e
7
- data.tar.gz: 35d178a9782c1a23685a8759e978e5941e149424aff2d87cc18491c1ce04af0770b94198461459e313e91cbda7b3a3ce490028ddeef2ed39007c5b4c68fb4946
6
+ metadata.gz: ee8dd3445a8f30df166e099d0e4ec2b5982787c307f4bdac7457b61195fd907940e75fb63c6cb0cccc870cc8ca32360615c12bdbc5aef2ad2b5ce747385c55d1
7
+ data.tar.gz: 716c08332f52cb7751506e4add860fee6be25fb546f66e31dfb6d794796a65a47bb01a78e10ceb2f2a9873e6cef050fba2ec2f93cb40e0368571a507a1fb3a8a
@@ -6,6 +6,13 @@ Metrics/AbcSize:
6
6
 
7
7
  Metrics/BlockLength:
8
8
  Enabled: False
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Enabled: False
12
+
13
+ Metrics/PerceivedComplexity:
14
+ Enabled: False
15
+
9
16
  Metrics/LineLength:
10
17
  Max: 120
11
18
 
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:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- snabberb (0.2.3)
4
+ snabberb (0.2.5)
5
5
  opal (~> 1.0)
6
6
 
7
7
  GEM
@@ -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({
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snabberb
4
- VERSION = '0.2.4'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -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
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-04-10 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal