Skip to content

Commit

Permalink
Make better use of subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Jun 10, 2018
1 parent d73ed1d commit d7ec0f4
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 191 deletions.
20 changes: 10 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/

module.exports = {
get Postprocessor (){ return require("./postproc/postprocessor.js"); },
get TextGrid (){ return require("./postproc/text-grid.js"); },
get TroffCanvasRenderer (){ return require("./postproc/canvas/renderer.js"); },
get TroffCanvasViewer (){ return require("./postproc/canvas/viewer.js"); },
get TTYRenderer (){ return require("./postproc/tty/renderer.js"); },
get TTYViewer (){ return require("./postproc/tty/viewer.js"); },
get Postprocessor (){ return require("./postproc/postprocessor.js"); },
get TextGrid (){ return require("./postproc/text-grid.js"); },
get TroffCanvasRenderer (){ return require("./postproc/canvas/renderer.js"); },
get TroffCanvasViewer (){ return require("./postproc/canvas/viewer.js"); },
get TTYRenderer (){ return require("./postproc/tty/renderer.js"); },
get TTYViewer (){ return require("./postproc/tty/viewer.js"); },

get PageLoader (){ return require("./system/page-loader.js"); },
get PageReference (){ return require("./system/page-reference.js"); },
get ShellCache (){ return require("./system/shell-cache.js"); },
get TroffType (){ return require("./system/troff-type.js"); },
get ManPageLoader (){ return require("./system/man/page-loader.js"); },
get ManPageReference (){ return require("./system/man/page-reference.js"); },
get ShellCache (){ return require("./system/shell-cache.js"); },
get TroffType (){ return require("./system/troff-type.js"); },
};
30 changes: 18 additions & 12 deletions lib/system/page-loader.js → lib/system/man/page-loader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

const fs = require("fs");
const PageReference = require("./page-reference.js");
const ShellCache = require("./shell-cache.js");
const TroffType = require("./troff-type.js");
const fs = require("fs");
const ShellCache = require("../shell-cache.js");
const TroffType = require("../troff-type.js");
const ManPageReference = require("./page-reference.js");


/**
Expand All @@ -12,13 +12,12 @@ const TroffType = require("./troff-type.js");
* An instance of this class manages all interaction between the Node
* process and the system's troff(1) and man(1) binaries. Because shell
* commands are cached internally, authors are encouraged to use only
* one (shared) PageLoader instance to reduce extraneous system calls.
* one (shared) ManPageLoader instance to reduce extraneous system calls.
*
* @see {@link ShellCache}
* @property {ShellCache} - Cached system commands and file-reads
* @property {ShellCache} shell - Cached system commands and loaded files
* @class
*/
class PageLoader{
class ManPageLoader{

/**
* Initialise a new loader instance.
Expand All @@ -30,7 +29,14 @@ class PageLoader{


/**
* Load a manpage file, without doing anything to its source.
* Load a manpage file, without altering or interpreting its
* markup. Man-pages may be specified either as a name/section
* pair, or with an explicit pathname pointing to the file.
*
* Filenames which end in `.gz` are assumed to be gzipped,
* and piped through gunzip(1) before being returned. (The
* host system is assumed by default to have a gunzip(1)
* implementation available).
*
* @example <caption>Using `man -w`</caption>
* load("sync", "8");
Expand All @@ -46,8 +52,8 @@ class PageLoader{
* @param {String} [arch=""]
* @return {Promise}
* Resolves with unformatted Roff source. Its contents must
* further be transformed using {@link PageLoader.format} for
* it to resemble its intended output format.
* be transformed further using {@link ManPageLoader.format}
* if one desires another output format.
*
* @public
*/
Expand Down Expand Up @@ -81,7 +87,7 @@ class PageLoader{
* @public
*/
async locate(){
const page = new PageReference(...arguments);
const page = new ManPageReference(...arguments);
const args = [...await this.getSearchArgs(), ...page.args].filter(Boolean);
const result = await this.shell.exec("man", args);
const paths = result.stdout.trim().split(/\n+/);
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions test/fixtures/demos/canvas.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
*{
tab-size: 4;
box-sizing: border-box;
}

/* Demo styling */
body{
white-space: nowrap;
text-align: center;
background: #ccc;
font-size: 0;
margin: 0;
}
body::before{
content: "";
height: 100vh;
width: 0;
display: inline-block;
vertical-align: middle;
}

#chalkboard{
font-size: 1rem;
background: #333;
border: 5px double #000;
border-color: #aaa #ccc #fff #666;
box-shadow: 0 0 1.5em -.25em rgba(0,0,0,1);

display: inline-block;
vertical-align: middle;
white-space: normal;
position: relative;
margin: 1em;
width: calc(100% - 2em);
max-width: 640px;
height: 500px;
}
.troff-view-pages{
padding: 1em;
}
.troff-view-page{
margin-bottom: 1em;
}
29 changes: 29 additions & 0 deletions test/fixtures/demos/canvas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en-AU">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="initial-scale=1, minimum-scale=1" />
<link rel="stylesheet" type="text/css" href="../../../lib/postproc/canvas/viewer.css" />
<link rel="stylesheet" type="text/css" href="./canvas.css" />
<title>TroffCanvasViewer demo</title>
</head>


<body>

<div id="chalkboard"></div>

<script>
"use strict";

const {TroffCanvasViewer} = require("../../..");
const view = new TroffCanvasViewer({
parentElement: document.getElementById("chalkboard"),
});

// Load ditroff source from file, then render it
view.loadFile("./text/pdf-large.out");
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions test/fixtures/demos/tty.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
*{
tab-size: 4;
box-sizing: border-box;
}

html{
background: #000;
color: #fff;
}

a:link,
a:visited{
color: inherit;
text-decoration: none;
}

#notice{
background: rgba(0, 0, 0, .75);
font: 1rem sans-serif;
color: #fff;

position: fixed;
overflow: hidden;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 9;
transition: 0s step-end z-index, .3s ease-in opacity;
}
#notice[hidden]{
display: block !important;
pointer-events: none;
opacity: 0;
z-index: -1;
transition-delay: .3s, 0s;
}

#notice > strong{
cursor: pointer;
position: fixed;
display: block;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
text-shadow: 1px 1px 0 #000;
}
#notice > strong::after{
content: "(Click to dismiss this message)";
display: block;
margin-top: 1em;
}
48 changes: 48 additions & 0 deletions test/fixtures/demos/tty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en-AU">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="initial-scale=1, minimum-scale=1" />
<link rel="stylesheet" type="text/css" href="./tty.css" />
<title>TTYViewer demo</title>
</head>


<body>

<div id="frame"></div>
<div id="notice" hidden><strong></strong></div>

<script>
"use strict";

// Unrelated garnish
notice.addEventListener("click", () => {
notice.hidden = true;
});


// Demo-related
const {
ManPageLoader,
TTYViewer,
} = require("../../../lib/index.js");

const loader = new ManPageLoader();
const viewer = new TTYViewer({
parentElement: document.getElementById("frame"),
onError: (error) => {
console.error(error);
notice.hidden = false;
notice.firstChild.textContent = error;
},
});

console.dir({loader, viewer});
loader.load("groff_char")
.then(data => viewer.render(data))
.catch(err => console.error(err));
</script>
</body>
</html>
75 changes: 0 additions & 75 deletions test/fixtures/preview-canvas.html

This file was deleted.

Loading

0 comments on commit d7ec0f4

Please sign in to comment.