-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrender.rb
More file actions
29 lines (24 loc) · 810 Bytes
/
render.rb
File metadata and controls
29 lines (24 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'extism'
url = 'https://github.com/extism/reactables/releases/latest/download/reactable.core.wasm'
manifest = Extism::Manifest.from_url url
reactable = Extism::Plugin.new(manifest)
jsx_code = <<~JSX
export function App(props) {
return <h1>Hello {props.customerName}!</h1>
}
JSX
# Compile our JSX template and register by name
reactable.call('compileTemplate',
JSON.generate(
name: 'greeting-template',
code: jsx_code
))
# Render with customer specific props
props = { customerName: 'Benjamin' }
html = reactable.call('render',
JSON.generate(
templateName: 'greeting-template',
props: props
))
puts html
# => <h1>Hello Benjamin!</h1>