RGL Browser

(added files which didn't add in previous patch)
This commit is contained in:
john.j.camilleri
2012-05-11 12:00:52 +00:00
parent 94f99118ad
commit 99c7579e85
7 changed files with 1783 additions and 0 deletions

13
lib/doc/browse/Makefile Normal file
View File

@@ -0,0 +1,13 @@
##
# Makefile for GF RGL Browser
# John J. Camilleri, 2012
##
dir=../../src
all:
./build-tags.sh
clean:
find -name '*.gf-tags' | xargs rm
cd $(dir) ; find -name '*.gfo' | xargs rm
cd $(dir) ; find -name '*.gf-tags' | xargs rm

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 B

View File

@@ -0,0 +1,38 @@
#!/bin/sh
##
# Script for building tags files for all RGL
# John J. Camilleri, 2012
##
dir=`pwd`
basedir=${dir}/../../src
tagsdir=${dir}/tags
index=${dir}/index.json
removeprefix="/home/john/repositories/GF"
# Iterate and build all the tags (takes some time)
rm -f $index
echo "{\n\"languages\": {" >> $index
for dir in `ls "$basedir/"`
do
if [ -d "$basedir/$dir" ]; then
cd $basedir/$dir
echo "Processing folder:" `pwd`
echo " \"${dir}\": [" >> $index
find -maxdepth 1 -name '*.gf' | while read -r file
do
gf --batch --quiet --tags --output-dir=${tagsdir} $file 2>/dev/null
echo " \""`echo $file | sed 's|./||;s|.gf||'`"\"," >> $index
done
echo " \"\"\n ]," >> $index
fi
done
echo " \"\":{}\n}\n}" >> $index
# Replace all URLs
echo "Replacing URLs"
cd $tagsdir
sed -i "s|${removeprefix}||g" *.gf-tags
exit 0

57
lib/doc/browse/index.html Normal file
View File

@@ -0,0 +1,57 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>GF RGL Browser</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="http://www.grammaticalframework.org/css/style.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>GF RGL Browser</h1>
<p style="font-style:italic;margin-top:-0.5em;">Updated 2012-05-11. <a href="#footer">About this tool</a></p>
</header>
<div role="main">
<div class="pane left">
<div id="languages"></div>
<div id="modules"></div>
</div>
<div class="pane right">
<div id="tabbar">
<h2></h2>
<div id="loading">
<img src="ajax-loader.gif" /> loading...
</div>
</div>
<div id="scope" class="panel scope">
<input type="text" id="search" />
<input type="checkbox" id="case_sensitive" checked="checked" />
<label for="case_sensitive">Case sensitive?</label>
<dl></dl>
</div>
<div id="code" class="panel code"></div>
</div>
<br style="clear:both">
</div>
<footer id="footer">
<h3>About the GF RGL Browser</h3>
<p>A basic tool for looking up module scopes and quickly looking at module sources, created out of necessity. It is experimental and has only been tested on the latest Chrome under Ubuntu. Even then, the page sometimes crashes and has to be closed. All feedback welcome.<br/>
To do:</p>
<ul>
<li>Test from other browsers</li>
<li>Stop from crashing occasionally</li>
<li>Line numbers and syntax highlighting for source code would be cool</li>
</ul>
<p><em>John J. Camilleri, 2012</em></p>
</footer>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>

1377
lib/doc/browse/index.json Normal file

File diff suppressed because it is too large Load Diff

184
lib/doc/browse/script.js Normal file
View File

@@ -0,0 +1,184 @@
/*
GF RGL Browser
John J. Camiller, 2012
*/
$(document).ready(function() {
// var urlPrefix = "/GF"; // local
var urlPrefix = ""; // live
var scrollToTop = function(){
$("html, body").animate({ scrollTop: 0 }, "slow");
}
var current_language = undefined;
var index;
$.getJSON("index.json", function(data){
index = data;
// Initialize the language list
var lang_select = $("<select>")
.attr('id', 'language_select')
.change(function(){
setLanguage($(this).val());
})
.appendTo("#languages")
var language_list = data['languages'];
for (i in language_list) {
if (!i) continue;
var lang = i;
$('<option>')
.html(lang)
.appendTo(lang_select);
}
setLanguage("english");
$("#loading").hide();
});
var setLanguage = function(lang){
current_language = lang;
$("#languages select").val(lang);
initModules(lang);
}
// Initialize the module list
var initModules = function(lang){
index['languages'][lang] = index['languages'][lang].sort();
$("#modules").html("");
for (i in index['languages'][lang]) {
var module = index['languages'][lang][i];
if (!module) continue;
$('<span>')
.html(module)
.addClass('button')
.click((function(lang, module){
return function() {
loadFile(lang, module);
}
})(lang, module))
.appendTo("#modules");
}
};
// Initialize the panels & tabs
var showPanel = function(obj){
$(".panel").hide();
$(obj).show(); // obj can be just a plain selector or a jQuery object
}
$(".panel").each(function(a,b){
$("<span>")
.addClass('tab').addClass($(b).attr('id'))
.html($(b).attr('id'))
.click(function(){
showPanel(b);
})
// .appendTo("#tabbar");
.insertBefore("#loading");
});
showPanel(".panel:first");
var setTitle = function(s){
$('#tabbar h2').html(s);
}
var loadFile = function(lang, module){
setTitle(lang+"/"+module);
loadTagsFile(module);
loadSourceFile(lang, module)
}
// Load a tags file
var loadTagsFile = function(module) {
$('#search').val("");
$('#scope dl').html("");
$("#loading").show();
$.ajax({
url: "tags/"+module+".gf-tags",
type: "GET",
success: function(data){
var data = data.replace(/^(\S+)\s+(.+)$/gm, '<dt name="$1">$1</dt><dd name="$1">$2</dd>');
data = data.replace(/\s(\/lib\/\S+?\.gf(-tags)?)/gm, '<a href="$1">$1</a>');
$('#scope dl').html(data);
$('#scope dl a').click(function(){
var href = $(this).attr('href');
var m = href.match(/([^\/]+)\/([^\/]+)\.(gf(-tags)?)$/);
if (m[3]=="gf") {
// Load both tags and source
loadFile(m[1], m[2]);
} else if (m[3]=="gf-tags") {
// Try and determine the language from the contents
checkSourceFile({
lang: current_language,
module: m[2],
onsuccess: function(){
loadFile(current_language, m[2]);
},
onerror: function(){
// Load just tags (we don't know source)
setTitle(m[2]+" (scope only)");
$('#code').html("");
loadTagsFile(m[2]);
}
});
}
scrollToTop();
return false;
});
$("#loading").hide();
},
error: function(data){
$('#scope dl').html("<em>No scope available</em>");
$("#loading").hide();
},
});
}
var checkSourceFile = function(args) {
$.ajax({
url: urlPrefix + "/lib/src/"+args.lang+"/"+args.module+".gf",
type: "HEAD",
success: args.onsuccess,
error: args.onerror
});
}
// Load a source module
var loadSourceFile = function(lang, module) {
$('#code').html("");
$("#loading").show();
$.ajax({
url: urlPrefix + "/lib/src/"+lang+"/"+module+".gf",
type: "GET",
success: function(data){
$('#code').html(data);
$("#loading").hide();
},
error: function(data){
$('#code').html("<em>No code available</em>");
$("#loading").hide();
}
});
}
// Custom selector
$.expr[':'].match = function(a,b,c) {
var needle = c[3];
var haystack = $(a).attr('name');
if (haystack == undefined)
return false;
if ($("#case_sensitive").is(":checked"))
return haystack.indexOf(needle)>=0;
else
return haystack.toLowerCase().indexOf(needle.toLowerCase())>=0;
};
var runfilter = function() {
// Hide anything which doesn't match
var s = $("#search").val();
$("#scope dl *").show();
if (s)
$("#scope dl *:not(:match(\""+s+"\"))").hide();
}
$("#search").keyup(runfilter);
$("#case_sensitive").change(runfilter);
});

114
lib/doc/browse/style.css Normal file
View File

@@ -0,0 +1,114 @@
/*
GF RGL Browser
John J. Camiller, 2012
*/
header h1
{
text-align:left;
}
div[role='main']
{
overflow:hidden;
width:100%;
}
.pane
{
display:block;
}
.pane.left
{
width:150px;
float:left;
}
.pane.right
{
margin-left:170px;
}
.button
{
cursor:pointer;
color:#00e;
padding:1px;
}
.button:hover
{
text-decoration:underline;
}
#languages
{
margin:0.5em 0;
}
#modules span
{
display:block;
margin:0.1em;
}
#tabbar *
{
display:inline-block;
}
#tabbar h2
{
margin: 0 1em;
font-size: 1em;
border:0;
}
.tab
{
cursor:pointer;
padding:0.5em;
margin-right:0.5em;
display:inline-block;
text-transform:capitalize;
}
#loading
{
display:inline-block;
color:#666;
}
.scope
{
background:#fff;
color:#333;
}
.code
{
background:#444;
color:#eee;
}
input#search
{
font-size:1em;
font-family:monospace;
width:25em;
padding:0.25em;
background:#eee;
}
#scope
{
padding: 1em;
}
#scope dl
{
font-family:monospace;
}
#scope dl a
{
}
#code
{
font-family:monospace;
white-space:pre;
padding: 1em;
}
dt
{
font-weight:bold;
}
footer
{
padding: 0.5em;
border-top: 1px solid #999;
margin-top: 2em;
color:#333;
}