Skip to content

Commit

Permalink
Support escaping bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksrutins committed Dec 28, 2023
1 parent b292cb1 commit c006539
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pages/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Cheetah uses the magic of [declarative shadow DOM](https://developer.chrome.com/
to make components work, so styles, scripts, and even IDs
are scoped to the component.

You can access attributes using the `{{attribute name}}` syntax, and you can render children using the standard [`slot`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) API.
You can access attributes using the `{{attribute name}}` syntax (if you want to put in a literal `{{ something }}`, you can escape it by putting a `!` character in front of it), and you can render children using the standard [`slot`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) API.

Speaking of scripts, to make more complicated components
(like the counter above), you'll want some JavaScript.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
url: $!{{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 5 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ impl Template {
ctx: &TemplateContext,
) -> Result<(), Box<dyn Error>> {
let scripts_ref_cloned = scripts_ref.clone();
let bind_regex = Regex::new(r"\{\{(?P<var>.*?)\}\}").unwrap();
let bind_regex = Regex::new(r"[^\!]\{\{(?P<var>.*?)\}\}").unwrap();
let literal_bind_regex = Regex::new(r"\!\{\{").unwrap();
let node = root.deref_mut();

let settings = SETTINGS.lock().unwrap();
Expand Down Expand Up @@ -232,6 +233,9 @@ impl Template {
}
})
.to_string();
*text = literal_bind_regex
.replace_all(&text, "{{")
.to_string();

if let Some(registrar) = registrar {
registrar
Expand Down

0 comments on commit c006539

Please sign in to comment.