From a910690c76a02cb4dc693d107baa2a807bd02693 Mon Sep 17 00:00:00 2001 From: shahrul Date: Sat, 12 Oct 2024 21:09:48 +0800 Subject: [PATCH] update readme --- .rockspec | 5 +++-- README.md | 28 ++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.rockspec b/.rockspec index 572f9ce..d8ba7b5 100644 --- a/.rockspec +++ b/.rockspec @@ -1,5 +1,5 @@ package = "luax" -version = "1.0.1-1" +version = "1.0.1-2" source = { url = "https://github.com/syarul/luax/archive/refs/tags/v1.0.1.tar.gz", @@ -106,6 +106,7 @@ dependencies = { build = { type = "builtin", modules = { - luax = "luax.lua" + luax = "luax.lua", + h = "h.lua" } } diff --git a/README.md b/README.md index fdc4a0a..5d89087 100644 --- a/README.md +++ b/README.md @@ -6,37 +6,33 @@ Decent parse for HTML, so you don't have to write as concatenates string, in sho ### Usage +Install with `Luarocks` + +`luarocks install luax` + +load the `LuaX` `h` pragma **only** with ```lua local h = require('h') -local el = div( - { class = "container" }, - p({ class = "title" }, "Hello, world!"), - span({ style = "color: red;" }, "This is a span") -) - -print(h(el)) +print(h(div({ style = "color: red;" }, "Hello from LuaX!"))) ``` You'll get, ```html -

Hello, world!

This is a span
+
Hello from LuaX!
``` - -### Usage with JSX like syntax (HTML inside Lua) - -first create a `*.luax` file, then import the `LuaX` pragma `h` +So how to use with actual HTML syntax in Lua? First create a `*.luax` file, ```lua -- el.luax -local class = "container" -local el =
Hello, world!
-return el +local attr = { style="color: red;" } +return
hello from LuaX!
``` import it on to the main ```lua +-- import luax to handle the parsing of *.luax file local h = require('luax') local el = require('el') @@ -47,7 +43,7 @@ print(h(el)) You'll get, ```html -
Hello, world!
+
Hello from LuaX!
``` Sample usage with list/table structure