Low Nodes are the flexible building blocks of your application. They can respond to a route request, or they can be called by another node. They can render a return value, or they can create an event. They are designed to be specific enough to observe events and return values, but generic enough to be split up to represent a complex application with its own patterns and structure.
Nodes can render HTML/JSON directly from the Ruby class (via RBX, similar to JSX) and render other nodes into the output using Antlers syntax; <html><{ ChildNode }></html>.
Use .rbx as your file extension and now you can place HTML inside of render():
class MyNode < LowNode
def render
<p>Hello</p>
end
endAntlers syntax can be embedded within RBX:
class ParentNode < LowNode
def render
<html><{ ChildNode }></html>
end
end
class ChildNode < LowNode
def render
<strong>Hello</strong>
end
endWhich outputs:
<html><strong>Hello</strong></html>ℹ️ For the full syntax guide see Antlers.
LowNode converts props to immutable copies, allowing you to run sections of code in parallel:
def render
<{ parallelize: }>
# For Loop executed at the same time as UserNode.
<{ for: user in: @users }>
<{ UserNode user=user }>
<{ :for }>
# PostsNode executed at the same time as For Loop.
<{ PostsNode }>
<{ :parallelize }>
endA node's action can set cookies with its response, and return a redirect:
class LoginNode < LowNode
include Controller
def post(event:)
set_cookie('session', 'token', max_age: 30 * 24 * 60 * 60)
redirect('/')
end
endCookies are HttpOnly, Secure and SameSite=Lax unless you say otherwise, like set_cookie('theme', 'dark', http_only: false), and max_age: 0 expires one. A redirect is a 303, so the browser gets the new address after a form, and redirect('/', status: 302) changes it. Add any other header with response_headers.add('cache-control', 'no-store').
Use .rb as your file extension to render using string interpolation:
class MyNode < LowNode
def initialize
@greeting = 'Hello'
end
def render
<<~HTML
<p>#{@greeting}</p>
HTML
end
end