-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support pipe
in Serbea 2.0, add new pure Ruby template syntax (WIP)
#817
Conversation
Your Render PR Server URL is https://bridgetown-beta-pr-817.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-ckicctglk5ic73beqg90. |
Your Render PR Server URL is https://bridgetown-api-pr-817.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-ckicctolk5ic73beqgf0. |
Note: this PR includes one breaking change to the default cookies setup for Roda (to set the cookie path to |
I'm going to go ahead and merge this in, and create some follow-up issues for the documentation, etc. |
Serbea 2.0 brings with it a new pipe helper that you can use in any Ruby context (including ERB). Example in a PORO:
This PR brings that into Bridgetown templates and components, as well as adds a brand-new enhanced "HTML-in-Ruby" syntax based on heredocs. (Update: I've extracted this out to a standalone gem, Streamlined, that Bridgetown will then import.)
Syntax example:
You can think of the new
text
,html
,render
, andhtml_map
helpers for HTML-in-Ruby as somewhat analogous to "tagged template literals" in JavaScript. HTML-in-Ruby is an alternative template format to ERB and Serbea, and can be used in any.rb
resource template as well as PORO components as in the example above.A RuboCop linter will be provided so that any
HTML
orMARKDOWN
heredoc with interpolated expressions not starting with an approved helper can be flagged. This is to ensure security against XSS…because Ruby doesn't provide any way to process interpolated expressions before they're inserted into the string, we have no way of HTML escaping content by default. By intentionally choosing thetext
helper, you get an escaped string. Or by usinghtml
/render
/etc., it will not escape.The file-based routes syntax is also improved, with a new Ruby front matter style available so you can write route handlers like: