Skip to content

Added realtime render endpoint using templater package #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: Roadmap-2023
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## About

## About
The Doc-Generator is an easily integrable and reusable tool built on open-source software (OSS). It provides seamless generation of single and bulk documents in various available formats, ensuring interoperability. Additionally, it offers the following features:

- Upload the generated documents to CDN, Google Drive, S3, or a custom sink.
Expand All @@ -8,7 +8,6 @@ The Doc-Generator is an easily integrable and reusable tool built on open-source
The project is built on a plugin model, which ensures customizability and wide adoption.

## C4GT 2023

- The [v2](https://github.com/Samagra-Development/Doc-Generator/tree/v2) branch contains the original source code written in python. You can refer to it for more details.
- Join our discord community here: [https://discord.com/invite/VPrXf7Jxpr](https://discord.com/invite/VPrXf7Jxpr), head to [doc-generator](https://discord.com/channels/973851473131761674/1107697276475941024) channel.
- To start contributing, check out the [good-first-issues](https://github.com/Samagra-Development/Doc-Generator/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) section.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"prisma": "^4.8.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"templater": "file:templater-0.0.1.tgz",
"tsc-files": "^1.1.3"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ model User {
email String @unique
name String?
}

model Template {
id Int @id @default(autoincrement())
content String
}

enum TemplateType {
JINJA
EJS
JSTL
}
4 changes: 2 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AppController {
status: 200,
description: 'Check if service is alive',
})
getHello(): string {
return this.appService.getHello();
getHello() {
return 'Doc Generator';
}
}
15 changes: 15 additions & 0 deletions src/app.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';

export class TemplateTest {
@ApiProperty({ type: String, description: 'Template content' })
content: string;

@ApiProperty({ type: String, description: 'Template id' })
id: string;
}

export enum TemplateType {
JSTL = 'JSTL',
EJS = 'EJS',
JINJA = 'JINJA',
}
15 changes: 13 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { PrismaHealthIndicator } from './health/prisma.health';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { HealthController } from './health/health.controller';
import { PrismaModule } from './prisma/prisma.module';
import { RenderModule } from 'templater';
import { GeneratorModule } from './generator/generator.module';
import { GeneratorService } from './generator/generator.service';
import { GeneratorController } from './generator/generator.controller';

@Module({
imports: [
Expand Down Expand Up @@ -38,8 +42,15 @@ import { PrismaModule } from './prisma/prisma.module';
HttpModule,
TerminusModule,
PrismaModule,
RenderModule,
GeneratorModule,
],
controllers: [AppController, HealthController, GeneratorController],
providers: [
AppService,
PrismaService,
PrismaHealthIndicator,
GeneratorService,
],
controllers: [AppController, HealthController],
providers: [AppService, PrismaService, PrismaHealthIndicator],
})
export class AppModule {}
6 changes: 1 addition & 5 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Doc generator';
}
}
export class AppService {}
22 changes: 22 additions & 0 deletions src/generator/generator.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Body, Controller, Post } from '@nestjs/common';
import { GeneratorService } from './generator.service';
import { GenReq, GenRes } from './types';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

@Controller('generate')
@ApiTags('generator')
export class GeneratorController {
constructor(private generateService: GeneratorService) {}

@Post('/')
@ApiOperation({ summary: 'For realtime rendering of templates' })
@ApiResponse({
status: 200,
description: 'processed string',
type: GenRes,
})
gen(@Body() body: GenReq): Promise<string | string[]> {
const res = this.generateService.generate(body);
return res;
}
}
12 changes: 12 additions & 0 deletions src/generator/generator.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { RenderModule } from 'templater';
import { GeneratorController } from './generator.controller';
import { GeneratorService } from './generator.service';

@Module({
imports: [RenderModule],
providers: [GeneratorService],
controllers: [GeneratorController],
exports: [GeneratorService],
})
export class GeneratorModule {}
13 changes: 13 additions & 0 deletions src/generator/generator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Injectable } from '@nestjs/common';
import { RenderService } from 'templater';
import { GenReq } from './types';

@Injectable()
export class GeneratorService {
constructor(private readonly renderService: RenderService) {}

async generate(data: GenReq) {
const { processed } = await this.renderService.renderTemplate(data);
return processed;
}
}
33 changes: 33 additions & 0 deletions src/generator/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ApiProperty } from '@nestjs/swagger';
import { TemplateType, TemplateTest } from '../app.interface';

export class GenReq {
@ApiProperty({
description: 'Template to be rendered',
type: TemplateTest,
})
template: TemplateTest;

@ApiProperty({
description: 'Data to be rendered in json format',
type: Object,
example: {
variable_name: 'variable_value',
},
})
data: any;

@ApiProperty({
description: 'Type of template',
enum: TemplateType,
})
engineType: TemplateType;
}

export class GenRes {
@ApiProperty({
description: 'Processed string',
type: String,
})
processed: string | string[];
}
Binary file added templater-0.0.1.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"strictPropertyInitialization": false,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
Expand Down
14 changes: 1 addition & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3413,13 +3413,6 @@ jest-message-util@^29.5.0:
slash "^3.0.0"
stack-utils "^2.0.3"

jest-mock-extended@^2.0.4:
version "2.0.9"
resolved "https://registry.yarnpkg.com/jest-mock-extended/-/jest-mock-extended-2.0.9.tgz#bc0e4a269cdb6047d7cc086e1d9722f7215ca795"
integrity sha512-eRZq7/FgwHbxOMm3Lo4DpQX6S2zi4OvwMVFHEb3FgDLp0Xy3P1WARkF93xxO5uD4nAHiEPYHZ25qVU9mAVxoLQ==
dependencies:
ts-essentials "^7.0.3"

jest-mock@^29.5.0:
version "29.5.0"
resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-29.5.0.tgz#26e2172bcc71d8b0195081ff1f146ac7e1518aed"
Expand Down Expand Up @@ -5007,11 +5000,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==

ts-essentials@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38"
integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==

[email protected]:
version "29.0.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.0.3.tgz#63ea93c5401ab73595440733cefdba31fcf9cb77"
Expand Down Expand Up @@ -5392,4 +5380,4 @@ [email protected]:
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==