1.4.2 • Published 3 years ago

nodehp v1.4.2

Weekly downloads
1
License
ISC
Repository
-
Last release
3 years ago

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);
ParameterTypeDescription
_PATH_StringString to print
dataANYdata 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_);
ParameterTypeDescription
_STR_StringString 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_);
ParameterTypeDescription
_TNAME_StringTag Name
_INL_Stringinline tag options (like class or href)
_STR_StringString to print

echoTag

Combines echo() and tag().

echoTag(_TNAME_, _INL_, _STR_);
ParameterTypeDescription
_TNAME_StringTag Name
_INL_Stringinline tag options (like class or href)
_STR_StringString to print

include

Prints string to the HTML output string.

include(_IPATH_, _IDATA_);
ParameterTypeDescription
_IPATH_Stringpath to external .nodehp file
_IDATA_ANYdata to send to the external .nodehp file

In your .nodehp code, the following cannot be used as they are necessary for nodehp to run properly:

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.

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago