Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrul committed Oct 12, 2024
1 parent 3a98494 commit a910690
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .rockspec
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -106,6 +106,7 @@ dependencies = {
build = {
type = "builtin",
modules = {
luax = "luax.lua"
luax = "luax.lua",
h = "h.lua"
}
}
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div class="container"><p class="title">Hello, world!</p><span style="color: red;">This is a span</span></div>
<div style="color: red;">Hello from LuaX!</div>
```

### 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 = <div id="hello" class={class}>Hello, world!</div>
return el
local attr = { style="color: red;" }
return <div style={attr.stlye}>hello from LuaX!</div>
```

import it on to the main
```lua
-- import luax to handle the parsing of *.luax file
local h = require('luax')

local el = require('el')
Expand All @@ -47,7 +43,7 @@ print(h(el))
You'll get,

```html
<div class="container" id="hello">Hello, world!</div>
<div style="color: red;">Hello from LuaX!</div>
```

Sample usage with list/table structure
Expand Down

0 comments on commit a910690

Please sign in to comment.