README
nodehp
A Hypertext Preprocessor for NodeJS, created in the spirit of PHP. However, instead of using PHP code, NodeJS with some added methods can be used instead.
Download nodehp
Install via npm:
npm install nodehp
Usage example
JS:
const nodehp = require('nodehp');
var data = {
number: 10,
string: "Hello World!"
}
//data is optional
var output_string = nodehp('path', data);
nodehp input:
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<!-- where your .nodehp code goes -->
<nodehp>
var output = data.string + "for the " + data.number + "th time!";
echo("<h1>" + output + "</h1>");
echoTag('p', 'style="color: red;"','paragraph');
</nodehp>
</body>
</html>
Output:
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<!-- where your .nodehp code goes -->
<h1>Hello World! for the 10th time!</h1>
<p style="color: red;">paragraph</p>
</body>
</html>
API
Server Side
nodehp
Returns output HTML string from given .nodehp
file.
require('nodehp')(_PATH_, data);
Parameter | Type | Description |
---|---|---|
_PATH_ |
String | String to print |
data |
ANY | data to send to the external .nodehp file |
Client Side
nodehp Tag
This tag turns is what is special about a .nodehp
file. It allows for NodeJS (with nodehp extentions) code to be written.
<nodehp>
<!-- where your .nodehp code goes -->
</nodehp>
echo
Prints string to the HTML output string.
echo(_STR_);
Parameter | Type | Description |
---|---|---|
_STR_ |
String | String to print |
tag
Returns a tag to the HTML output string. This string is not automatically added to the HTML output string.
tag(_TNAME_, _INL_, _STR_);
Parameter | Type | Description |
---|---|---|
_TNAME_ |
String | Tag Name |
_INL_ |
String | inline tag options (like class or href ) |
_STR_ |
String | String to print |
echoTag
Combines echo()
and tag()
.
echoTag(_TNAME_, _INL_, _STR_);
Parameter | Type | Description |
---|---|---|
_TNAME_ |
String | Tag Name |
_INL_ |
String | inline tag options (like class or href ) |
_STR_ |
String | String to print |
include
Prints string to the HTML output string.
include(_IPATH_, _IDATA_);
Parameter | Type | Description |
---|---|---|
_IPATH_ |
String | path to external .nodehp file |
_IDATA_ |
ANY | data to send to the external .nodehp file |
.nodehp
code, the following cannot be used as they are necessary for nodehp to run properly:
In your For Internal Use:
- _NODEHP_
- _PATH_
- _FILE_
- _OUTPUT_
- _CURSOR_
- _STRING_
- _STR_
- _CSFKW_
- _IPATH_
- _IDATA_
- _TNAME_
- _INL_
For Sublime Users:
Included is my custom Sublime highlighting syntax (.sublime-syntax). This adds Javascript syntax highlighting inside the nodehp tag and uses the .nodehp
file extention.
Installation:
In Sublime Text 3, got to:
Prefrences > Browse Packages...
This will open a folder in file explorer. The .sublime-syntax file should go in the User
folder.