1.0.2 • Published 8 years ago

node-inject-template v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

node-inject-template

Inject underscore template file into main html file inside script tag.

Installation

npm install node-inject-template

Launch

node ./node_modules/node-inject-template/index.js dest=index.html folder=templates

That command take two options :

  • dest : destination file whete templates content will be injected
  • folder : folder who containes all templates to inject

In this case all files in templates folder will be injected in index.html file.

Special comment

Before run command you must add that html comment in destination file :

<!-- #! template -->
<!-- ## template -->

Example

index.html file :

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
    </head>
    <body>
        <!-- #! template -->
        <!-- ## template -->
    </body>
</html>

A templates file in templates folder, main-view.html

<h1>
    <% _.first(['hello']) %> world
</h1>

Result after command (output file is actually not prettyfied) :

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Test</title>
        </head>
        <body>
            <!-- #! template -->
            <script type="text/template" id="template-1">
                <h1>
                    <% _.first(['hello']) %> world
                </h1>
            </script>
            <!-- ## template -->
        </body>
    </html>

TODO

  • Create grunt plugin
  • Add possibility to run command without node ./node_modules/node-inject-template/index.js

Changelog

1.0.2

  • Reset destination file before inject template