add api viewer

This commit is contained in:
j 2011-12-28 19:04:27 +05:30
parent 5617c23659
commit cb13217314
6 changed files with 245 additions and 1 deletions

6
README
View file

@ -16,4 +16,10 @@ b) offline annotations(something like speedtrans) with ability to sync/upload to
since there might be no dns lookup for local.pad.ma possible since there might be no dns lookup for local.pad.ma possible
after checkout make sure a version of oxjs is available at static/oxjs
i.e.
cd pandoralocal/static
bzr branch http://code.0x2620.org/oxjs
cd oxjs
./tools/build/build.py

View file

@ -189,7 +189,8 @@ class Server(Resource):
def render_GET(self, request): def render_GET(self, request):
print 'render_GET' print 'render_GET'
request.headers['Server'] = 'pandoralocal/%s' % __version__ request.headers['Server'] = 'pandoralocal/%s' % __version__
f = open('static/index.html') path = self.static_path('api.html')
f = open(path)
data = f.read() data = f.read()
f.close() f.close()
request.headers['Content-Type'] = 'text/html' request.headers['Content-Type'] = 'text/html'

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>pandoralocal API</title>
<link rel="shortcut icon" type="image/png" href="/png/icon16.png"/>
<link rel="stylesheet" type="text/css" href="/css/highlight.css"/>
<script type="text/javascript" src="/oxjs/build/Ox.js"></script>
<script type="text/javascript" src="/js/api/highlight.pack.js"></script>
<script type="text/javascript" src="/js/api/pandora.js"></script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,67 @@
pre code {
display: block;
background: #F0F0F0;
}
pre code,
.xml .title {
color: black;
}
.string,
.title,
.parent,
.tag .attribute .value,
.rules .value,
.rules .value .number,
.preprocessor,
.instancevar,
.aggregate,
.template_tag,
.django .variable,
.addition,
.flow,
.stream {
color: #800;
}
.comment,
.annotation,
.template_comment,
.diff .header,
.chunk {
color: #888;
}
.number,
.regexp,
.literal,
.change {
color: #080;
}
.decorator,
.filter .argument,
.localvars,
.array,
.attr_selector,
.pi,
.doctype,
.deletion,
.envvar,
.shebang {
color: #88F;
}
.keyword,
.id,
.title,
.aggregate {
font-weight: bold;
}
.html .css,
.html .javascript,
.html .vbscript {
opacity: 0.5;
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,155 @@
/***
Pandora API
***/
Ox.load('UI', {
hideScreen: false,
showScreen: true,
theme: 'classic'
}, function() {
var app = new Ox.App({
apiURL: '/api/',
init: 'init',
}).bindEvent('load', function(data) {
app.site = {
};
app.site.default_info = '<div class="OxSelectable"><h2>Pan.do/ra API Overview</h2>use this api in the browser with <a href="/static/oxjs/demos/doc2/index.html#Ox.App">Ox.app</a> or use <a href="http://code.0x2620.org/pandora_client">pandora_client</a> it in python. Further description of the api can be found <a href="https://wiki.0x2620.org/wiki/pandora/API">on the wiki</a></div>';
app.$body = $('body');
app.$document = $(document);
app.$window = $(window);
//app.$body.html('');
Ox.UI.hideLoadingScreen();
app.$ui = {};
app.$ui.actionList = constructList();
app.$ui.actionInfo = Ox.Container().css({padding: '16px'}).html(app.site.default_info);
app.api.api({docs: true, code: true}, function(results) {
app.actions = results.data.actions;
if(document.location.hash) {
app.$ui.actionList.triggerEvent('select', {ids: document.location.hash.substring(1).split(',')});
}
});
var $left = new Ox.SplitPanel({
elements: [
{
element: new Ox.Element().append(new Ox.Element()
.html('Pandoralocal API').css({
'padding': '4px',
})).css({
'background-color': '#ddd',
'font-weight': 'bold',
}),
size: 24
},
{
element: app.$ui.actionList
}
],
orientation: 'vertical'
});
var $main = new Ox.SplitPanel({
elements: [
{
element: $left,
size: 160
},
{
element: app.$ui.actionInfo,
}
],
orientation: 'horizontal'
});
$main.appendTo(app.$body);
});
function constructList() {
return new Ox.TextList({
columns: [
{
align: "left",
id: "name",
operator: "+",
title: "Name",
unique: true,
visible: true,
width: 140
},
],
columnsMovable: false,
columnsRemovable: false,
id: 'actionList',
items: function(data, callback) {
function _sort(a, b) {
if(a.name > b.name)
return 1;
else if(a.name == b.name)
return 0;
return -1;
}
if (!data.keys) {
app.api.api(function(results) {
var items = [];
Ox.forEach(results.data.actions, function(v, k) {
items.push({'name': k})
});
items.sort(_sort);
var result = {'data': {'items': items.length}};
callback(result);
});
} else {
app.api.api(function(results) {
var items = [];
Ox.forEach(results.data.actions, function(v, k) {
items.push({'name': k})
});
items.sort(_sort);
var result = {'data': {'items': items}};
callback(result);
});
}
},
scrollbarVisible: true,
sort: [
{
key: "name",
operator: "+"
}
]
}).bindEvent({
select: function(data) {
var info = $('<div>').addClass('OxSelectable'),
hash = '#';
if(data.ids.length) {
data.ids.forEach(function(id) {
info.append($("<h2>").html(id));
var $doc =$('<pre>')
.html(app.actions[id].doc.replace('/\n/<br>\n/g'))
.appendTo(info);
var $code = $('<code class="python">')
.html(app.actions[id].code[1].replace('/\n/<br>\n/g'))
.hide();
var f = app.actions[id].code[0];
$('<span>')
.html(' View Source ('+f+')')
.click(function() { $code.toggle();})
.appendTo(info);
$('<pre>').append($code).appendTo(info);
hljs.highlightBlock($code[0], ' ');
hash += id + ',';
});
} else {
info.html(app.site.default_info);
}
document.location.hash = hash.substring(0, hash.length-1);
app.$ui.actionInfo.html(info);
}
});
}
});