The module mapfile-ejs allows you to use Embedded JavaScript (EJS) into MapServer Mapfiles.
- Install
Node.js
andnpm
from https://nodejs.org/ - Install
mapfile-ejs
withnpm install mapfile-ejs -g
Use the file extension *.emap for MapServer Mapfiles with EJS. If you watch a directory, all *.emap files will be rendering to *.map files.
Usage: emap [options]
Options:
-h, --help Output usage information
-V, --version Output the version number
-d, --directory <string> Input directory of mapfiles with EJS (*.emap) (default: current directory)
-i, --inputEncoding <string> Encoding of input mapfiles with EJS (default: utf8)
-o, --outputEncoding <string> Encoding of output mapfiles without EJS (default: utf8)
-r, --ignoreInitial Ignore rendering of mapfiles with EJS on initial (default: false)
-e, --eFiles Render all e files like *.exml, *.ecss (default: false)
Examples:
Start watching and rendering with default options:
$ emap
Start watching and rendering with custom options:
$ emap -d ./examples -i iso-8859-1 -o iso-8859-1 -r -e
Render a file:
import { render } from 'mapfile-ejs';
(async () => {
// render file with default options
await render(
`./template__utf8.emap`,
`./template__utf8.map`
);
// render file with custom options
await render(
`./template__iso_8859_1.emap`,
`./template__iso_8859_1__02.map`,
{ inputEncoding: `ISO-8859-1`, outputEncoding: `ISO-8859-1` }
);
})();
Watch a directory:
import { watch } from 'mapfile-ejs';
// watch a directory with default options
watch(`dir1`);
// watch a directory with custom options
watch(`dir2`, {
inputEncoding: `utf8`,
outputEncoding: `utf8`,
eFiles: false,
ignoreInitial: false
});
More details are available at the API Documentation and at the examples directory
Input (example.emap):
MAP
<%
//Loop to create 3 layers
for(let i = 0; i < 3; i++) {
-%>
LAYER
NAME "layer_<%- i %>"
END
<%
} //End of loop
-%>
END
Output (example.map):
MAP
LAYER
NAME "layer_0"
END
LAYER
NAME "layer_1"
END
LAYER
NAME "layer_2"
END
END
How to use require and include:
<%
// import is available like
const path = await import(`node:path`);
-%>
<%
// include is available (include_file.ejs) like
-%>
<%- await include('include_file', { }); %>
Run cli during development:
npm run emap -- -d ./examples/watch/dir1
Run examples:
node examples/isTemplate/index.js
node examples/render/index.js
node examples/watch/index.js
- Fix mistakes in README.md (2023-04-28)
- Update dependencies (2023-04-27)
- Switch from
require()
toimport()
(2023-04-27) - Switch
render()
toasync render()
(2023-04-07) - Remove api documentation (2023-04-27)
- Remove ESLint configuration file
.eslintrc.js
(2023-04-27)
- Update dependencies
- Fix npm bug
- Change npm publisher
- Update dependencies
- Update dependencies
- Update mistaks in
README.md
- Fix log bugs in the cli tool
emap
- Addexamples in
README.md
- Add API Documentation
docs/api
- Add changelog
docs/changelog
- Add ESLint configuration file
.eslintrc.js
- Add Visual Studio Code configuration
.vscode/settings.json
- Restructure code in
src
directory - Add npm script
npm run cli -d ./examples/watchDir/dir1
- Update dependencies
- Switch from class
MapfileRenderer
to module withrender()
andwatch()
function - Add
isTemplate()
function - Add new examples