Skip to content

Commit 160a285

Browse files
author
shahrul
committed
use meta
1 parent a910690 commit 160a285

File tree

7 files changed

+135
-219
lines changed

7 files changed

+135
-219
lines changed

.rockspec

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,13 @@
11
package = "luax"
2-
version = "1.0.1-2"
2+
version = "1.0.2-1"
33

44
source = {
5-
url = "https://github.com/syarul/luax/archive/refs/tags/v1.0.1.tar.gz",
6-
dir = "luax-1.0.1"
5+
url = "https://github.com/syarul/luax/archive/refs/tags/v1.0.2.tar.gz",
6+
dir = "luax-1.0.2"
77
}
88
description = {
99
summary = "HTML parse in Lua",
10-
detailed = [[## LuaX
11-
Decent parse for HTML, so you don't have to write as concatenates string, in short a React JSX implementation in LUA.
12-
13-
<a href="https://luarocks.org/modules/syarul/luax" rel="nofollow"><img alt="Luarocks Package" src="https://img.shields.io/badge/Luarocks-1.0.1-blue.svg" style="max-width:100%;"></a>
14-
[![Lua CI](https://github.com/syarul/luax/actions/workflows/lua.yml/badge.svg)](https://github.com/syarul/luax/actions/workflows/lua.yml)
15-
16-
### Usage
17-
18-
```lua
19-
local h = require('h')
20-
21-
local el = div(
22-
{ class = "container" },
23-
p({ class = "title" }, "Hello, world!"),
24-
span({ style = "color: red;" }, "This is a span")
25-
)
26-
27-
print(h(el))
28-
```
29-
30-
You'll get,
31-
32-
```html
33-
<div class="container"><p class="title">Hello, world!</p><span style="color: red;">This is a span</span></div>
34-
```
35-
36-
### Usage with JSX like syntax (HTML inside Lua)
37-
38-
first create a `*.luax` file, then import the `LuaX` pragma `h`
39-
40-
```lua
41-
-- el.luax
42-
local class = "container"
43-
local el = <div id="hello" class={class}>Hello, world!</div>
44-
return el
45-
```
46-
47-
import it on to the main
48-
```lua
49-
local h = require('luax')
50-
51-
local el = require('el')
52-
53-
print(h(el))
54-
```
55-
56-
You'll get,
57-
58-
```html
59-
<div class="container" id="hello">Hello, world!</div>
60-
```
61-
62-
Sample usage with list/table structure
63-
64-
```lua
65-
local function map(a, fcn)
66-
local b = {}
67-
for _, v in ipairs(a) do
68-
table.insert(b, fcn(v))
69-
end
70-
return b
71-
end
72-
73-
local filters = {
74-
{ url = "#/", name = "All", selected = true },
75-
{ url = "#/active", name = "Active", selected = false },
76-
{ url = "#/completed", name = "Completed", selected = false },
77-
}
78-
79-
local content = table.concat(map(filters, function(filter)
80-
return h(<li>
81-
<a
82-
class={filter.selected and 'selected' or nil}
83-
href={filter.url}
84-
_="on click add .selected to me"
85-
>
86-
{filter.name}
87-
</a>
88-
</li>)
89-
end), '\n')
90-
91-
return <ul class="filters" _="on load set $filter to me">
92-
{content}
93-
</ul>
94-
```
95-
96-
See the test folder to see more usage cases.
97-
98-
> Inspired by https://bvisness.me/luax/.
99-
]],
10+
detailed = "LuaX is Lua + XML Syntax extension with builtin decent parse. In retrospect it's akin to React JSX.",
10011
homepage = "https://github.com/syarul/luax",
10112
license = "MIT"
10213
}

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
## LuaX
2-
Decent parse for HTML, so you don't have to write as concatenates string, in short a React JSX implementation in LUA.
32

4-
<a href="https://luarocks.org/modules/syarul/luax" rel="nofollow"><img alt="Luarocks Package" src="https://img.shields.io/badge/Luarocks-1.0.1-blue.svg" style="max-width:100%;"></a>
3+
LuaX is Lua + XML Syntax extension with builtin decent parse. In retrospect it's akin to React JSX.
4+
5+
6+
<a href="https://luarocks.org/modules/syarul/luax" rel="nofollow"><img alt="Luarocks Package" src="https://img.shields.io/badge/Luarocks-1.0.2-blue.svg" style="max-width:100%;"></a>
57
[![Lua CI](https://github.com/syarul/luax/actions/workflows/lua.yml/badge.svg)](https://github.com/syarul/luax/actions/workflows/lua.yml)
68

9+
## Decent Parser
10+
Initial inspiration comes from [https://bvisness.me/luax/](https://bvisness.me/luax/). The reason is to make it simpler with support of Lua `metaprogramming` where node `tags` is handle automatically without defining it.
11+
712
### Usage
813

914
Install with `Luarocks`
1015

1116
`luarocks install luax`
1217

13-
load the `LuaX` `h` pragma **only** with
18+
If you only need the pragma without handling transpiling lua files, load the `LuaX` `h` pragma **only** with
1419
```lua
1520
local h = require('h')
1621

@@ -32,7 +37,7 @@ return <div style={attr.stlye}>hello from LuaX!</div>
3237

3338
import it on to the main
3439
```lua
35-
-- import luax to handle the parsing of *.luax file
40+
-- import luax transpiler to handle the parsing of *.luax file
3641
local h = require('luax')
3742

3843
local el = require('el')
@@ -46,7 +51,7 @@ You'll get,
4651
<div style="color: red;">Hello from LuaX!</div>
4752
```
4853

49-
Sample usage with list/table structure
54+
Sample usage with table structure
5055

5156
```lua
5257
local function map(a, fcn)
@@ -81,5 +86,3 @@ return <ul class="filters" _="on load set $filter to me">
8186
```
8287

8388
See the test folder to see more usage cases.
84-
85-
> Inspired by https://bvisness.me/luax/.

h.lua

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
-- inspired by https://bvisness.me/luax/
2-
-- a React createElement/hyperscript shallow implementation in LUA
3-
-- usage
4-
-- local myElement = div(
5-
-- { class = "container" },
6-
-- p({ class = "title" }, "Hello, world!"),
7-
-- span({ style = "color: red;" }, "This is a span")
8-
-- )
9-
10-
-- print(h(myElement))
11-
12-
function printTable(t, indent)
13-
indent = indent or 0
14-
local tab = string.rep(" ", indent)
15-
16-
for key, value in pairs(t) do
17-
if type(value) == "table" then
18-
print(tab .. tostring(key) .. ": ")
19-
printTable(value, indent + 1)
20-
else
21-
print(tab .. tostring(key) .. ": " .. tostring(value))
22-
end
23-
end
24-
end
25-
261
local voidTags = {
272
"area", "base", "basefont", "br", "col",
283
"frame", "hr", "img", "input", "link",

0 commit comments

Comments
 (0)