view src/lib/Shared.luan @ 12:ad1604c72156

fix bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Jul 2022 22:01:23 -0600
parents 0472897e790d
children 24668255cede
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Http = require "luan:http/Http.luan"
local Io = require "luan:Io.luan"
local uri = Io.uri or error()
local Parsers = require "luan:Parsers.luan"
local json_parse = Parsers.json_parse or error()
local Forum = require "site:/lib/Forum.luan"
local forum_title = Forum.title or error()
local mailer_url = Forum.mailer_url or error()
local User = require "site:/lib/User.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "Shared"


local Shared = {}

function Shared.head()
%>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<style>
			@import "/site.css";
		</style>
		<script src="/site.js"></script>
<%
end

function Shared.header()
	local user = User.current()
%>
		<p style="text-align:center">Yes the aesthetics suck.  Will be fixed later.</p>
		<div header>
			<a href="/"><%=forum_title%></a>
<%	if user == nil then %>
			<a href="/login.html">login</a>
<%	else %>
			<a href="/account.html"><%=user.name_html%></a>
<%	end %>
		</div>
<%
end

function Shared.footer()
%>
		<div footer>
			<a href="/config.html">Configuration</a>
		</div>
<%
end

function Shared.admin_header()
%>
		<div header>
			<a href="/private/admin.html">Admin</a>
		</div>
<%
end

function Shared.base_url()
	return Http.request.scheme.."://"..Http.request.headers["host"]
end

function Shared.call_mail_api(cmd,parameters)
	local url = mailer_url.."/api/"..cmd..".json"
	local options = {
		parameters = parameters
	}
	local response = uri(url,options).read_text()
	return json_parse(response)
end

return Shared