forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The wild.sh script generates a FILES.html index for every project, which links to osh-to-oil.html#<source name>. That page has a bit of JavaScript to fetch the original source, oil source, and AST and show them in iframes.
- Loading branch information
Andy Chu
committed
Feb 3, 2017
1 parent
9b4e2f2
commit 722e018
Showing
4 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* For the FILES.html index */ | ||
|
||
thead { | ||
font-weight: bold; | ||
/*text-align: center;*/ | ||
} | ||
|
||
table { | ||
padding: 10px; /* Padding makes it look nicer. */ | ||
margin: 0 auto; /* center table on the page */ | ||
border-collapse: collapse; /* this is like old cellpadding */ | ||
} | ||
|
||
/* like cellspacing? */ | ||
td { | ||
padding: 5px; | ||
} | ||
|
||
h2 { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<html> | ||
|
||
<!-- | ||
TODO: Would be nice to either: | ||
- scroll iframes together | ||
- The conversion of osh to oil is line-for-line (but the AST isn't.) | ||
- maybe scroll 2 of them together, and provide a textbox for the others | ||
- provide a line number text box | ||
- provide a search textbox | ||
- API to scroll to text position? | ||
- fragment params: | ||
- line to highlight? | ||
- could even be the filename to load. then you don't have to generate so | ||
much code. | ||
--> | ||
|
||
<head> | ||
<script type="text/javascript" src="osh-to-oil.js"></script> | ||
<style> | ||
iframe { | ||
width: 700px; | ||
height: 700px; | ||
} | ||
/* For AJAX errors */ | ||
#status { | ||
text-align: center; | ||
font-size: x-large; | ||
color: darkred; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body onload="onLoad(location.hash, globals, kStatusElem);" | ||
onhashchange="onHashChange(location.hash, globals, kStatusElem);"> | ||
|
||
<p>Back to <a href="FILES.html">file list</a></p> | ||
|
||
<p id="status"></p> | ||
|
||
<h2 id="title"></h2> | ||
|
||
<!-- | ||
TODO: provide direct links too | ||
<p> | ||
Original Source: <a href="acpid.txt">acpid.txt</a><br/> | ||
AST in <a href="acpid-AST.html">HTML</a>, <a href="acpid-AST.txt">text</a><br/> | ||
<a href="acpid.oil">Auto-conversion to Oil</a><br/> | ||
</p> | ||
--< | ||
<p> | ||
<i>(Widen your browser until osh and oil code appears side by side)</i> | ||
</p> | ||
<!-- src filled in from URL hash --> | ||
<iframe id="orig" src=""></iframe> | ||
<iframe id="oil" src=""></iframe> | ||
<iframe id="ast" src=""></iframe> | ||
|
||
<!-- page globals --> | ||
<script type="text/javascript"> | ||
var globals = {}; // currently unused | ||
var kStatusElem = document.getElementById('status'); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// For osh-to-oil.html. | ||
|
||
'use strict'; | ||
|
||
// Append a message to an element. Used for errors. | ||
function appendMessage(elem, msg) { | ||
elem.innerHTML += msg + '<br />'; | ||
} | ||
|
||
// jQuery-like AJAX helper, but simpler. | ||
|
||
// Requires an element with id "status" to show errors. | ||
// | ||
// Args: | ||
// errElem: optional element to append error messages to. If null, then | ||
// alert() on error. | ||
// success: callback that is passed the xhr object. | ||
function ajaxGet(url, errElem, success) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url, true /*async*/); | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState != 4 /*DONE*/) { | ||
return; | ||
} | ||
|
||
if (xhr.status != 200) { | ||
var msg = 'ERROR requesting ' + url + ': ' + xhr.status + ' ' + | ||
xhr.statusText; | ||
if (errElem) { | ||
appendMessage(errElem, msg); | ||
} else { | ||
alert(msg); | ||
} | ||
return; | ||
} | ||
|
||
success(xhr); | ||
}; | ||
xhr.send(); | ||
} | ||
|
||
// Fill in title and iframe src attributes. | ||
function loadSource(sourceName, statusElem) { | ||
var sourceElem = document.getElementById('sourceFrames'); | ||
|
||
document.getElementById('title').innerHTML = sourceName; | ||
|
||
document.getElementById('orig').src = sourceName + '.txt'; | ||
document.getElementById('oil').src = sourceName + '.oil'; | ||
document.getElementById('ast').src = sourceName + '-AST.html'; | ||
appendMessage(statusElem, "Loaded contents for " + sourceName); | ||
} | ||
|
||
function getNameFromHash(urlHash, statusElem) { | ||
var h = urlHash.substring(1); // without leading # | ||
if (h.length < 1) { | ||
appendMessage(statusElem, "Invalid URL hash: [" + urlHash + "]"); | ||
return null; | ||
} | ||
return h; | ||
} | ||
|
||
function onLoad(urlHash, globals, statusElem) { | ||
onHashChange(urlHash, globals, statusElem); | ||
} | ||
|
||
// This is the onhashchange handler. | ||
function onHashChange(urlHash, globals, statusElem) { | ||
var sourceName = getNameFromHash(urlHash, statusElem); | ||
if (sourceName === null) return; | ||
|
||
loadSource(sourceName, statusElem) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters