alpha p2
This commit is contained in:
240
core/builtin.lua
240
core/builtin.lua
@@ -398,242 +398,14 @@ function M:custom(str)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h1(str)
|
||||
str = str or ""
|
||||
self:custom(std.h1(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h2(str)
|
||||
str = str or ""
|
||||
self:custom(std.h2(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h3(str)
|
||||
str = str or ""
|
||||
self:custom(std.h3(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h4(str)
|
||||
str = str or ""
|
||||
self:custom(std.h4(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h5(str)
|
||||
str = str or ""
|
||||
self:custom(std.h5(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:h6(str)
|
||||
str = str or ""
|
||||
self:custom(std.h6(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:p(str)
|
||||
str = str or ""
|
||||
table.insert(self.parts, "<p>" .. str .. "</p>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:note(content)
|
||||
content = content or ""
|
||||
self:custom('<div class="note">' .. content .. '</div>')
|
||||
return self
|
||||
end
|
||||
|
||||
function M:muted(content)
|
||||
content = content or ""
|
||||
self:custom('<div class="muted quiet">' .. content .. '</div>')
|
||||
return self
|
||||
end
|
||||
|
||||
function M:a(link, str)
|
||||
link = link or "example.com"
|
||||
str = str or link
|
||||
table.insert(self.parts, "<a href=\"" .. link .. "\">" .. str .. "</a>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:ha(link, str)
|
||||
link = link or "example.com"
|
||||
str = str or link
|
||||
table.insert(self.parts, "<a class=\"hidden\" href=\"" .. link .. "\">" .. str .. "</a>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:external(link, str)
|
||||
link = link or "example.com"
|
||||
str = str or link
|
||||
table.insert(self.parts, "<a target=\"_blank\" href=\"" .. link .. "\">" .. str .. "</a>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:version()
|
||||
return self.version
|
||||
end
|
||||
|
||||
function M:ul(items)
|
||||
items = items or {}
|
||||
local html = "<ul>"
|
||||
for _, item in ipairs(items) do
|
||||
html = html .. "<li>" .. tostring(item) .. "</li>"
|
||||
end
|
||||
html = html .. "</ul>"
|
||||
self:custom(html)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:ol(items)
|
||||
items = items or {}
|
||||
local html = "<ol>"
|
||||
for _, item in ipairs(items) do
|
||||
html = html .. "<li>" .. tostring(item) .. "</li>"
|
||||
end
|
||||
html = html .. "</ol>"
|
||||
self:custom(html)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:li(str)
|
||||
str = str or ""
|
||||
self:custom("<li>" .. str .. "</li>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:code(str)
|
||||
str = str or ""
|
||||
self:custom("<pre><code>" .. str .. "</code></pre>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:blockquote(str)
|
||||
str = str or ""
|
||||
self:custom("<blockquote>" .. str .. "</blockquote>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:hr()
|
||||
self:custom("<hr>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:divider()
|
||||
self:custom('<div class="divider"></div>')
|
||||
return self
|
||||
end
|
||||
|
||||
function M:img(src, alt)
|
||||
src = src or ""
|
||||
alt = alt or ""
|
||||
self:custom('<img src="' .. src .. '" alt="' .. alt .. '">')
|
||||
return self
|
||||
end
|
||||
|
||||
function M:table(headers, rows)
|
||||
headers = headers or {}
|
||||
rows = rows or {}
|
||||
|
||||
local html = "<table><thead><tr>"
|
||||
for _, header in ipairs(headers) do
|
||||
html = html .. "<th>" .. tostring(header) .. "</th>"
|
||||
end
|
||||
html = html .. "</tr></thead><tbody>"
|
||||
|
||||
for _, row in ipairs(rows) do
|
||||
html = html .. "<tr>"
|
||||
for _, cell in ipairs(row) do
|
||||
html = html .. "<td>" .. tostring(cell) .. "</td>"
|
||||
end
|
||||
html = html .. "</tr>"
|
||||
end
|
||||
|
||||
html = html .. "</tbody></table>"
|
||||
self:custom(html)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:div(content, class)
|
||||
content = content or ""
|
||||
class = class or ""
|
||||
local class_attr = class ~= "" and (' class="' .. class .. '"') or ""
|
||||
self:custom("<div" .. class_attr .. ">" .. content .. "</div>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:span(content, class)
|
||||
content = content or ""
|
||||
class = class or ""
|
||||
local class_attr = class ~= "" and (' class="' .. class .. '"') or ""
|
||||
self:custom("<span" .. class_attr .. ">" .. content .. "</span>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:strong(str)
|
||||
str = str or ""
|
||||
self:custom("<strong>" .. str .. "</strong>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:em(str)
|
||||
str = str or ""
|
||||
self:custom("<em>" .. str .. "</em>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:br()
|
||||
self:custom("<br>")
|
||||
return self
|
||||
end
|
||||
|
||||
function M:section(content)
|
||||
content = content or ""
|
||||
self:custom('<div class="section">' .. content .. '</div>')
|
||||
return self
|
||||
end
|
||||
|
||||
function M:links(link_list)
|
||||
link_list = link_list or {}
|
||||
local html = '<div class="links">'
|
||||
for _, link_data in ipairs(link_list) do
|
||||
local link = link_data.link or link_data[1] or "#"
|
||||
local text = link_data.text or link_data[2] or link
|
||||
local external = link_data.external or false
|
||||
if external then
|
||||
html = html .. '<a target="_blank" href="' .. link .. '">' .. text .. '</a>'
|
||||
else
|
||||
html = html .. '<a href="' .. link .. '">' .. text .. '</a>'
|
||||
for name, func in pairs(std) do
|
||||
if type(func) == "function" then
|
||||
M[name] = function(self, ...)
|
||||
local result = func(...)
|
||||
table.insert(self.parts, result)
|
||||
return self
|
||||
end
|
||||
end
|
||||
html = html .. '</div>'
|
||||
self:custom(html)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:lead(str)
|
||||
str = str or ""
|
||||
self:custom(std.small(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:small(str)
|
||||
str = str or ""
|
||||
self:custom(std.small(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:highlight(str)
|
||||
str = str or ""
|
||||
self:custom(std.highlight(str))
|
||||
return self
|
||||
end
|
||||
|
||||
function M:banner(str)
|
||||
self:custom(std.banner(str))
|
||||
end
|
||||
|
||||
function M:build()
|
||||
|
||||
Reference in New Issue
Block a user