Skip to content

Commit

Permalink
Updated the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RussBaz committed Mar 14, 2024
1 parent 43a1134 commit 3cc74e6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 55 deletions.
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "cc76b894169a3c86b71bac10c78a4db6beb7a9ad",
"version" : "3.2.0"
"revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb",
"version" : "3.3.0"
}
},
{
Expand Down Expand Up @@ -131,17 +131,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "635b2589494c97e48c62514bc8b37ced762e0a62",
"version" : "2.63.0"
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "363da63c1966405764f380c627409b2f9d9e710b",
"version" : "1.21.0"
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63",
"version" : "1.22.0"
}
},
{
Expand Down
106 changes: 57 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,51 +67,51 @@ public func configure(_ app: Application) async throws {

## Table of Contents

- [What is HTMX?](#what-is-htmx)
- [HTMX](#htmx)
- [Installation](#installation)
- [Configuration](#configuration)
- [HX Request Extensions](#hx-request-extensions)
- [HX Extension Method and HX\<MyType\>](#hx-extension-method-and-hxmytype)
- [HX Templateable and Custom Templating Engines](#hx-templateable-and-custom-templating-engines)
- [Request Headers](#request-headers)
- [Response Headers](#response-headers)
- [Overview](#overview)
- [Location](#location)
- [Push Url](#htmx)
- [Redirect](#htmx)
- [Refresh](#htmx)
- [Replace Url](#htmx)
- [Reselect](#htmx)
- [Reswap](#htmx)
- [Retarget](#htmx)
- [Trigger, Trigger After Settle and Trigger After Swap](#htmx)
- [HXError, Abort and HXErrorMiddleware](#htmx)
- [HXRedirect](#htmx)
- [Simple Localisation](#htmx)
- [Configuration](#htmx)
- [HXLocalisable Protocol and HXLocalisation](#htmx)
- [HXRequestLocalisation](#htmx)
- [Custom HXTextTag Leaf Tag](#htmx)
- [Other Utilities](#htmx)
- [String + View](#htmx)
- [Date + Custom Interval](#htmx)
- [Request + Base Url](#htmx)
- [HXAsyncCommand](#htmx)
- [staticRoute Helper](#htmx)
- [Changelog](#htmx)
- [HTMX Demo](#htmxleaf-demo)
- [What is HTMX?](#what-is-htmx)
- [HTMX](#htmx)
- [Installation](#installation)
- [Configuration](#configuration)
- [HX Request Extensions](#hx-request-extensions)
- [HX Extension Method and HX\<MyType\>](#hx-extension-method-and-hxmytype)
- [HX Templateable and Custom Templating Engines](#hx-templateable-and-custom-templating-engines)
- [Request Headers](#request-headers)
- [Response Headers](#response-headers)
- [Overview](#overview)
- [Location](#location)
- [Push Url](#htmx)
- [Redirect](#htmx)
- [Refresh](#htmx)
- [Replace Url](#htmx)
- [Reselect](#htmx)
- [Reswap](#htmx)
- [Retarget](#htmx)
- [Trigger, Trigger After Settle and Trigger After Swap](#htmx)
- [HXError, Abort and HXErrorMiddleware](#htmx)
- [HXRedirect](#htmx)
- [Simple Localisation](#htmx)
- [Configuration](#htmx)
- [HXLocalisable Protocol and HXLocalisation](#htmx)
- [HXRequestLocalisation](#htmx)
- [Custom HXTextTag Leaf Tag](#htmx)
- [Other Utilities](#htmx)
- [String + View](#htmx)
- [Date + Custom Interval](#htmx)
- [Request + Base Url](#htmx)
- [HXAsyncCommand](#htmx)
- [staticRoute Helper](#htmx)
- [Changelog](#htmx)
- [HTMX Demo](#htmxleaf-demo)

## What is HTMX?

Here is my hot take: Make your backend code the single source of truth for your project, and drop most of your front end bloat in favour of updating your HTML in-place and seamlessly. Without reloading the page and with only your server side HTML templates. Learn more at [htmx.org](https://htmx.org/).

And here is the official intro:

> - Why should only `<a>` and `<form>` be able to make HTTP requests?
> - Why should only `click` & `submit` events trigger them?
> - Why should only `GET` & `POST` methods be available?
> - Why should you only be able to replace the **_entire_** screen?
> - Why should only `<a>` and `<form>` be able to make HTTP requests?
> - Why should only `click` & `submit` events trigger them?
> - Why should only `GET` & `POST` methods be available?
> - Why should you only be able to replace the **_entire_** screen?
>
> By removing these **_arbitrary constraints_**, htmx completes HTML as a **_hypertext_**.
Expand All @@ -123,13 +123,13 @@ Lastly, here is a quick introduction to HTMX by `Fireship`: [htmx in 100 seconds

SPM installation:

- Add the package to your package dependencies
- Add the package to your package dependencies

```swift
.package(url: "https://github.com/RussBaz/VaporHX.git", from: "0.0.22"),
.package(url: "https://github.com/RussBaz/VaporHX.git", from: "0.0.23"),
```

- Then add it to your target dependencies
- Then add it to your target dependencies

```swift
.product(name: "VHX", package: "VaporHX"),
Expand Down Expand Up @@ -299,7 +299,15 @@ routes.get("slot") { req in
}
```

To learn more about the `HXResponseHeaders`, please refere to the Response Headers section.
To add an HTMX specific header to a response, you can update `response.headers` extension:

```swift
req.htmx.response.headers // HXResponseHeaders
```

Otherwise, you can provide a header to any `render` method. It will override any previously specified headers.

To learn more about the `HXResponseHeaders`, please refere to the [Response Headers](#response-headers) section.

How to redirect quickly with proper HTMX headers?

Expand Down Expand Up @@ -462,16 +470,16 @@ This is a showcase of some HTMX features built with the Leaf templating engine a

#### To run the demo using Xcode

- Open this project in Xcode
- Switch the scheme from `VHX` to `Demo` (left hand side of the top url bar)
- Confirm that the correct Run Target is selected (likely 'My Mac')
- Set the custom working directory in the scheme editor to the root folder of this package as shown in the [Vapor docs](https://docs.vapor.codes/getting-started/xcode/). Otherwise, it will display a warning in the console and it will be unable to find leaf templates.
- Press the play / run button
- Then head to `http://localhost:8080`
- Open this project in Xcode
- Switch the scheme from `VHX` to `Demo` (left hand side of the top url bar)
- Confirm that the correct Run Target is selected (likely 'My Mac')
- Set the custom working directory in the scheme editor to the root folder of this package as shown in the [Vapor docs](https://docs.vapor.codes/getting-started/xcode/). Otherwise, it will display a warning in the console and it will be unable to find leaf templates.
- Press the play / run button
- Then head to `http://localhost:8080`

#### To run the demo using the command line

- execute the following from the VaporHX projects root dir
- execute the following from the VaporHX projects root dir

```bash
swift run Demo
Expand Down

0 comments on commit 3cc74e6

Please sign in to comment.