Empezar
This commit is contained in:
commit
05d6865aec
58
Menú artístico.0.2.lua
Executable file
58
Menú artístico.0.2.lua
Executable file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env lua5.1
|
||||||
|
local m = 1
|
||||||
|
local f = 2
|
||||||
|
|
||||||
|
local tipos = {
|
||||||
|
{"Un collage", m},
|
||||||
|
{"Una intervención contrapublicitaria o contrapropaganda", f},
|
||||||
|
{"Una cerámica", f},
|
||||||
|
{"Un comic", m},
|
||||||
|
}
|
||||||
|
|
||||||
|
local temas = {
|
||||||
|
"destrucción ambiental",
|
||||||
|
"una canción",
|
||||||
|
"otra obra artística",
|
||||||
|
"el mercado inmobiliario",
|
||||||
|
"redes sociales",
|
||||||
|
}
|
||||||
|
|
||||||
|
local adjetivos = {
|
||||||
|
{"", ""},
|
||||||
|
{"feo", "fea"},
|
||||||
|
}
|
||||||
|
|
||||||
|
local random_i = 1
|
||||||
|
local function random(list)
|
||||||
|
math.randomseed((''..os.time()):reverse() + random_i)
|
||||||
|
random_i = random_i + 5
|
||||||
|
return list[math.random(#list)]
|
||||||
|
end
|
||||||
|
|
||||||
|
require'html'
|
||||||
|
|
||||||
|
print(render{
|
||||||
|
h2({}, {"Algunas obras generadas aleatoriamente"}),
|
||||||
|
ol({}, map({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, function(key, value)
|
||||||
|
local tipo = random(tipos)
|
||||||
|
local tema = random(temas)
|
||||||
|
local adjetivo = random(adjetivos)[tipo[2]]
|
||||||
|
return li({}, {tipo[1]," ",adjetivo," sobre ",tema})
|
||||||
|
end)),
|
||||||
|
h2({}, {"Tipos de obra"}),
|
||||||
|
ol({}, map(tipos, function(key, tipo)
|
||||||
|
return li({}, {tipo[1]})
|
||||||
|
end)),
|
||||||
|
h2({}, {"Algunas características (opcional)"}),
|
||||||
|
ol({}, map({unpack(adjetivos, 2)}, function(key, adjetivo)
|
||||||
|
return li({}, {adjetivo[1],"/",adjetivo[2]})
|
||||||
|
end)),
|
||||||
|
h2({}, {"Temas para la obra"}),
|
||||||
|
ol({}, map(temas, function(key, tema)
|
||||||
|
return li({}, {tema})
|
||||||
|
end)),
|
||||||
|
p({}, {
|
||||||
|
a({ href = "https://gitea.nulo.in/Nulo/sitio/src/branch/ANTIFASCISTA/Men%C3%BA%20art%C3%ADstico.gen" }, {"Código"}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
57
Menú artístico.lua
Executable file
57
Menú artístico.lua
Executable file
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env lua5.1
|
||||||
|
local m = 1
|
||||||
|
local f = 2
|
||||||
|
|
||||||
|
local tipos = {
|
||||||
|
{"Un collage", m},
|
||||||
|
{"Una intervención contrapublicitaria o contrapropaganda", f},
|
||||||
|
{"Una cerámica", f},
|
||||||
|
{"Un comic", m},
|
||||||
|
}
|
||||||
|
|
||||||
|
local temas = {
|
||||||
|
"destrucción ambiental",
|
||||||
|
"una canción",
|
||||||
|
"otra obra artística",
|
||||||
|
"el mercado inmobiliario",
|
||||||
|
"redes sociales",
|
||||||
|
}
|
||||||
|
|
||||||
|
local adjetivos = {
|
||||||
|
{"", ""},
|
||||||
|
{"feo", "fea"},
|
||||||
|
}
|
||||||
|
|
||||||
|
local random_i = 1
|
||||||
|
local function random(list)
|
||||||
|
math.randomseed((''..os.time()):reverse() + random_i)
|
||||||
|
random_i = random_i + 5
|
||||||
|
return list[math.random(#list)]
|
||||||
|
end
|
||||||
|
|
||||||
|
require'html'
|
||||||
|
|
||||||
|
print(render{
|
||||||
|
h2{"Algunas obras generadas aleatoriamente"},
|
||||||
|
ol(map({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, function(key, value)
|
||||||
|
local tipo = random(tipos)
|
||||||
|
local tema = random(temas)
|
||||||
|
local adjetivo = random(adjetivos)[tipo[2]]
|
||||||
|
return li{tipo[1]," ",adjetivo," sobre ",tema}
|
||||||
|
end)),
|
||||||
|
h2{"Tipos de obra"},
|
||||||
|
ol(map(tipos, function(tipo) return li{tipo[1]} end)),
|
||||||
|
h2{"Algunas características (opcional)"},
|
||||||
|
ol(map({unpack(adjetivos, 2)}, function(adjetivo)
|
||||||
|
return li{adjetivo[1],"/",adjetivo[2]}
|
||||||
|
end)),
|
||||||
|
h2{"Temas para la obra"},
|
||||||
|
ol(map(temas, function(tema) return li{tema} end)),
|
||||||
|
p{
|
||||||
|
a{
|
||||||
|
href = "https://gitea.nulo.in/Nulo/sitio/src/branch/ANTIFASCISTA/Men%C3%BA%20art%C3%ADstico.gen",
|
||||||
|
"Código"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
34
html.0.1.lua
Normal file
34
html.0.1.lua
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
local function map(list, func)
|
||||||
|
local new_list = {}
|
||||||
|
for key, value in pairs(list) do
|
||||||
|
new_list[key] = func(key, value)
|
||||||
|
end
|
||||||
|
return new_list
|
||||||
|
end
|
||||||
|
local function join(list)
|
||||||
|
local string = ""
|
||||||
|
for key, value in pairs(list) do
|
||||||
|
string = string .. value
|
||||||
|
end
|
||||||
|
return string
|
||||||
|
end
|
||||||
|
|
||||||
|
local function basic_element(name)
|
||||||
|
return function(params, children)
|
||||||
|
return "<"..name
|
||||||
|
..join(map(params, function(key, value)
|
||||||
|
return " "..key.."='"..value.."'"
|
||||||
|
end))
|
||||||
|
..">"
|
||||||
|
..join(children)
|
||||||
|
.."</"..name..">"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function a(params, children)
|
||||||
|
if not params.href then
|
||||||
|
print("WARNING: Link `"..join(children).."` doesn't have a href.")
|
||||||
|
end
|
||||||
|
return basic_element("a")(params, children)
|
||||||
|
end
|
||||||
|
print(a({ href = "https://nulo.in" }, {"Hola, soy html.lua"}))
|
83
html.0.2.lua
Normal file
83
html.0.2.lua
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
function map(list, func)
|
||||||
|
local new_list = {}
|
||||||
|
for key, value in pairs(list) do
|
||||||
|
new_list[key] = func(key, value)
|
||||||
|
end
|
||||||
|
return new_list
|
||||||
|
end
|
||||||
|
function join(list)
|
||||||
|
local string = ""
|
||||||
|
for key, value in pairs(list) do
|
||||||
|
string = string .. value
|
||||||
|
end
|
||||||
|
return string
|
||||||
|
end
|
||||||
|
|
||||||
|
function render(element)
|
||||||
|
if type(element) == "string" then
|
||||||
|
-- TODO: escape
|
||||||
|
return element
|
||||||
|
end
|
||||||
|
if element[1] then
|
||||||
|
return join(map(element, function(key, value)
|
||||||
|
return render(value)
|
||||||
|
end))
|
||||||
|
end
|
||||||
|
|
||||||
|
local close_tag = "</"..element.type..">"
|
||||||
|
local self_closing = element.type == "meta"
|
||||||
|
if self_closing then
|
||||||
|
close_tag = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
return "<"..element.type
|
||||||
|
..join(map(element.parameters, function(key, value)
|
||||||
|
-- TODO: escape
|
||||||
|
return " "..key.."='"..value.."'"
|
||||||
|
end))
|
||||||
|
..">"
|
||||||
|
..join(map(element.children, function(key, value)
|
||||||
|
return render(value)
|
||||||
|
end))
|
||||||
|
..close_tag
|
||||||
|
end
|
||||||
|
|
||||||
|
local function basic_element(name)
|
||||||
|
return function(params, children)
|
||||||
|
return { type = name, parameters = params, children = children }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function a(params, children)
|
||||||
|
if not params.href then
|
||||||
|
print("WARNING: Link `"..join(children).."` doesn't have a href.")
|
||||||
|
end
|
||||||
|
return basic_element("a")(params, children)
|
||||||
|
end
|
||||||
|
|
||||||
|
head = basic_element("head")
|
||||||
|
body = basic_element("body")
|
||||||
|
title = basic_element("title")
|
||||||
|
h1 = basic_element("h1")
|
||||||
|
h2 = basic_element("h2")
|
||||||
|
h3 = basic_element("h3")
|
||||||
|
h4 = basic_element("h4")
|
||||||
|
h5 = basic_element("h5")
|
||||||
|
h6 = basic_element("h6")
|
||||||
|
ul = basic_element("ul")
|
||||||
|
ol = basic_element("ol")
|
||||||
|
li = basic_element("li")
|
||||||
|
p = basic_element("p")
|
||||||
|
meta = basic_element("meta")
|
||||||
|
|
||||||
|
local link = a({ href = "https://nulo.in" }, {"Hola, soy html.lua"})
|
||||||
|
|
||||||
|
local head_block = head({}, {
|
||||||
|
meta({charset = "utf-8"}, {}),
|
||||||
|
title({}, {"Hello world"}),
|
||||||
|
})
|
||||||
|
local body_block = body({}, {
|
||||||
|
link
|
||||||
|
})
|
||||||
|
|
||||||
|
--print(render(head_block)..render(body_block))
|
85
html.lua
Normal file
85
html.lua
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
function _map(_pairs, list, func)
|
||||||
|
local new_list = {}
|
||||||
|
for key, value in _pairs(list) do
|
||||||
|
new_list[key] = func(value, key)
|
||||||
|
end
|
||||||
|
return new_list
|
||||||
|
end
|
||||||
|
function map(list, func) return _map(pairs, list, func) end
|
||||||
|
function imap(list, func) return _map(ipairs, list, func) end
|
||||||
|
function _join(_pairs, list)
|
||||||
|
local string = ""
|
||||||
|
for key, value in _pairs(list) do
|
||||||
|
string = string .. value
|
||||||
|
end
|
||||||
|
return string
|
||||||
|
end
|
||||||
|
function join(list) return _join(pairs, list) end
|
||||||
|
function ijoin(list) return _join(ipairs, list) end
|
||||||
|
|
||||||
|
function render(element)
|
||||||
|
if type(element) == "string" then
|
||||||
|
-- TODO: escape
|
||||||
|
return element
|
||||||
|
end
|
||||||
|
if element[1] then
|
||||||
|
return join(map(element, render))
|
||||||
|
end
|
||||||
|
|
||||||
|
local close_tag = "</"..element.type..">"
|
||||||
|
local self_closing = element.type == "meta"
|
||||||
|
if self_closing then
|
||||||
|
close_tag = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
return "<"..element.type
|
||||||
|
..join(map(element.things, function(value, key)
|
||||||
|
if type(key) == "number" then return "" end
|
||||||
|
-- TODO: escape
|
||||||
|
return " "..key.."='"..value.."'"
|
||||||
|
end))
|
||||||
|
..">"
|
||||||
|
..join(imap(element.things, render))
|
||||||
|
..close_tag
|
||||||
|
end
|
||||||
|
|
||||||
|
local function basic_element(name)
|
||||||
|
return function(things)
|
||||||
|
return { type = name, things = things }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function a(things)
|
||||||
|
if not things.href then
|
||||||
|
print("WARNING: Link `"..ijoin(things).."` doesn't have a href.")
|
||||||
|
end
|
||||||
|
return basic_element("a")(things)
|
||||||
|
end
|
||||||
|
|
||||||
|
head = basic_element("head")
|
||||||
|
body = basic_element("body")
|
||||||
|
title = basic_element("title")
|
||||||
|
h1 = basic_element("h1")
|
||||||
|
h2 = basic_element("h2")
|
||||||
|
h3 = basic_element("h3")
|
||||||
|
h4 = basic_element("h4")
|
||||||
|
h5 = basic_element("h5")
|
||||||
|
h6 = basic_element("h6")
|
||||||
|
ul = basic_element("ul")
|
||||||
|
ol = basic_element("ol")
|
||||||
|
li = basic_element("li")
|
||||||
|
p = basic_element("p")
|
||||||
|
meta = basic_element("meta")
|
||||||
|
|
||||||
|
local link = a{href = "https://nulo.in",
|
||||||
|
"Hola, soy html.lua"}
|
||||||
|
|
||||||
|
local head_block = head{
|
||||||
|
meta{charset = "utf-8"},
|
||||||
|
title{"Hello world"},
|
||||||
|
}
|
||||||
|
local body_block = body{
|
||||||
|
link,
|
||||||
|
}
|
||||||
|
|
||||||
|
print(render{head_block, body_block})
|
Loading…
Reference in a new issue