Skip to content

Commit b1682ce

Browse files
committed
removal of duplicated code
1 parent b873726 commit b1682ce

File tree

8 files changed

+155
-286
lines changed

8 files changed

+155
-286
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ in the documentation of this project are to be interpreted as described in [RFC
8282

8383
## Features
8484

85-
* PEB can be started from any folder without installation procedure.
85+
* [PEB can be started from any folder without installation procedure.](./doc/CONSTANTS.md)
8686
* [Perl script output is seamlessly inserted in a nice HTML user interface.](./doc/SETTINGS.md#perl-scripts-api)
8787
* [Event-driven interactive Perl scripts can be repeatedly fed with data.](./doc/SETTINGS.md#interactive-perl-scripts)
8888
* [Any version of Perl 5 can be used.](./doc/REQUIREMENTS.md#runtime-requirements)

doc/SETTINGS.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,33 @@ The ``pebSettings`` JavaScript object may have the following properties:
5858

5959
## Perl Scripts API
6060

61-
Every Perl script run by PEB has a JavaScript settings object with an arbitrary name and fixed object properties. The name of the JavaScript settings object with a ``.script`` extension forms settings pseudo link used to start the Perl script.
61+
Every Perl script run by PEB has a JavaScript settings object with an arbitrary name and fixed object properties. The name of the JavaScript settings object with a ``.script`` extension forms a pseudo link used to start the Perl script.
6262

6363
There are three methods to start a local Perl script:
6464

65-
* **Clicking a link to a script settings pseudo link:**
65+
* **Clicking a link to a script pseudo link:**
6666

6767
```html
6868
<a href="test.script">Start Perl script</a>
6969
```
7070

71-
* **Submitting a form to a script settings pseudo link:**
71+
* **Submitting a form to a script pseudo link:**
7272

7373
```html
7474
<form action="test.script">
7575
<input type="submit" value="Start Perl script">
7676
</form>
7777
```
7878

79-
* **Calling a JavaScript function with a script settings pseudo link:**
79+
* **Calling a JavaScript function with a script pseudo link:**
8080

8181
```javascript
8282
peb.startScript('test.script');
8383
```
8484

85-
This method creates an invisible form and submits it to the script settings pseudo link.
85+
This method creates an invisible form and submits it to the script pseudo link.
8686

87-
A minimal example of a JavaScript settings object for a Perl script run by PEB:
87+
An example of a JavaScript settings object for a Perl script run by PEB:
8888

8989
```javascript
9090
var perl_script = {};
@@ -99,7 +99,8 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
9999

100100
* **scriptRelativePath**
101101
``String`` for the relative path of a Perl script run by PEB
102-
The script relative path is converted to a full path using the ``{PEB_app_directory}`` as a root folder.
102+
The relative path of a script is converted to a full path using the
103+
``{PEB_executable_directory}/resources/app`` as a root folder.
103104
PEB does not check filename extensions or shebang lines of Perl scripts.
104105
Scripts without filename extensions can also be used.
105106
*This object property is mandatory.*
@@ -111,7 +112,6 @@ A JavaScript settings object for a Perl script run by PEB has the following prop
111112
* **stdoutFunction**
112113
executed every time data is available on STDOUT
113114
The only parameter passed to the ``stdoutFunction`` is the STDOUT ``String``.
114-
*This object property is mandatory.*
115115

116116
An example of an immediate STDOUT data display without accumulation:
117117

resources/app/index-windows.html

Lines changed: 9 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
'Text was entered in a form and it is going to be lost!\n' +
2323
'Are you sure you want to close the application?';
2424

25-
// Settings objects for Perl scripts
26-
// Interactive script:
25+
// PEB settings objects for auto-started Perl interactive scripts:
2726
var messenger_one = {};
2827
messenger_one.scriptRelativePath = 'perl-scripts/messenger.pl';
28+
2929
messenger_one.inputData = function() {
3030
var message = {};
3131
if(("tempfile" in messenger_one)) {
@@ -38,6 +38,7 @@
3838

3939
var messenger_two = {};
4040
messenger_two.scriptRelativePath = 'perl-scripts/messenger.pl';
41+
4142
messenger_two.inputData = function() {
4243
var message = {};
4344
if(("tempfile" in messenger_two)) {
@@ -50,11 +51,13 @@
5051

5152
var interactive_one = {};
5253
interactive_one.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
54+
5355
interactive_one.inputData = function() {
5456
var input = {};
5557
input.mode = "unix-epoch";
5658
return JSON.stringify(input);
5759
}
60+
5861
interactive_one.stdoutFunction = function (stdout) {
5962
var target = document.getElementById('instance-one-output');
6063
var output = JSON.parse(stdout);
@@ -72,11 +75,13 @@
7275

7376
var interactive_two = {};
7477
interactive_two.scriptRelativePath = 'perl-scripts/interactive-windows.pl';
78+
7579
interactive_two.inputData = function() {
7680
var input = {};
7781
input.mode = "local-time";
7882
return JSON.stringify(input);
7983
}
84+
8085
interactive_two.stdoutFunction = function (stdout) {
8186
var target = document.getElementById('instance-two-output');
8287
var output = JSON.parse(stdout);
@@ -91,147 +96,16 @@
9196
target.innerHTML = html;
9297
};
9398
}
94-
95-
// Other PEB tests:
96-
var open_file = {};
97-
open_file.scriptRelativePath = 'perl-scripts/open-files.pl';
98-
open_file.stdoutFunction = function (stdout) {
99-
displayTestResult('open-file', stdout);
100-
}
101-
102-
var open_files = {};
103-
open_files.scriptRelativePath = 'perl-scripts/open-files.pl';
104-
open_files.stdoutFunction = function (stdout) {
105-
displayTestResult('open-files', stdout);
106-
}
107-
108-
var open_directory = {};
109-
open_directory.scriptRelativePath = 'perl-scripts/open-directory.pl';
110-
open_directory.stdoutFunction = function (stdout) {
111-
displayTestResult('open-directory', stdout);
112-
}
113-
114-
var perl_info = {};
115-
perl_info.scriptRelativePath = 'perl-scripts/perl-info.pl';
116-
perl_info.stdoutFunction = function (stdout) {
117-
clearTestData();
118-
displayTestResult('perl-info', stdout);
119-
}
120-
121-
var sqlite = {};
122-
sqlite.scriptRelativePath = 'perl-scripts/sqlite.pl';
123-
sqlite.stdoutFunction = function (stdout) {
124-
clearTestData();
125-
displayTestResult('sqlite-test', stdout);
126-
}
127-
128-
// Settings objects for the filesystem dialogs:
129-
var select_file = {};
130-
select_file.type = 'single-file';
131-
select_file.receiverFunction = function (fileName) {
132-
open_file.inputData = fileName;
133-
clearTestData();
134-
peb.startScript('open_file.script');
135-
}
136-
137-
var new_file_name = {};
138-
new_file_name.type = 'new-file-name';
139-
new_file_name.receiverFunction = function (fileName) {
140-
clearTestData();
141-
var pre = document.createElement("pre");
142-
pre.innerHTML = 'New file name: ' + fileName;
143-
document.getElementById('tests').appendChild(pre);
144-
}
145-
146-
var select_files = {};
147-
select_files.type = 'multiple-files';
148-
select_files.receiverFunction = function (fileNames) {
149-
open_files.inputData = fileNames;
150-
clearTestData();
151-
peb.startScript('open_files.script');
152-
}
153-
154-
var select_directory = {};
155-
select_directory.type = 'directory';
156-
select_directory.receiverFunction = function (directoryName) {
157-
open_directory.inputData = directoryName;
158-
clearTestData();
159-
peb.startScript('open_directory.script');
160-
}
161-
162-
function startPerlInfo() {
163-
peb.startScript('perl_info.script');
164-
}
165-
166-
function startSqlite() {
167-
peb.startScript('sqlite.script');
168-
}
169-
170-
function clearTestData() {
171-
var container = document.getElementById('tests');
172-
while (container.firstChild) {
173-
container.removeChild(container.firstChild);
174-
}
175-
}
176-
177-
function displayTestResult(id, stdout) {
178-
var existingElement = document.getElementById(id);
179-
if (existingElement === null) {
180-
clearTestData();
181-
var newElement = document.createElement("pre");
182-
newElement.id = id;
183-
newElement.innerHTML = stdout;
184-
document.getElementById('tests').appendChild(newElement);
185-
} else {
186-
existingElement.innerHTML = existingElement.innerHTML + stdout;
187-
}
188-
}
18999
</script>
190100

191101
<script src="jquery/jquery-1.12.4.min.js"></script>
192102
<script src="bootstrap/js/bootstrap.js"></script>
193103
<script src="bootstrap/js/bootstrap-dropdown.js"></script>
104+
<script src="peb-demo.js"></script>
194105

195106
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css" media="all">
196107
<link rel="stylesheet" type="text/css" href="bootstrap/css/darkly-theme.css" media="all">
197-
198-
<style type='text/css'>
199-
body {
200-
padding-top: 65px;
201-
}
202-
203-
pre {
204-
margin: 4px;
205-
text-align: left;
206-
font-size: 14px;
207-
font-family: sans-serif;
208-
}
209-
210-
.navbar .navbar-header {
211-
text-align: center;
212-
vertical-align: middle;
213-
}
214-
215-
.navbar .navbar-nav {
216-
display: inline-block;
217-
float: center;
218-
}
219-
220-
.navbar-toggle {
221-
float: center;
222-
margin: 10px;
223-
vertical-align: middle;
224-
}
225-
226-
.introduction {
227-
font-size: 20px;
228-
}
229-
230-
.interactive-output {
231-
font-size: 20px;
232-
margin-bottom: 20px;
233-
}
234-
</style>
108+
<link rel="stylesheet" type="text/css" href="peb-demo.css" media="all">
235109
</head>
236110

237111
<body>

0 commit comments

Comments
 (0)