-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: [ "master", "main" ] | ||
pull_request: | ||
branches: [ "master", "main" ] | ||
workflow_call: # enable calling this workflow inside other (such as the deploy one) | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
LUA_ROCKS_API_KEY: ${{ secrets.LUA_ROCKS_API_KEY }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build the Docker test image | ||
run: docker compose build test | ||
- name: Run tests | ||
run: docker compose run --rm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: deploy | ||
|
||
# How to fire this workflow | ||
## After you are ready to deploy your rock, you need create a git tag in the format vX.Y.Z | ||
## git tag vX.Y.Z && git push --tags | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*-*' | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yml | ||
deploy: | ||
name: Deploy rock to luarocks.org | ||
env: | ||
LUA_ROCKS_API_KEY: ${{ secrets.LUA_ROCKS_API_KEY }} | ||
needs: [ build ] # build must pass to deploy | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build the Docker luarocks upload image | ||
run: docker compose build upload | ||
- name: Deploy to luarocks.org | ||
run: docker compose run --rm upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.PHONY: clean run1 run2 | ||
.PHONY: clean all run1 run2 | ||
|
||
all: run1 run2 | ||
|
||
run1: | ||
lua test.lua | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: '3.9' | ||
|
||
services: | ||
test: | ||
command: bash -c "luarocks make && busted --shuffle" | ||
build: | ||
context: . | ||
dockerfile: test.Dockerfile | ||
volumes: | ||
- ".:/lua/" | ||
working_dir: "/lua" | ||
|
||
lint: | ||
command: luacheck -q . | ||
build: | ||
context: . | ||
dockerfile: test.Dockerfile | ||
volumes: | ||
- ".:/lua/" | ||
working_dir: "/lua" | ||
|
||
upload: | ||
environment: | ||
- LUA_ROCKS_API_KEY | ||
#the command doesn't work without the bash -c, even being a single command | ||
command: bash -c "luarocks upload xml2lua-*.rockspec --force --api-key=$LUA_ROCKS_API_KEY" | ||
build: | ||
context: . | ||
dockerfile: test.Dockerfile | ||
volumes: | ||
- ".:/lua/" | ||
working_dir: "/lua" | ||
depends_on: | ||
- test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package = "luaxml" | ||
version = "1.0-0" | ||
source = { | ||
url = "git://github.com/Crazyokd/luaxml", | ||
tag = "v1.0-0" | ||
} | ||
description = { | ||
summary = "Expressing xml with lua", | ||
detailed = [[ | ||
lua <=> xml with order. | ||
]], | ||
homepage = "https://github.com/Crazyokd/luaxml", | ||
license = "MIT" | ||
} | ||
dependencies = { | ||
"lua >= 5.1, <= 5.4" | ||
} | ||
build = { | ||
type = "builtin", | ||
modules = { | ||
luaxml = "luaxml.lua", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local function print_r(root) | ||
local cache = { [root] = "." } | ||
|
||
local function _dump(t, space, name) | ||
local temp = {} | ||
for k, v in pairs(t) do | ||
local key = tostring(k) | ||
if cache[v] then | ||
table.insert(temp, "+" .. key .. " {" .. cache[v] .. "}") | ||
elseif type(v) == "table" then | ||
local new_key = name .. "." .. key | ||
cache[v] = new_key | ||
table.insert(temp, | ||
"+" .. key .. _dump(v, space .. (next(t, k) and "|" or " ") .. string.rep(" ", #key), new_key)) | ||
else | ||
table.insert(temp, "+" .. key .. " [" .. tostring(v) .. "]") | ||
end | ||
end | ||
return table.concat(temp, "\n" .. space) | ||
end | ||
|
||
print(_dump(root, "", "")) | ||
end | ||
|
||
local f = assert(io.open("test.xml", "r")) | ||
local xml = f:read("a") | ||
f:close() | ||
|
||
local lxml = require "luaxml" | ||
local lx1 = lxml.new() | ||
|
||
lx1:load(xml) | ||
-- print_r(lx1.xt) | ||
print(lx1) | ||
lx1:save('test2.xml') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
local function print_r(root) | ||
local cache = { [root] = "." } | ||
|
||
local function _dump(t, space, name) | ||
local temp = {} | ||
for k, v in pairs(t) do | ||
local key = tostring(k) | ||
if cache[v] then | ||
table.insert(temp, "+" .. key .. " {" .. cache[v] .. "}") | ||
elseif type(v) == "table" then | ||
local new_key = name .. "." .. key | ||
cache[v] = new_key | ||
table.insert(temp, | ||
"+" .. key .. _dump(v, space .. (next(t, k) and "|" or " ") .. string.rep(" ", #key), new_key)) | ||
else | ||
table.insert(temp, "+" .. key .. " [" .. tostring(v) .. "]") | ||
end | ||
end | ||
return table.concat(temp, "\n" .. space) | ||
end | ||
|
||
print(_dump(root, "", "")) | ||
end | ||
|
||
|
||
local luaxml = require "luaxml" | ||
|
||
local lx1 = luaxml.new() | ||
lx1.xt = { | ||
["@meta"] = {}, | ||
["root@1"] = { | ||
["key1@1"] = { | ||
["@val"] = "value1", | ||
["@next"] = "key2@1", | ||
}, | ||
["key2@1"] = { | ||
["@val"] = 123, | ||
["@attr"] = { type = "string" }, | ||
["@next"] = "key3@1", | ||
}, | ||
["key3@1"] = { | ||
["@val"] = 31, | ||
["@next"] = "key3@2", | ||
}, | ||
["key3@2"] = { | ||
["@val"] = 32, | ||
["@next"] = "key4@1", | ||
}, | ||
["key4@1"] = { | ||
["key41@1"] = { | ||
["@val"] = 123, | ||
["@next"] = "key42@1" | ||
}, | ||
["key42@1"] = { | ||
["@val"] = 123, | ||
}, | ||
["@head"] = "key41@1", | ||
["@attr"] = { type = "map" }, | ||
}, | ||
["@head"] = "key1@1", | ||
}, | ||
["@head"] = "root@1", | ||
} | ||
|
||
|
||
print(lx1) | ||
|
||
print(assert(lx1:get("/root/key1") == "value1")) | ||
lx1:set("/root/key1", 456) | ||
print(assert(lx1:get("/root/key1") == 456)) | ||
|
||
|
||
print(lx1:get("/root/key3[1]")) -- 31 | ||
lx1["/root/key3[1]"] = 789 | ||
print(lx1:get("/root/key3[1]")) -- 789 | ||
print(lx1:get("/root/key5")) -- nil | ||
|
||
-- lx1:set("/root/key3[3]", 1024) | ||
lx1["/root/key3[3]"] = 1024 | ||
|
||
-- iterate attrs | ||
assert(lx1["/root/key4/@type"] == "map") | ||
local key4attrs = lx1:get_attrs("/root/key4") | ||
for k, v in pairs(key4attrs) do | ||
print(k, v) | ||
end | ||
|
||
print(lx1) | ||
|
||
print(lx1["/root/key1"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM nickblah/lua:5.4.6-luarocks-ubuntu | ||
|
||
RUN apt-get update -qq > /dev/null \ | ||
&& apt-get install build-essential git zip -qq > /dev/null \ | ||
&& luarocks install dkjson > /dev/null \ | ||
&& luarocks install luacheck > /dev/null \ | ||
&& luarocks install luacov > /dev/null \ | ||
&& luarocks install luacov-coveralls > /dev/null \ | ||
&& luarocks install busted > /dev/null | ||
|
||
CMD ["busted"] |