snabberb 0.3.0 → 0.4.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: f6178782a46938a5569124c4fc28c148ed953a9bccf8cd7e4be2ba1835ca2b2c
4
- data.tar.gz: 925315dd99157e735c0c05771349473eee08381a567a4a532348e2287630a0d4
3
+ metadata.gz: 5d93f43d626c08cee99d8841191645c31e8d975401896b7f18ffee18c46ac459
4
+ data.tar.gz: 6f65115a69e13d77fccce6162c38f03f315d0c034e20e146af6c1acc3f5824b3
5
5
  SHA512:
6
- metadata.gz: b1b5b865a8bc623aef95f22f5c2cb1c53020ed7ec41d06b7f604cd88ba6ed94e677b0f765d23fd4bc96a7f09bac010263d2bcabe4c3894c8e7ee0ca882bbed0c
7
- data.tar.gz: 72f2d035af6f132b2a06fb165ea6ee20ab58ad50d165b41557ca028815b356808549346dd729cafc076d95c8642939cdf365f8a1ec9d045cde8b06eb25920c29
6
+ metadata.gz: b29014129127dc418951f000e0ddf47bd0a2985cd8c44cb8bada9b874c7a66d353db5ca6e6f18331b979fb3041a07a0b35dbaf3ef29bc8d667486f7e5d5ed7c7
7
+ data.tar.gz: 94cccfec82ed3572a3a718d8433ad031b291a977109747ffac5422731137cedc6a2d450e9506127330dcb4b1790bffc186aada5f0e2ca513b2957506ff2e5a3d
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('path/to/my\_component.rb', **needs)
158
+
159
+ This reads in the ruby file at the path and 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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snabberb
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/snabberb.rb CHANGED
@@ -18,7 +18,7 @@ module Snabberb
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,6 +38,19 @@ 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(file, **needs)
44
+ klass = file.split('/').last
45
+ .split('.').first
46
+ .split('_').map(&:capitalize).join
47
+
48
+ <<~RUBY
49
+ #{File.read(file)}
50
+ #{klass}.html(`#{wrap(needs)}`)
51
+ RUBY
52
+ end
53
+
41
54
  def self.prerender_script(layout, application, application_id, javascript_include_tags: '', **needs)
42
55
  needs = wrap(needs)
43
56
  attach_func = wrap_s("Opal.$$.#{application}.$attach(\"#{application_id}\", #{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.3.0
4
+ version: 0.4.0
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-17 00:00:00.000000000 Z
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal