@reldens/cms 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -11
- package/admin/reldens-admin-client.css +81 -78
- package/lib/frontend.js +141 -27
- package/lib/manager.js +1 -0
- package/lib/template-engine/asset-transformer.js +41 -0
- package/lib/template-engine/collections-single-transformer.js +22 -5
- package/lib/template-engine/collections-transformer.js +35 -14
- package/lib/template-engine/date-transformer.js +53 -0
- package/lib/template-engine/entities-transformer.js +4 -2
- package/lib/template-engine/partials-transformer.js +5 -1
- package/lib/template-engine/system-variables-provider.js +105 -0
- package/lib/template-engine/translate-transformer.js +98 -0
- package/lib/template-engine/translation-service.js +104 -0
- package/lib/template-engine/url-transformer.js +41 -0
- package/lib/template-engine.js +91 -10
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Reldens CMS
|
|
4
4
|
|
|
5
|
-
A powerful, flexible Content Management System built with Node.js, featuring an admin panel, multi-domain frontend support, enhanced templating with reusable content blocks, and automated installation.
|
|
5
|
+
A powerful, flexible Content Management System built with Node.js, featuring an admin panel, multi-domain frontend support, enhanced templating with reusable content blocks, system variables, internationalization, and automated installation.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
@@ -24,6 +24,10 @@ A powerful, flexible Content Management System built with Node.js, featuring an
|
|
|
24
24
|
- **Entity access control** for public/private content
|
|
25
25
|
- **Static asset serving** with Express integration as default
|
|
26
26
|
- **Template engine** with Mustache integration as default
|
|
27
|
+
- **System variables** for request, route, and domain context
|
|
28
|
+
- **Enhanced context passing** with currentEntity data in child blocks
|
|
29
|
+
- **Template functions** for URLs, assets, dates, and translations
|
|
30
|
+
- **Event-driven rendering** with hooks for customization
|
|
27
31
|
- **Custom 404 handling**
|
|
28
32
|
|
|
29
33
|
### - Admin Panel
|
|
@@ -50,6 +54,7 @@ A powerful, flexible Content Management System built with Node.js, featuring an
|
|
|
50
54
|
- **Event-driven system** with hooks for customization
|
|
51
55
|
- **Extensible authentication** (database users or custom callbacks)
|
|
52
56
|
- **File security** with path validation and dangerous key filtering
|
|
57
|
+
- **Internationalization support** with translation files
|
|
53
58
|
|
|
54
59
|
## Installation
|
|
55
60
|
|
|
@@ -128,6 +133,74 @@ const cms = new Manager({
|
|
|
128
133
|
|
|
129
134
|
## Enhanced Templating System
|
|
130
135
|
|
|
136
|
+
### System Variables
|
|
137
|
+
Every template has access to system variables providing context about the current request:
|
|
138
|
+
|
|
139
|
+
```html
|
|
140
|
+
<!-- Current request information -->
|
|
141
|
+
{{currentRequest.baseUrl}} <!-- https://example.com -->
|
|
142
|
+
{{currentRequest.protocol}} <!-- https -->
|
|
143
|
+
{{currentRequest.host}} <!-- example.com -->
|
|
144
|
+
{{currentRequest.path}} <!-- /articles/123 -->
|
|
145
|
+
{{currentRequest.method}} <!-- GET -->
|
|
146
|
+
{{currentRequest.userAgent}} <!-- Browser information -->
|
|
147
|
+
{{currentRequest.isSecure}} <!-- true/false -->
|
|
148
|
+
|
|
149
|
+
<!-- Current route data (if matched) -->
|
|
150
|
+
{{currentRoute.id}} <!-- Route ID -->
|
|
151
|
+
{{currentRoute.path}} <!-- Route path pattern -->
|
|
152
|
+
{{currentRoute.title}} <!-- Route title -->
|
|
153
|
+
{{currentRoute.template}} <!-- Route template -->
|
|
154
|
+
{{currentRoute.layout}} <!-- Route layout -->
|
|
155
|
+
|
|
156
|
+
<!-- Current domain information -->
|
|
157
|
+
{{currentDomain.current}} <!-- Current domain -->
|
|
158
|
+
{{currentDomain.default}} <!-- Default domain -->
|
|
159
|
+
{{currentDomain.resolved}} <!-- Resolved domain -->
|
|
160
|
+
|
|
161
|
+
<!-- System information -->
|
|
162
|
+
{{systemInfo.environment}} <!-- development/production -->
|
|
163
|
+
{{systemInfo.nodeVersion}} <!-- Node.js version -->
|
|
164
|
+
{{systemInfo.timestamp}} <!-- Current timestamp -->
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Template Functions
|
|
168
|
+
Templates support dynamic functions for common operations:
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<!-- URL generation with current domain -->
|
|
172
|
+
[url(/articles)] <!-- https://example.com/articles -->
|
|
173
|
+
[url(/contact#form)] <!-- https://example.com/contact#form -->
|
|
174
|
+
|
|
175
|
+
<!-- Asset URLs with domain -->
|
|
176
|
+
[asset(/css/styles.css)] <!-- https://example.com/css/styles.css -->
|
|
177
|
+
[asset(/images/logo.png)] <!-- https://example.com/images/logo.png -->
|
|
178
|
+
|
|
179
|
+
<!-- Date formatting -->
|
|
180
|
+
[date()] <!-- Current date with default format -->
|
|
181
|
+
[date(now, Y-m-d)] <!-- 2024-01-15 -->
|
|
182
|
+
[date(2024-01-01, d/m/Y)] <!-- 01/01/2024 -->
|
|
183
|
+
|
|
184
|
+
<!-- Internationalization -->
|
|
185
|
+
[translate(welcome.message)] <!-- Translated text -->
|
|
186
|
+
[t(hello.world, Hello World!)] <!-- With fallback -->
|
|
187
|
+
[t(greeting, Hi {name}!, {name: John})] <!-- With interpolation -->
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Enhanced Context Passing
|
|
191
|
+
Child content blocks and partials receive context from parent pages:
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<!-- In a CMS page or layout -->
|
|
195
|
+
<entity name="cmsBlocks" field="name" value="article-sidebar"/>
|
|
196
|
+
|
|
197
|
+
<!-- Inside the article-sidebar block, you can access: -->
|
|
198
|
+
{{currentEntity.title}} <!-- Parent page title -->
|
|
199
|
+
{{currentEntity.id}} <!-- Parent page ID -->
|
|
200
|
+
{{currentEntity.template}} <!-- Parent page template -->
|
|
201
|
+
<!-- Any other parent page properties -->
|
|
202
|
+
```
|
|
203
|
+
|
|
131
204
|
### Template Functions
|
|
132
205
|
Templates support dynamic content blocks, entity rendering, and collections with advanced query options:
|
|
133
206
|
|
|
@@ -365,6 +438,55 @@ Collections support advanced query parameters for pagination and sorting:
|
|
|
365
438
|
</collection>
|
|
366
439
|
```
|
|
367
440
|
|
|
441
|
+
## Internationalization
|
|
442
|
+
|
|
443
|
+
### Translation Files
|
|
444
|
+
Create translation files in the `translations` directory:
|
|
445
|
+
|
|
446
|
+
**translations/en.json:**
|
|
447
|
+
```json
|
|
448
|
+
{
|
|
449
|
+
"navigation": {
|
|
450
|
+
"home": "Home",
|
|
451
|
+
"about": "About Us",
|
|
452
|
+
"contact": "Contact"
|
|
453
|
+
},
|
|
454
|
+
"messages": {
|
|
455
|
+
"welcome": "Welcome to our site!",
|
|
456
|
+
"greeting": "Hello {name}!"
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
**translations/es.json:**
|
|
462
|
+
```json
|
|
463
|
+
{
|
|
464
|
+
"navigation": {
|
|
465
|
+
"home": "Inicio",
|
|
466
|
+
"about": "Acerca de",
|
|
467
|
+
"contact": "Contacto"
|
|
468
|
+
},
|
|
469
|
+
"messages": {
|
|
470
|
+
"welcome": "¡Bienvenido a nuestro sitio!",
|
|
471
|
+
"greeting": "¡Hola {name}!"
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### Using Translations in Templates
|
|
477
|
+
```html
|
|
478
|
+
<!-- Simple translation -->
|
|
479
|
+
[translate(navigation.home)]
|
|
480
|
+
|
|
481
|
+
<!-- With fallback -->
|
|
482
|
+
[t(navigation.home, Home)]
|
|
483
|
+
|
|
484
|
+
<!-- With interpolation -->
|
|
485
|
+
[t(messages.greeting, Hello!, {name: John})]
|
|
486
|
+
|
|
487
|
+
<!-- Locale detection from request headers or ?locale=es parameter -->
|
|
488
|
+
```
|
|
489
|
+
|
|
368
490
|
### Layout System
|
|
369
491
|
The CMS uses a two-tier layout system:
|
|
370
492
|
|
|
@@ -375,11 +497,11 @@ The CMS uses a two-tier layout system:
|
|
|
375
497
|
<head>
|
|
376
498
|
<title>{{title}}</title>
|
|
377
499
|
<meta name="description" content="{{description}}"/>
|
|
378
|
-
<link href="/css/styles.css" rel="stylesheet"/>
|
|
500
|
+
<link href="[asset(/css/styles.css)]" rel="stylesheet"/>
|
|
379
501
|
</head>
|
|
380
502
|
<body class="{{siteHandle}}">
|
|
381
503
|
{{&content}}
|
|
382
|
-
<script src="/js/scripts.js"></script>
|
|
504
|
+
<script src="[asset(/js/scripts.js)]"></script>
|
|
383
505
|
</body>
|
|
384
506
|
</html>
|
|
385
507
|
```
|
|
@@ -415,7 +537,7 @@ Create reusable content blocks in the `cms_blocks` table via the admin panel:
|
|
|
415
537
|
INSERT INTO cms_blocks (name, title, content) VALUES
|
|
416
538
|
('contact-info', 'Contact Information', '<p>Email: info@example.com</p>'),
|
|
417
539
|
('article-sidebar', 'Article Categories',
|
|
418
|
-
'<div class="categories"><h3>Categories</h3><ul><li><a href="/articles/technology">Technology</a></li></ul></div>');
|
|
540
|
+
'<div class="categories"><h3>Categories</h3><ul><li><a href="[url(/articles/technology)]">Technology</a></li></ul></div>');
|
|
419
541
|
```
|
|
420
542
|
|
|
421
543
|
### Entity Access Control
|
|
@@ -452,12 +574,41 @@ templates/
|
|
|
452
574
|
├── partials/
|
|
453
575
|
│ ├── header.html (default)
|
|
454
576
|
│ └── footer.html (default)
|
|
577
|
+
├── translations/
|
|
578
|
+
│ ├── en.json
|
|
579
|
+
│ ├── es.json
|
|
580
|
+
│ └── fr.json
|
|
455
581
|
├── page.html (base HTML wrapper)
|
|
456
582
|
└── 404.html
|
|
457
583
|
```
|
|
458
584
|
|
|
459
585
|
## Advanced Usage
|
|
460
586
|
|
|
587
|
+
### Event System
|
|
588
|
+
The CMS provides hooks for customization through event listeners:
|
|
589
|
+
|
|
590
|
+
```javascript
|
|
591
|
+
// Listen for template variable events
|
|
592
|
+
cms.events.on('reldens.afterVariablesCreated', (eventData) => {
|
|
593
|
+
// Add custom variables
|
|
594
|
+
eventData.variables.customData = {
|
|
595
|
+
timestamp: Date.now(),
|
|
596
|
+
version: '1.0.0'
|
|
597
|
+
};
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// Listen for content processing events
|
|
601
|
+
cms.events.on('reldens.beforeContentProcess', (eventData) => {
|
|
602
|
+
// Modify content before processing
|
|
603
|
+
eventData.content = eventData.content.replace(/\[custom\]/g, 'Custom Value');
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
cms.events.on('reldens.afterContentProcess', (eventData) => {
|
|
607
|
+
// Modify processed content
|
|
608
|
+
eventData.processedContent += '\n<!-- Processed at ' + new Date() + ' -->';
|
|
609
|
+
});
|
|
610
|
+
```
|
|
611
|
+
|
|
461
612
|
### Custom Authentication
|
|
462
613
|
```javascript
|
|
463
614
|
const customAuth = async (email, password, roleId) => {
|
|
@@ -535,13 +686,15 @@ The installer provides checkboxes for:
|
|
|
535
686
|
- `findEntityByPath(path)` - Entity-based URL handling
|
|
536
687
|
|
|
537
688
|
### TemplateEngine Class
|
|
538
|
-
- `render(template, data, partials)` - Main template rendering with enhanced
|
|
539
|
-
- `
|
|
540
|
-
- `
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
- `
|
|
544
|
-
- `
|
|
689
|
+
- `render(template, data, partials, domain, req, route, currentEntityData)` - Main template rendering with enhanced context
|
|
690
|
+
- `processAllTemplateFunctions(template, domain, req, systemVariables)` - Process all template functions
|
|
691
|
+
- `buildEnhancedRenderData(data, systemVariables, currentEntityData)` - Build template context with system variables
|
|
692
|
+
|
|
693
|
+
### SystemVariablesProvider Class
|
|
694
|
+
- `buildSystemVariables(req, route, domain)` - Create system variables for templates
|
|
695
|
+
- `buildCurrentRequestData(req, domain)` - Build request context
|
|
696
|
+
- `buildCurrentRouteData(route)` - Build route context
|
|
697
|
+
- `buildCurrentDomainData(domain)` - Build domain context
|
|
545
698
|
|
|
546
699
|
### AdminManager Class
|
|
547
700
|
- `setupAdmin()` - Initialize admin panel
|
|
@@ -566,6 +719,10 @@ project/
|
|
|
566
719
|
│ ├── partials/ # Shared template partials
|
|
567
720
|
│ ├── page.html # Base HTML wrapper
|
|
568
721
|
│ └── 404.html # Error page
|
|
722
|
+
├── translations/
|
|
723
|
+
│ ├── en.json # English translations
|
|
724
|
+
│ ├── es.json # Spanish translations
|
|
725
|
+
│ └── fr.json # French translations
|
|
569
726
|
├── public/
|
|
570
727
|
│ ├── css/ # Stylesheets
|
|
571
728
|
│ ├── js/ # Client scripts
|