vweb: look for html templates in `templates/`
							parent
							
								
									972f60d785
								
							
						
					
					
						commit
						a2d7bc6e6f
					
				| 
						 | 
					@ -86,20 +86,21 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
 | 
				
			||||||
	p.check(.rpar)
 | 
						p.check(.rpar)
 | 
				
			||||||
	// Compile vweb html template to V code, parse that V code and embed the resulting V function
 | 
						// Compile vweb html template to V code, parse that V code and embed the resulting V function
 | 
				
			||||||
	// that returns an html string.
 | 
						// that returns an html string.
 | 
				
			||||||
	mut path := p.cur_fn_name + '.html'
 | 
						html_name := '${p.cur_fn_name}.html'
 | 
				
			||||||
	// if p.pref.is_verbose {
 | 
						// Looking next to the vweb program
 | 
				
			||||||
	println('>>> compiling vweb HTML template "$path"')
 | 
						dir := os.dir(p.scanner.file_path)
 | 
				
			||||||
	// }
 | 
						mut path := os.join_path(dir, html_name)
 | 
				
			||||||
	if !os.exists(path) {
 | 
						if !os.exists(path) {
 | 
				
			||||||
		// Can't find the template file in current directory,
 | 
							// can be in `templates/`
 | 
				
			||||||
		// try looking next to the vweb program, in case it's run with
 | 
							path = os.join_path(dir, 'templates', html_name)
 | 
				
			||||||
		// v path/to/vweb_app.v
 | 
					 | 
				
			||||||
		path = os.dir(p.scanner.file_path) + '/' + path
 | 
					 | 
				
			||||||
		if !os.exists(path) {
 | 
							if !os.exists(path) {
 | 
				
			||||||
			p.error('vweb HTML template "$path" not found')
 | 
								p.error('vweb HTML template "$html_name" not found')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// println('path is now "$path"')
 | 
							// println('path is now "$path"')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// if p.pref.is_verbose {
 | 
				
			||||||
 | 
						println('>>> compiling vweb HTML template "$path"')
 | 
				
			||||||
 | 
						// }
 | 
				
			||||||
	v_code := tmpl.compile_file(path, p.cur_fn_name)
 | 
						v_code := tmpl.compile_file(path, p.cur_fn_name)
 | 
				
			||||||
	mut scope := &ast.Scope{
 | 
						mut scope := &ast.Scope{
 | 
				
			||||||
		start_pos: 0
 | 
							start_pos: 0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,9 +30,9 @@ pub fn compile_template(content, fn_name string) string {
 | 
				
			||||||
	// lines := os.read_lines(path)
 | 
						// lines := os.read_lines(path)
 | 
				
			||||||
	mut html := content
 | 
						mut html := content
 | 
				
			||||||
	mut header := ''
 | 
						mut header := ''
 | 
				
			||||||
	if os.exists('header.html') && html.contains('@header') {
 | 
						if os.exists('templates/header.html') && html.contains('@header') {
 | 
				
			||||||
		h := os.read_file('header.html') or {
 | 
							h := os.read_file('templates/header.html') or {
 | 
				
			||||||
			panic('reading file header.html failed')
 | 
								panic('reading file templates/header.html failed')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		header = h.replace("\'", '"')
 | 
							header = h.replace("\'", '"')
 | 
				
			||||||
		html = header + html
 | 
							html = header + html
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue