Skip to content

Commit 16522df

Browse files
committed
revert lte syntax change
1 parent 93ae424 commit 16522df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+272
-287
lines changed

src/manifest.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ mod test {
9797
# SPDX-License-Identifier: MIT
9898
9999
beforeDevCommand = npm start -- --port 1420
100-
beforeBuildCommand = {{ pkg_manager_run_command }} build # this comment should be stripped
100+
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
101101
devPath = http://localhost:1420
102102
103103
[mobile]
104-
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
104+
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
105105
106106
[files]
107107
tauri.svg = src/assets/tauri.svg
@@ -115,7 +115,7 @@ mod test {
115115

116116
Manifest {
117117
before_dev_command: Some("npm start -- --port 1420"),
118-
before_build_command: Some("{{ pkg_manager_run_command }} build"),
118+
before_build_command: Some("{% pkg_manager_run_command %} build"),
119119
dev_path: Some("http://localhost:1420"),
120120
dist_dir: None,
121121
with_global_tauri: None,
@@ -130,7 +130,7 @@ mod test {
130130

131131
Manifest {
132132
before_dev_command: Some("npm start -- --port 1420"),
133-
before_build_command: Some("{{ pkg_manager_run_command }} build mobile"),
133+
before_build_command: Some("{% pkg_manager_run_command %} build mobile"),
134134
dev_path: Some("http://localhost:1420"),
135135
dist_dir: None,
136136
with_global_tauri: None,
@@ -152,7 +152,7 @@ mod test {
152152
devPath = http://localhost:1420
153153
154154
[mobile]
155-
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
155+
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
156156
157157
[files]
158158
tauri.svg = src/assets/tauri.svg
@@ -170,9 +170,9 @@ mod test {
170170
# SPDX-License-Identifier: MIT
171171
172172
beforeDevCommand = npm start -- --port 1420
173-
beforeBuildCommand = {{ pkg_manager_run_command }} build # this comment should be stripped
173+
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
174174
devPath = http://localhost:1420
175-
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
175+
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
176176
177177
[files]
178178
tauri.svg = src/assets/tauri.svg
@@ -186,7 +186,7 @@ mod test {
186186

187187
Manifest {
188188
before_dev_command: Some("npm start -- --port 1420"),
189-
before_build_command: Some("{{ pkg_manager_run_command }} build mobile"),
189+
before_build_command: Some("{% pkg_manager_run_command %} build mobile"),
190190
dev_path: Some("http://localhost:1420"),
191191
dist_dir: None,
192192
with_global_tauri: None,

src/template.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'a> Template {
362362
};
363363

364364
// Only modify files that need to use the template engine
365-
let (file_data, file_name) = if let Some(file_name) = file_name.strip_suffix(".lts") {
365+
let (file_data, file_name) = if let Some(file_name) = file_name.strip_suffix(".lte") {
366366
let file_data = EMBEDDED_TEMPLATES::get(file).unwrap().data.to_vec();
367367
let file_data_as_str = std::str::from_utf8(&file_data)?;
368368
(

src/utils/lte.rs

+19-34
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ enum Token<'a> {
4343
impl Display for Token<'_> {
4444
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4545
match self {
46-
Token::OBracket => write!(f, "{{{{"),
46+
Token::OBracket => write!(f, "{{%"),
4747
Token::If => write!(f, "if"),
4848
Token::Var(var) => write!(f, "{} (variable)", var),
4949
Token::Else => write!(f, "else"),
5050
Token::EndIf => write!(f, "endif"),
51-
Token::CBracket => write!(f, "}}}}"),
51+
Token::CBracket => write!(f, "%}}"),
5252
Token::Text(_) => write!(f, "(text)"),
5353
Token::Invalid(col) => write!(f, "invalid token at {col}"),
5454
}
@@ -90,10 +90,6 @@ impl<'a> Lexer<'a> {
9090
self.bytes[self.cursor + 1] as char
9191
}
9292

93-
fn prev_char(&self) -> char {
94-
self.bytes[self.cursor.saturating_sub(1)] as char
95-
}
96-
9793
fn skip_whitespace(&mut self) {
9894
while self.cursor < self.len && self.current_char().is_whitespace() {
9995
self.cursor += 1;
@@ -128,13 +124,13 @@ impl<'a> Lexer<'a> {
128124
return None;
129125
}
130126

131-
if self.current_char() == '{' && self.next_char() == '{' && self.prev_char() != '\\' {
127+
if self.current_char() == '{' && self.next_char() == '%' {
132128
self.in_bracket = true;
133129
self.cursor += 2;
134130
return Some(Token::OBracket);
135131
}
136132

137-
if self.current_char() == '}' && self.next_char() == '}' {
133+
if self.current_char() == '%' && self.next_char() == '}' {
138134
self.in_bracket = false;
139135
self.cursor += 2;
140136
return Some(Token::CBracket);
@@ -158,10 +154,7 @@ impl<'a> Lexer<'a> {
158154

159155
if !self.in_bracket {
160156
let start = self.cursor;
161-
while !(self.current_char() == '{'
162-
&& self.next_char() == '{'
163-
&& self.prev_char() != '\\')
164-
{
157+
while !(self.current_char() == '{' && self.next_char() == '%') {
165158
self.cursor += 1;
166159

167160
if self.cursor >= self.len {
@@ -394,7 +387,7 @@ mod tests {
394387

395388
#[test]
396389
fn it_replaces_variable() {
397-
let template = "<html>Hello {{ name }}</html>";
390+
let template = "<html>Hello {% name %}</html>";
398391
let data: HashMap<&str, &str> = [("name", "world")].into();
399392
let rendered = render(template, &data).expect("it should render");
400393
assert_eq!(rendered, "<html>Hello world</html>")
@@ -405,7 +398,7 @@ mod tests {
405398
let template = r#"
406399
<html>
407400
<h1>Hello<h2>
408-
<em>{{ name }}</em>
401+
<em>{% name %}</em>
409402
</html>"#;
410403
let data: HashMap<&str, &str> = [("name", "world")].into();
411404
let rendered = render(template, &data).expect("it should render");
@@ -419,15 +412,15 @@ mod tests {
419412

420413
#[test]
421414
fn it_performs_condition() {
422-
let template = "<html>Hello {{ if alpha }}alpha{{ else }}stable{{ endif }}</html>";
415+
let template = "<html>Hello {% if alpha %}alpha{% else %}stable{% endif %}</html>";
423416
let data: HashMap<&str, bool> = [("alpha", true)].into();
424417
let rendered = render(template, &data).expect("it should render");
425418
assert_eq!(rendered, "<html>Hello alpha</html>")
426419
}
427420

428421
#[test]
429422
fn it_performs_else_condition() {
430-
let template = "<html>Hello {{ if alpha }}alpha{{ else }}stable{{ endif }}</html>";
423+
let template = "<html>Hello {% if alpha %}alpha{% else %}stable{% endif %}</html>";
431424
let data: HashMap<&str, bool> = [("alpha", false)].into();
432425
let rendered = render(template, &data).expect("it should render");
433426
assert_eq!(rendered, "<html>Hello stable</html>")
@@ -437,9 +430,9 @@ mod tests {
437430
fn it_performs_condition_with_new_lines() {
438431
let template = r#"
439432
<html>
440-
<h1>Hello<h2>{{ if alpha }}
441-
<em>alpha</em>{{ else }}
442-
<em>stable</em>{{ endif }}
433+
<h1>Hello<h2>{% if alpha %}
434+
<em>alpha</em>{% else %}
435+
<em>stable</em>{% endif %}
443436
</html>"#;
444437
let data: HashMap<&str, bool> = [("alpha", true)].into();
445438
let rendered = render(template, &data).expect("it should render");
@@ -455,9 +448,9 @@ mod tests {
455448
fn it_replaces_variable_within_if() {
456449
let template = r#"
457450
<html>
458-
<h1>Hello<h2>{{ if alpha }}
459-
<em>{{ alpha_str }}</em>{{ else }}
460-
<em>stable</em>{{ endif }}
451+
<h1>Hello<h2>{% if alpha %}
452+
<em>{% alpha_str %}</em>{% else %}
453+
<em>stable</em>{% endif %}
461454
</html>"#;
462455
let data: HashMap<&str, &str> = [("alpha", "true"), ("alpha_str", "holla alpha")].into();
463456
let rendered = render(template, &data).expect("it should render");
@@ -473,9 +466,9 @@ mod tests {
473466
fn it_performs_nested_conditions() {
474467
let template = r#"
475468
<html>
476-
<h1>Hello<h2>{{ if alpha }}
477-
<em>{{ alpha_str }}</em>{{ else }}
478-
<em>{{ if beta }}beta{{else}}stable{{endif}}</em>{{ endif }}
469+
<h1>Hello<h2>{% if alpha %}
470+
<em>{% alpha_str %}</em>{% else %}
471+
<em>{% if beta %}beta{%else%}stable{%endif%}</em>{% endif %}
479472
</html>"#;
480473
let data: HashMap<&str, &str> = [
481474
("alpha", "false"),
@@ -494,17 +487,9 @@ mod tests {
494487

495488
#[test]
496489
fn it_panics() {
497-
let template = "<html>Hello {{ name }</html>";
490+
let template = "<html>Hello {% name }</html>";
498491
let data: HashMap<&str, &str> = [("name", "world")].into();
499492
let rendered = render(template, &data);
500493
assert!(rendered.is_err())
501494
}
502-
503-
#[test]
504-
fn it_escapes_brackets() {
505-
let template = "<html>Hello \\{{ name }}</html>";
506-
let data: HashMap<&str, &str> = [("name", "world")].into();
507-
let rendered = render(template, &data).unwrap();
508-
assert_eq!(rendered, template)
509-
}
510495
}

templates/_base_/src-tauri/Cargo.toml.lts templates/_base_/src-tauri/Cargo.toml.lte

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "{{ package_name }}"
2+
name = "{% package_name %}"
33
version = "0.0.0"
44
description = "A Tauri App"
55
authors = ["you"]
@@ -9,21 +9,21 @@ edition = "2021"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

12-
{{ if mobile }}[lib]
13-
name = "{{ lib_name }}"
12+
{% if mobile %}[lib]
13+
name = "{% lib_name %}"
1414
crate-type = ["staticlib", "cdylib", "rlib"]
1515

16-
{{ endif }}{{ if stable }}[build-dependencies]
16+
{% endif %}{% if stable %}[build-dependencies]
1717
tauri-build = { version = "1.5", features = [] }
1818

1919
[dependencies]
2020
tauri = { version = "1.5", features = ["shell-open"] }
21-
serde = { version = "1.0", features = ["derive"] }{{ else }}[build-dependencies]
21+
serde = { version = "1.0", features = ["derive"] }{% else %}[build-dependencies]
2222
tauri-build = { version = "2.0.0-alpha", features = [] }
2323

2424
[dependencies]
2525
tauri = { version = "2.0.0-alpha", features = [] }
26-
tauri-plugin-shell = "2.0.0-alpha"{{ endif }}
26+
tauri-plugin-shell = "2.0.0-alpha"{% endif %}
2727
serde_json = "1.0"
2828

2929
[features]
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
{{ if mobile }}fn main() {
5-
{{ lib_name }}::run()
6-
}{{ else }}// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
4+
{% if mobile %}fn main() {
5+
{% lib_name %}::run()
6+
}{% else %}// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
77
#[tauri::command]
88
fn greet(name: &str) -> String {
99
format!("Hello, {}! You've been greeted from Rust!", name)
1010
}
1111

1212
fn main() {
1313
tauri::Builder::default()
14-
{{ if alpha }}.plugin(tauri_plugin_shell::init())
15-
{{ endif }}.invoke_handler(tauri::generate_handler![greet])
14+
{% if alpha %}.plugin(tauri_plugin_shell::init())
15+
{% endif %}.invoke_handler(tauri::generate_handler![greet])
1616
.run(tauri::generate_context!())
1717
.expect("error while running tauri application");
18-
}{{ endif }}
18+
}{% endif %}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"build": {
3-
"beforeDevCommand": "{{ before_dev_command }}",
4-
"beforeBuildCommand": "{{ before_build_command }}",
5-
"devPath": "{{ dev_path }}",
6-
"distDir": "{{ dist_dir }}"{{ if with_global_tauri }},
7-
"withGlobalTauri": true{{ endif }}
3+
"beforeDevCommand": "{% before_dev_command %}",
4+
"beforeBuildCommand": "{% before_build_command %}",
5+
"devPath": "{% dev_path %}",
6+
"distDir": "{% dist_dir %}"{% if with_global_tauri %},
7+
"withGlobalTauri": true{% endif %}
88
},
99
"package": {
10-
"productName": "{{ project_name }}",
10+
"productName": "{% project_name %}",
1111
"version": "0.0.0"
1212
},
1313
"tauri": {
14-
{{ if stable }}"allowlist": {
14+
{% if stable %}"allowlist": {
1515
"all": false,
1616
"shell": {
1717
"all": false,
1818
"open": true
1919
}
2020
},
21-
{{ endif }}"bundle": {
21+
{% endif %}"bundle": {
2222
"active": true,
2323
"targets": "all",
2424
"identifier": "com.tauri.dev",
@@ -37,15 +37,15 @@
3737
{
3838
"fullscreen": false,
3939
"resizable": true,
40-
"title": "{{ package_name }}",
40+
"title": "{% package_name %}",
4141
"width": 800,
4242
"height": 600
4343
}
4444
]
45-
}{{ if alpha }},
45+
}{% if alpha %},
4646
"plugins": {
4747
"shell": {
4848
"open": true
4949
}
50-
}{{ endif }}
50+
}{% endif %}
5151
}

templates/template-angular/angular.json.lts templates/template-angular/angular.json.lte

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"analytics": false
77
},
88
"projects": {
9-
"{{ package_name }}": {
9+
"{% package_name %}": {
1010
"projectType": "application",
1111
"root": "",
1212
"sourceRoot": "src",
@@ -15,7 +15,7 @@
1515
"build": {
1616
"builder": "@angular-devkit/build-angular:application",
1717
"options": {
18-
"outputPath": "dist/{{ package_name }}",
18+
"outputPath": "dist/{% package_name %}",
1919
"index": "src/index.html",
2020
"browser": "src/main.ts",
2121
"polyfills": ["zone.js"],
@@ -54,10 +54,10 @@
5454
},
5555
"configurations": {
5656
"production": {
57-
"buildTarget": "{{ package_name }}:build:production"
57+
"buildTarget": "{% package_name %}:build:production"
5858
},
5959
"development": {
60-
"buildTarget": "{{ package_name }}:build:development"
60+
"buildTarget": "{% package_name %}:build:development"
6161
}
6262
},
6363
"defaultConfiguration": "development"

templates/template-angular/package.json.lts templates/template-angular/package.json.lte

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "{{ package_name }}",
2+
"name": "{% package_name %}",
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
@@ -21,8 +21,8 @@
2121
"rxjs": "~7.8.0",
2222
"tslib": "^2.3.0",
2323
"zone.js": "~0.14.2",
24-
"@tauri-apps/api": "^{{ if alpha }}2.0.0-alpha.13{{ else }}1.5.2{{ endif }}"{{ if alpha }},
25-
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{{ endif }}
24+
"@tauri-apps/api": "^{% if alpha %}2.0.0-alpha.13{% else %}1.5.2{% endif %}"{% if alpha %},
25+
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{% endif %}
2626
},
2727
"devDependencies": {
2828
"@angular-devkit/build-angular": "^17.0.0",
@@ -36,7 +36,7 @@
3636
"karma-jasmine": "~5.1.0",
3737
"karma-jasmine-html-reporter": "~2.1.0",
3838
"typescript": "~5.2.2",
39-
"@tauri-apps/cli": "^{{ if alpha }}2.0.0-alpha.20{{ else }}1.5.8{{ endif }}"{{ if mobile }},
40-
"internal-ip": "^7.0.0"{{ endif }}
39+
"@tauri-apps/cli": "^{% if alpha %}2.0.0-alpha.20{% else %}1.5.8{% endif %}"{% if mobile %},
40+
"internal-ip": "^7.0.0"{% endif %}
4141
}
4242
}

templates/template-angular/src/app/app.component.ts.lts templates/template-angular/src/app/app.component.ts.lte

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { RouterOutlet } from '@angular/router';
4-
import { invoke } from "@tauri-apps/api/{{ if alpha }}core{{ else }}tauri{{ endif }}";
4+
import { invoke } from "@tauri-apps/api/{% if alpha %}core{% else %}tauri{% endif %}";
55

66
@Component({
77
selector: 'app-root',

0 commit comments

Comments
 (0)