You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-10Lines changed: 70 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,11 +40,12 @@ go get github.com/yaitoo/xun@latest
40
40
`Xun` has some specified directories that is used to organize code, routing and static assets.
41
41
-`public`: Static assets to be served.
42
42
-`components` A partial view that is shared between layouts/pages/views.
43
-
-`views`: A internal page view. It is used in `context.View` to render different view from current routing.
43
+
-`views`: An internal page view that can be referenced in `context.View` to render different UI for current routing.
44
44
-`layouts`: A layout is shared between multiple pages/views
45
-
-`pages`: A public page view. It also is used to automatically create a accessible page routing.
45
+
-`pages`: A public page view that will create public page routing automatically.
46
+
-`text`: An internal text view that can be referenced in `context.View` to render with a data model.
46
47
47
-
*NB: All html files(component,layout, view and page) will be parsed by [html/template](https://pkg.go.dev/html/template). You can feel free to use all built-in [Actions,Pipelines and Functions](https://pkg.go.dev/text/template), and your custom functions that is registered in `HtmlViewEngine`.*
48
+
**NOTE: All html files(component,layout, view and page) will be parsed by [html/template](https://pkg.go.dev/html/template). You can feel free to use all built-in [Actions,Pipelines and Functions](https://pkg.go.dev/text/template), and your custom functions that is registered in `HtmlViewEngine`.**
48
49
49
50
### Layouts and Pages
50
51
`Xun` uses file-system based routing, meaning you can use folders and files to define routes. This section will guide you through how to create layouts and pages, and link between them.
@@ -110,7 +111,7 @@ You can create a layout(.html) file inside the `layouts` directory.
110
111
### Static assets
111
112
You can store static files, like images, fonts, js and css, under a directory called `public` in the root directory. Files inside public can then be referenced by your code starting from the base URL (/).
112
113
113
-
*NB: `public/index.html` will be exposed by `/` instead of `/index.html`.*
114
+
**NOTE: `public/index.html` will be exposed by `/` instead of `/index.html`.**
114
115
115
116
#### Creating a component
116
117
A component is a partial view that is shared between multiple layouts/pages/views.
@@ -148,6 +149,66 @@ A component is a partial view that is shared between multiple layouts/pages/view
148
149
</html>
149
150
```
150
151
152
+
### Text View
153
+
A text view is UI that is referenced in `context.View` to render the view with a data model.
154
+
155
+
**NOTE: Text files are parsed using the `text/template` package. This is different from the `html/template` package used in `pages/layouts/views/components`. While `text/template` is designed for generating textual output based on data, it does not automatically secure HTML output against certain attacks. Therefore, please ensure your output is safe to prevent code injection.**
@@ -171,7 +232,7 @@ Page Router only serve static content from html files. We have to define router
171
232
```
172
233
173
234
174
-
*NB: An `/index.html` always be registered as `/{$}` in routing table. See more detail on [Routing Enhancements for Go 1.22](https://go.dev/blog/routing-enhancements).*
235
+
**NOTE: An `/index.html` always be registered as `/{$}` in routing table. See more detail on [Routing Enhancements for Go 1.22](https://go.dev/blog/routing-enhancements).**
175
236
> There is one last bit of syntax. As we showed above, patterns ending in a slash, like /posts/, match all paths beginning with that string. To match only the path with the trailing slash, you can write /posts/{$}. That will match /posts/ but not /posts or /posts/234.
176
237
177
238
#### Dynamic Routes
@@ -217,11 +278,11 @@ For examples, below patterns will be generated automatically, and registered in
217
278
```
218
279
219
280
220
-
### Multiple Viewers based on MIME request
221
-
In our application, a routing can have multiple viewers. Response is render based on the request header `Accept`. Default viewer is used if there is no any viewer is matched by `Accept`. The built-it default viewer is `JsonViewer`. But it can be overridden by`xun.WithViewer`in `xun.New`. see more examples on [Tests](app_test.go)
281
+
### Multiple Viewers
282
+
In our application, a route can support multiple viewers. The response is rendered based on the `Accept` request header. If no viewer matches the `Accept` header, the default viewer is used. The built-in default viewer is `JsonViewer`, but this can be overridden using`xun.WithViewer`when initializing with `xun.New`. For more examples, see the [Tests](app_test.go).
222
283
223
-
> curl -v http://127.0.0.1
224
-
```
284
+
```bash
285
+
curl -v http://127.0.0.1
225
286
> GET / HTTP/1.1
226
287
> Host: 127.0.0.1
227
288
> User-Agent: curl/8.7.1
@@ -265,7 +326,6 @@ In our application, a routing can have multiple viewers. Response is render base
265
326
</body>
266
327
</html>
267
328
```
268
-
269
329
### Middleware
270
330
Middleware allows you to run code before a request is completed. Then, based on the incoming request, you can modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.
0 commit comments