Skip to content

Commit 835fd90

Browse files
committed
refactor: move variables to parent scope and clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 96abca0 commit 835fd90

File tree

1 file changed

+11
-9
lines changed
  • lib/node_modules/@stdlib/plot/base/view/lib/electron

1 file changed

+11
-9
lines changed

lib/node_modules/@stdlib/plot/base/view/lib/electron/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
'use strict';
2020

21-
// TODO: refactor. Remove disposable server. Create a server in the electron process and have it serve assets from local directories. Should be similar to SimpleServer.
22-
2321
// MODULES //
2422

2523
var spawn = require( 'child_process' ).spawn;
@@ -29,6 +27,7 @@ var instanceOf = require( '@stdlib/assert/instance-of' );
2927
var ENV = require( '@stdlib/process/env' );
3028
var copy = require( '@stdlib/utils/copy' );
3129
var merge = require( '@stdlib/utils/merge' );
30+
var replace = require( '@stdlib/string/base/replace' );
3231
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
3332
var createServer = require( '@stdlib/plot/base/server' );
3433
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -42,12 +41,17 @@ var electron = tryRequire( '@stdlib/electron' );
4241
var FOPTS = {
4342
'encoding': 'utf8'
4443
};
44+
var INDEX_TEMPLATE = path.join( __dirname, 'index.html' );
45+
var RESET_CSS = path.join( __dirname, 'css', 'reset.css' );
46+
47+
var RE_PLOT = /\{\{plot\}\}/;
48+
var RE_RESET_CSS = /\{\{reset\}\}/;
4549

4650

4751
// MAIN //
4852

4953
/**
50-
* Opens a plot in an electron window.
54+
* Opens a plot in an Electron window.
5155
*
5256
* @private
5357
* @param {Object} plot - plot context
@@ -66,14 +70,12 @@ function view( plot, html ) {
6670
throw new Error( 'invalid operation. Unable to load Electron. Ensure Electron is installed and try again.' );
6771
}
6872
debug( 'Injecting HTML into HTML template...' );
69-
index = path.join( __dirname, 'index.html' );
70-
index = readFileSync( index, FOPTS );
71-
index = index.replace( /\{\{plot\}\}/, html );
73+
index = readFileSync( INDEX_TEMPLATE, FOPTS );
74+
index = replace( index, RE_PLOT, html );
7275

7376
debug( 'Injecting CSS into HTML template...' );
74-
css = path.join( __dirname, 'css', 'reset.css' );
75-
css = readFileSync( css, FOPTS );
76-
index = index.replace( /\{\{reset\}\}/, css );
77+
css = readFileSync( RESET_CSS, FOPTS );
78+
index = replace( index, RE_RESET_CSS, css );
7779

7880
debug( 'Creating a server...' );
7981
createServer( router, onReady );

0 commit comments

Comments
 (0)