
Sputnik
A Wiki in Lua
Yuri Takhteyev & Jim Whitehead II
July 14, 2008



$ bash kepler-install-1.1-1 --prefix=$SPUTNIK

#! /bin/bash /home/yuri/sputnik/bin/wsapi.cgi
require('sputnik')
local my_sputnik = sputnik.new{
-- set a bunch of parameters
}
return function(wsapi_env)
return my_sputnik.run(wsapi_env)
end

#! /bin/bash /home/yuri/sputnik/bin/wsapi.cgi
require('sputnik')
return sputnik.new_wsapi_run_fn{
-- set a bunch of parameters
}

local request = wsapi.request.new(wsapi_env)
request = self:translate_request(request)
local node = self:get_node(request.node_id)
local action_fn = self:get_action_fn(node, request.command)
local content, content_type = action_fn(node, request, self)
local response = wsapi.response.new()
response.headers["Content-Type"] = content_type or "text/html"
response:write(content)
return response:finish()

$ ./bin/luarocks --from=$URL install sputnik
$ ./bin/luarocks install wsapi-fcgi
$ ./bin/luarocks --from=$URL1 install sputnik-tickets
$ ./bin/luarocks --from=$URL2 install your-plugin



(See http://sputnik.freewisdom.org/en/Versium)


$do_messages[[<p class="$class">$message</p>]]
<div class='content'>$content</div>
{
do_messages = node.messages,
content = node.inner_html,
}

<p class="notice">Successfully created your new account.\</p>
<div class='content'>\</div>
(See http://cosmo.luaforge.net)

$if_logged_in[[ _(HI_USER) (<a $logout_link>_(LOGOUT)</a>) ]]
HI_USER = {
en_US = "Hi, $user!",
ru = "Превед, $user!",
pt_BR = "Oi, $user!",
}

INTERFACE_LANGUAGE = "ru"
Превед, Медвед!









Creating a database schema for API documentation is relatively straightforward, but difficult to extend.



arguments = {
[1] = {
name = "unit",
desc = "The unit to query",
type = "unitId",
},
}
categories = "unit, stats"
description = "Returns the current mana points of the given unit"
returns = {
[1] = {
desc = "The unit's current mana points",
name = "mana",
type = "number",
},
}
signature = [[mana = UnitMana("unit")]]








fields= [[
reported_by = {.11}
priority = {.12}
component = {.13}
assigned_to = {.14}
status = {.15}
resolution = {.16}
]]

NODE.edit_ui= [[
reported_by = {1.31, "text_field"}
assigned_to = {1.32, "text_field"}
status = {1.33, "select",
options = {"open", "someday", ... }}
resolution = {1.35, "select",
options = {"n.a.", "fixed", "wontfix"}}
priority = {2.10, "select",
options = {"unassigned", "high", ... }}
page_name = null
]]

actions= [[show = "tickets.show"]]
translations = "tickets/translations"
templates = "tickets/templates"

<table width="100%">
<tr style="background:$status_color">
<td width="15%" style="text-align: right;">
<span style="font-size: 80%">ticket id</span><br/>
<span style="font-size: 200%;">$ticket_id</span>
</td>
<td width="15%" style="text-align: right;">
<span style="font-size: 80%">status</span><br/>
<span style="font-size: 200%">$status</span>
...

$status_color
$ticket_id
$status

actions.show = function(node, request, sputnik)
local parent_id = node.id:match(PARENT_PATTERN)
local index_node = sputnik:get_node(parent_id)
local ticket_info = {
status = node.status
status_color = status_to_color[node.status] or "white",
ticket_id = node.id:gsub(parent_id.."/", ""),
...
}
...
node.inner_html = cosmo.fill(node.templates.SHOW, ticket_info)
return node.wrappers.default(node, request, sputnik)
end

http://sputnik.freewisdom.org/en/Lua_Workshop_2008.slides