Use jte template engine
This commit is contained in:
47
pom.xml
47
pom.xml
@@ -15,6 +15,7 @@
|
||||
<description>Bad-practice editor</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<jte.version>3.0.3</jte.version>
|
||||
<repackage.classifier/>
|
||||
<spring-native.version>0.12.1</spring-native.version>
|
||||
</properties>
|
||||
@@ -23,10 +24,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mustache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
@@ -47,6 +44,17 @@
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>gg.jte</groupId>
|
||||
<artifactId>jte</artifactId>
|
||||
<version>${jte.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gg.jte</groupId>
|
||||
<artifactId>jte-spring-boot-starter-2</artifactId>
|
||||
<version>${jte.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
@@ -110,6 +118,37 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>gg.jte</groupId>
|
||||
<artifactId>jte-maven-plugin</artifactId>
|
||||
<version>${jte.version}</version>
|
||||
<configuration>
|
||||
<sourceDirectory>${basedir}/src/main/jte</sourceDirectory>
|
||||
<contentType>Html</contentType>
|
||||
<targetResourceDirectory>${project.build.directory}/classes</targetResourceDirectory>
|
||||
<extensions>
|
||||
<extension>
|
||||
<className>gg.jte.nativeimage.NativeResourcesExtension</className>
|
||||
</extension>
|
||||
</extensions>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jte-gen</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>gg.jte</groupId>
|
||||
<artifactId>jte-native-resources</artifactId>
|
||||
<version>${jte.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.github.russp.bpe.config;
|
||||
|
||||
import gg.jte.springframework.boot.autoconfigure.ReactiveJteAutoConfiguration;
|
||||
import gg.jte.springframework.boot.autoconfigure.ReactiveJteViewResolver;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Locale;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@ImportAutoConfiguration(ReactiveJteAutoConfiguration.class)
|
||||
@RequiredArgsConstructor
|
||||
public class JteConfiguration {
|
||||
|
||||
private final ReactiveJteViewResolver jteViewResolver;
|
||||
|
||||
@PostConstruct
|
||||
public void vr() {
|
||||
log.info("ReactiveJteViewResolver created: {}", jteViewResolver);
|
||||
jteViewResolver.resolveViewName("login", Locale.ENGLISH)
|
||||
.log()
|
||||
.block();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class BrowserController {
|
||||
model.addAttribute("breadcrumbs", breadcrumbs);
|
||||
model.addAttribute("selectedFile", path);
|
||||
|
||||
model.addAttribute("selectedFileName", Paths.get(path).getFileName());
|
||||
model.addAttribute("selectedFileName", Paths.get(path).getFileName().toString());
|
||||
return "edit";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
@import java.util.List
|
||||
@import com.github.russp.bpe.http.FileDto
|
||||
|
||||
@param List<FileDto> files
|
||||
@param List<FileDto> breadcrumbs
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
@@ -26,9 +32,9 @@
|
||||
<nav>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
{{#breadcrumbs}}
|
||||
<li><a href="/?path={{fullName}}">{{name}}</a></li>
|
||||
{{/breadcrumbs}}
|
||||
@for(FileDto breadcrumb : breadcrumbs)
|
||||
<li><a href="/?path=${breadcrumb.getFullName()}">${breadcrumb.getName()}</a></li>
|
||||
@endfor
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
@@ -47,26 +53,25 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#files}}
|
||||
@for(FileDto file : files)
|
||||
<tr>
|
||||
<th scope="row">
|
||||
{{#dir}}
|
||||
<a href="/?path={{fullName}}">
|
||||
@if(file.isDir())
|
||||
<a href="/?path=${file.getFullName()}">
|
||||
<i class="fa fa-folder"></i>
|
||||
{{name}}
|
||||
${file.getName()}
|
||||
</a>
|
||||
{{/dir}}
|
||||
{{^dir}}
|
||||
<a href="/edit?path={{fullName}}">
|
||||
@else
|
||||
<a href="/edit?path=${file.getFullName()}">
|
||||
<i class="fa fa-file"></i>
|
||||
{{name}}
|
||||
${file.getName()}
|
||||
</a>
|
||||
{{/dir}}
|
||||
@endif
|
||||
</th>
|
||||
<td>{{modifiedAt}}</td>
|
||||
<td>{{size}}</td>
|
||||
<td>${file.getModifiedAt()}</td>
|
||||
<td>${file.getSize()}</td>
|
||||
</tr>
|
||||
{{/files}}
|
||||
@endfor
|
||||
</tbody>
|
||||
</table>
|
||||
</figure>
|
||||
@@ -1,3 +1,14 @@
|
||||
@import java.util.List
|
||||
@import org.springframework.security.web.server.csrf.CsrfToken
|
||||
@import com.github.russp.bpe.http.FileDto
|
||||
|
||||
@param String selectedFile
|
||||
@param String selectedFileName
|
||||
@param List<FileDto> breadcrumbs
|
||||
|
||||
@param CsrfToken _csrf
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
@@ -5,10 +16,10 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Browser">
|
||||
|
||||
<meta name="_csrf" content="{{_csrf.token}}"/>
|
||||
<meta name="_csrf_header" content="{{_csrf.headerName}}"/>
|
||||
<meta name="_csrf" content="${_csrf.getToken()}"/>
|
||||
<meta name="_csrf_header" content="${_csrf.getHeaderName()}"/>
|
||||
|
||||
<title>Edit {{selectedFileName}}</title>
|
||||
<title>Edit ${selectedFileName}</title>
|
||||
|
||||
<link rel="shortcut icon" href="https://picocss.com/favicon.ico">
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
|
||||
@@ -23,14 +34,14 @@
|
||||
<body>
|
||||
|
||||
<header class="container">
|
||||
<h5>Edit {{selectedFileName}}</h5>
|
||||
<h5>Edit ${selectedFileName}</h5>
|
||||
<nav>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
{{#breadcrumbs}}
|
||||
<li><a href="/?path={{fullName}}">{{name}}</a></li>
|
||||
{{/breadcrumbs}}
|
||||
<li>{{selectedFileName}}</li>
|
||||
@for(FileDto breadcrumb : breadcrumbs)
|
||||
<li><a href="/?path=${breadcrumb.getFullName()}">${breadcrumb.getName()}</a></li>
|
||||
@endfor
|
||||
<li>${selectedFileName}</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="javascript:save()" role="button">Save</a></li>
|
||||
@@ -71,7 +82,7 @@
|
||||
|
||||
<script>
|
||||
var modelist = require("ace/ext/modelist");
|
||||
var mode = modelist.getModeForPath("{{selectedFileName}}");
|
||||
var mode = modelist.getModeForPath("${selectedFileName}");
|
||||
var editor = ace.edit("editor",
|
||||
{
|
||||
mode: mode.mode,
|
||||
@@ -80,7 +91,7 @@
|
||||
});
|
||||
document.getElementById('editor').style.fontSize = '1.2em';
|
||||
|
||||
fetch('/content?path={{selectedFile}}')
|
||||
fetch('/content?path=${selectedFile}')
|
||||
.then(function (response) {
|
||||
return response.text()
|
||||
})
|
||||
@@ -94,11 +105,11 @@
|
||||
var blob = new Blob([editor.getValue()]);
|
||||
var formData = new FormData();
|
||||
formData.set("file", blob);
|
||||
fetch('/content?path={{selectedFile}}', {
|
||||
fetch('/content?path=${selectedFile}', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
"{{_csrf.headerName}}": "{{_csrf.token}}"
|
||||
"${_csrf.getHeaderName()}": "${_csrf.getToken()}"
|
||||
},
|
||||
body: formData,
|
||||
})
|
||||
@@ -1,3 +1,7 @@
|
||||
@import org.springframework.security.web.server.csrf.CsrfToken
|
||||
|
||||
@param CsrfToken _csrf
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
@@ -14,7 +18,7 @@
|
||||
<!-- Pico.css -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
|
||||
<!-- Custom template-->
|
||||
<!-- <link rel="stylesheet" href="/stylesheet.css">-->
|
||||
<!-- <link rel="stylesheet" href="/stylesheet.css">-->
|
||||
<style>
|
||||
|
||||
/* Grid */
|
||||
@@ -107,7 +111,7 @@
|
||||
<form method="post">
|
||||
<input type="text" name="username" placeholder="Username" aria-label="Login" autocomplete="nickname" required>
|
||||
<input type="password" name="password" placeholder="Password" aria-label="Password" autocomplete="current-password" required>
|
||||
<input type="hidden" name="{{_csrf.parameterName}}" value="{{_csrf.token}}"/>
|
||||
<input type="hidden" name="${_csrf.getParameterName()}" value="${_csrf.getToken()}"/>
|
||||
<button type="submit" class="contrast">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -1,35 +0,0 @@
|
||||
<header class="container">
|
||||
<hgroup>
|
||||
<h1>Basic template</h1>
|
||||
<h2>A basic custom template for Pico using only CSS custom properties (variables).</h2>
|
||||
</hgroup>
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<details role="list">
|
||||
<summary aria-haspopup="listbox" role="button" class="secondary">Theme</summary>
|
||||
<ul role="listbox">
|
||||
<li><a href="#" data-theme-switcher="auto">Auto</a></li>
|
||||
<li><a href="#" data-theme-switcher="light">Light</a></li>
|
||||
<li><a href="#" data-theme-switcher="dark">Dark</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
<li>
|
||||
<details role="list">
|
||||
<summary aria-haspopup="listbox">Examples</summary>
|
||||
<ul role="listbox">
|
||||
<li><a href="../preview/">Preview</a></li>
|
||||
<li><a href="../preview-rtl/">Right-to-left</a></li>
|
||||
<li><a href="../classless/">Class-less</a></li>
|
||||
<li><a href="../basic-template/">Basic template</a></li>
|
||||
<li><a href="../company/">Company</a></li>
|
||||
<li><a href="../google-amp/">Google Amp</a></li>
|
||||
<li><a href="../sign-in/">Sign in</a></li>
|
||||
<li><a href="../bootstrap-grid/">Bootstrap grid</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
Reference in New Issue
Block a user