Giter Site home page Giter Site logo

reluax's Introduction

Reluax

Crates.io Version

reluax lets you easily create dynamic websites in a custom dialect of Lua, inspired by JSX. The service has been written in Rust, and uses luajit as its Lua runtime for performance and ease of integration of other libraries.

Requirements

  • luajit

Installation

Currently, the project is only supported on Linux and MacOS.

Reluax is available through GitHub releases as a prebuilt binary, or from crates.io through cargo install reluax, if you have the Rust toolchain installed. Alternatively, it is packaged as a Nix flake: if you have Nix installed, you can nix run github:Duckonaut/reluax.

Usage

Commands:
  serve  Serve a directory of LuaX files in production mode
  build  Build a directory of LuaX files
  dev    Serve a directory of LuaX files in development mode
  new    Create a new project
  init   Initialize a new project in the current directory
  help   Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help

Examples:
  reluax serve
  reluax serve --port 4000
  reluax dev -P public/ -C luax/

To create an example project, run reluax new my-first-project.

Inspiration

The project was heavily inspired by Ben Visness' blog post, I made JSX for Lua (because I hate static sites), which I highly recommend reading.

API

A Reluax project is very simple. Reluax expects to run a directory of files, with the entry point being reluax.luax or reluax.lua. This module needs to return a table containing the member function route, and optionally a project name under the key name. For code examples, check the examples directory.

The route function will be called with the path and, optionally, method and body of a request, and can return a variety of responses, by returning two values: the status code, and the response body.

The response body will usually be a table, and by default will be treated as a HTML page (see example/basic/). It can be optionally wrapped using the functions reluax.html or reluax.json, the first of which will make sure the HTML is returned as is, without a <!DOCTYPE html> tag, and the second returning the table as a JSON object.

With this you can build a rather powerful backend, handling templating, routing, and anything else through LuaX code.

The reluax global table contains several utility functions, described below:

  • reluax.json: wrap the table to be interpreted as a JSON response,
  • reluax.html_page: wrap the table to be interpreted as a full HTML page (default behavior),
  • reluax.html: wrap the table to be interpreted as a HTML excerpt (for e.g. use with htmx),
  • reluax.path_matches: check if a path string matches the template,
  • reluax.path_extract: extract named path parameters from the path.

reluax's People

Contributors

duckonaut avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.