-
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
4 changed files
with
310 additions
and
49 deletions.
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
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,16 @@ | ||
local xml_gen = require("xml-generator") | ||
local xml = xml_gen.xml | ||
|
||
local my_node = xml.div {id="my-div"} { | ||
xml.p {id="p-1"} "Hello World"; | ||
xml.p {id="p-2"} "Hello World"; | ||
xml.p {id="p-3"} "Hello World"; | ||
} | ||
|
||
print(my_node.tag, my_node.attributes.id) | ||
|
||
for i, child in ipairs(my_node.children) do | ||
print(i, child.tag, child.attributes.id) | ||
end | ||
|
||
-- print(my_node) |
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,31 @@ | ||
local xml_gen = require("xml-generator") | ||
local xml = xml_gen.xml | ||
|
||
math.randomseed(os.time()) | ||
|
||
local random_number = xml_gen.component(function(args, children) | ||
local min = args.min or 0 | ||
local max = args.max or 100 | ||
--remove these from the args so they dont show up in our HTML attributes later | ||
args.min = nil | ||
args.max = nil | ||
|
||
coroutine.yield(xml.p"This is a valid coroutine too!") | ||
|
||
return xml.span(args) { | ||
math.random(min, max), | ||
children --children is a table of all the children passed to the component, this may be empty | ||
} | ||
end) | ||
|
||
local doc = xml.html { | ||
xml.body { | ||
random_number {min = 0, max = 100}; | ||
random_number {max=10} { | ||
xml.p "This is inside the span!" | ||
}; | ||
random_number; | ||
} | ||
} | ||
|
||
print(doc) |
Oops, something went wrong.