Skip to content

Commit

Permalink
feat: Updated the projects README and added a LICENSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
HiImJulien committed Sep 16, 2024
1 parent c6f55c2 commit dd64789
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [HiImJulien]
ko_fi: jkirsch
24 changes: 24 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MIT License
-----------

Copyright (c) 2024 Julian Kirsch (https://juliankirsch.me)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
129 changes: 104 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,92 @@
# in-vite
<div align="center">
<h1>Welcome to in-vite :crab:</h1>
</div>

Integrate vite into your backend.
## What's in-vite?

## Installing
`In-vite` is a small library, inspired by Laravel's Vite Plugin. It allows you
to integrate vite's bundling capabilities into your Rust :crab: backend.

This library can be added to your project simply by calling:
## Getting Started :rocket:

```sh
cargo add in-vite
cargo install in-vite
```

## Integrations
The library revolves around the struct `Vite` which handles most aspects and
is required for integration:

This library includes integrations for template engines such as [tera](https://github.com/Keats/tera)
and [minijinja](https://github.com/mitsuhiko/minijinja). The integrations can
be activated by including the appropriate feature flag.
```rs

use in_vite::Vite;

fn main() {
let vite = Vite::default();

### Tera
// Retrieve the HTML required to include app.js and it's dependencies.
let code = vite.make_html(vec!["app.js"]).unwrap();
}

```

To install with the tera integration simply call:
> [!IMPORTANT]
> `in-vite` does not setup Vite by itself, rather it expects an already
> setup isntance.
> On how to setup Vite read further.
### Setting up Vite :construction:

This library requires an instance of Vite to be already setup. To setup Vite
use your favorite package manager, for example using `npm`:

```sh
npm create vite@latest
```

Next, you need to extend Vite's `vite.config.js`:

```js
// vite.config.js

export default defineConfig({
build: {
manifest: true,
rollupOptions: {
input: 'app.js'
},
}
});

```

The manifest is used in production builds to resolve the appropriate
build artifact.

> [!NOTE]
> You must manually specify entrypoints, since Vite has no `index.html`
> to go from.
### Further configurations

TODO: Once the struct `ViteOptions` is implemented, document it here.

## Integrations :world_map:

`in-vite` provides integrations for templating engines such as
[tera](https://github.com/Keats/tera) and
[minijinja](https://github.com/mitsuhiko/minijinja). Which can be activated
using the appropriate feature flag.

### Integration with `tera`

Using the feature flag `tera`, the integration can be activated:

```sh
cargo add in-vite -F tera
```

And integrated simply so:
Integrating Vite is as simple as registering a function with your `tera::Tera`
instance:

```rs

Expand All @@ -33,32 +95,49 @@ let vite = Vite::default();
let mut tera = tera::Tera::default();
tera.register_function("vite", vite);

let template = tera.render_str(r#"{{ vite(resources="app.js") }}"#, &tera::Context::new())?;

let template = tera.render_str(
r#"{{ vite(resources="views/foo.js") }}"#
)?;
```

### Minijinja
### Integration with `minijinja` :ninja:

To install with the minijinja integration simply call:
Like other integrations, this one can be activated with the feature flag `minijinja`:

```sh
cargo add in-vite -F minijinja
```

And integrated simply so:

```rs

let vite = Vite::default();

let mut env = minijinja::Environment::new();
env.add_global("vite", Value::from_object(vite));

let template = env.render_str(
r#"{{ vite(resources=["views/foo.js"]) }}"#
)?;
env.add_global("vite", minijinja::Value::from_object(vite));

let template = env.render_str(r#"{{ vite(resources="app.js") }}"#, minijinja::Value::UNDEFINED)?;
```

## Contributing

If you consider contributing, then first of all: Thank you! :gift_heart:
The first and simplest way to show your support is to star this repo.

This project accepts bug reports and feature requests via the integrated
[issue tracker](https://github.com/HiImJulien/in-vite/issues). Pull requests
for new integrations are also welcome!

Additionally, code reviews and pointers on how to improve the libraries code
are welcome. This is my first Rust library after all.

## Sponsoring

Thank you for considering sponsoring! While this project does not require
sponsoring, small donations are accepted. 100% of the donations are used to
provide a student (me) :man_student: with a steady supply of caffeinated beverages
which are then metabolized into 100% organic Rust code.

## License

This project is licensed under the MIT license, which you find
[here](https://github.com/HiImJulien/in-vite/blob/master/LICENSE.md).


2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mod test_tera {
#[cfg(feature = "minijinja")]
pub mod minijinja {

use minijinja::value::{from_args, FunctionArgs, Kwargs, Object, ObjectRepr};
use minijinja::value::{from_args, Kwargs, Object, ObjectRepr};
use minijinja::{Error, Value};
use std::sync::Arc;

Expand Down

0 comments on commit dd64789

Please sign in to comment.