Skip to content

Commit 5e1d13f

Browse files
committed
chore: restructure codebase
1 parent ea79007 commit 5e1d13f

20 files changed

Lines changed: 8143 additions & 59 deletions

.github/workflows/npm-publish.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3+
4+
name: Node.js Package Publisher
5+
6+
on:
7+
release:
8+
types: [ created ]
9+
push:
10+
tags:
11+
- "v*"
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
- run: npm ci
22+
- run: npm run test
23+
24+
publish-npm:
25+
needs: build
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
registry-url: https://registry.npmjs.org/
33+
- run: npm ci
34+
- run: npm publish
35+
env:
36+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main, master, develop]
6+
pull_request:
7+
branches: [main, master, develop]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest]
15+
node-version: [18.x, 20.x, 22.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run tests
31+
run: npm test
32+
33+
- name: Verify test files exist
34+
run: |
35+
if [ ! -d "tests" ]; then
36+
echo "No tests directory found"
37+
exit 1
38+
fi
39+
if [ -z "$(ls -A tests/*.test.js 2>/dev/null)" ]; then
40+
echo "No test files found in tests directory"
41+
exit 1
42+
fi

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
JStemplater-Nodejs.sublime-project
1+
node_modules/
2+
.secrets

README.md

Lines changed: 160 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,162 @@
1-
# JSTemplater
2-
NodeJS Library/Tool to use pure DOM javascript render with view Engine
1+
# JS-templater
32

4-
### To install package
3+
A Node.js library/tool to use pure DOM JavaScript rendering with a view engine. JS-templater allows you to build modern web applications by rendering JavaScript templates on the server side while maintaining a clean separation between your Node.js backend and JavaScript frontend.
4+
5+
## Features
6+
7+
- 🚀 **Simple Integration**: Easy to integrate with Express.js and other Node.js web frameworks
8+
- 🎨 **Pure JavaScript**: Use vanilla JavaScript for rendering, no framework dependencies
9+
- 📦 **Template Engine**: Server-side template generation with context data passing
10+
- 🔧 **Flexible**: Pass JSON context data to your JavaScript templates
11+
- 📝 **Clean HTML**: Generates clean, semantic HTML structure
12+
13+
## Installation
14+
15+
```bash
16+
npm install js-templater
17+
```
18+
19+
Or install from source:
20+
21+
```bash
22+
git clone https://github.com/marcuwynu23/JSTemplater-NodeJS.git
23+
cd JSTemplater-NodeJS
24+
npm install
25+
```
26+
27+
## Quick Start
28+
29+
### 1. Basic Express.js Setup
30+
31+
```javascript
32+
const express = require('express');
33+
const JSTemplate = require('js-templater');
34+
35+
const app = express();
36+
37+
// Initialize JSTemplate with your static files root
38+
const jsTemplate = new JSTemplate('/static/');
39+
40+
// Serve static files
41+
app.use('/static', express.static('public'));
42+
43+
app.get('/', (req, res) => {
44+
// Render a JavaScript template
45+
const html = jsTemplate.render('index', {
46+
title: 'Welcome',
47+
user: 'John'
48+
});
49+
res.send(html);
50+
});
51+
52+
app.listen(3000, () => {
53+
console.log('Server running on port 3000');
54+
});
555
```
6-
npm i js-templater
7-
```
56+
57+
### 2. Project Structure
58+
59+
Your Node.js application should have the following structure:
60+
61+
```
62+
your-app/
63+
├── server.js
64+
└── public/
65+
├── css/
66+
│ └── style.css
67+
└── js/
68+
└── index.js
69+
```
70+
71+
### 3. JavaScript Template Example
72+
73+
Create `public/js/index.js`:
74+
75+
```javascript
76+
// Get the root element
77+
const root = document.getElementById("root");
78+
79+
// Parse context data if provided
80+
let context = {};
81+
if (root.dataset.content) {
82+
context = JSON.parse(root.dataset.content);
83+
}
84+
85+
// Render your application
86+
root.innerHTML = `
87+
<h1>${context.title || "Hello World"}</h1>
88+
<p>Welcome, ${context.user || "Guest"}!</p>
89+
`;
90+
```
91+
92+
## API Reference
93+
94+
### `JSTemplate(staticRoot)`
95+
96+
Initialize the JSTemplate engine.
97+
98+
**Parameters:**
99+
100+
- `staticRoot` (string): The root path for static files (e.g., '/static/')
101+
102+
**Example:**
103+
104+
```javascript
105+
const jsTemplate = new JSTemplate('/static/');
106+
```
107+
108+
### `render(scriptName, context)`
109+
110+
Render a JavaScript template.
111+
112+
**Parameters:**
113+
114+
- `scriptName` (string): Name of the JavaScript file (without .js extension)
115+
- `context` (object, optional): Context data to pass to the template as JSON
116+
117+
**Returns:**
118+
119+
- `string`: Complete HTML document with embedded script
120+
121+
**Example:**
122+
123+
```javascript
124+
const html = jsTemplate.render('dashboard', {
125+
users: ['Alice', 'Bob']
126+
});
127+
```
128+
129+
## Examples
130+
131+
See the [examples](./examples/) directory for more detailed usage examples.
132+
133+
## Testing
134+
135+
Run tests using Jest:
136+
137+
```bash
138+
npm test
139+
```
140+
141+
Or run tests in watch mode:
142+
143+
```bash
144+
npm run test:watch
145+
```
146+
147+
## Requirements
148+
149+
- Node.js >= 10.0.0
150+
- Express.js (for web framework integration) or any Node.js HTTP server
151+
152+
## License
153+
154+
See [LICENSE](LICENSE) file for details.
155+
156+
## Contributing
157+
158+
Contributions are welcome! Please feel free to submit a Pull Request.
159+
160+
## Author
161+
162+
Mark Wayne B. Menorca

0 commit comments

Comments
 (0)