Skip to content

Commit

Permalink
example cpp template complete
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek97 committed Sep 26, 2018
1 parent b25d189 commit dd8cbef
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules
certification/*
src/certification/*

.DS_Store
config.json
config.json

*.swp
*.prod
Binary file added src/assets/fonts/BebasNeue-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/assets/img/bg-cpp-new.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/cblogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/certi-cpp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/signmmgupta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed src/certification/.gitkeep
Empty file.
25 changes: 20 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ queuePromise.then(q => {
// Receive messages
q.subscribe(async function ({ data, callback }) {
try {
data.salt = v4().slice(-4)

// 1. generate html
const path = p.join(__dirname, './certification/' + v4() + ".pdf")
const templatePath = p.join(__dirname, './templates/' + data.template + '.hbs')

const document = {
template: fs.readFileSync(templatePath).toString('utf-8'),
context: {
data
},
path
path,
options: {
type: "pdf",
format: "A4",
orientation: "landscape",
border: "0",
base: "file:///" + __dirname + '/assets/'
}
}

await PDF.create(document, {
Expand All @@ -59,18 +69,23 @@ queuePromise.then(q => {
const webhookPayload = {
secret: config.appSecret,
certificateId: data.certificateId,
url: linkForKey(destKeyName)
url: linkForKey(destKeyName),
salt: data.salt
}

await needle('post', callback, webhookPayload, { json: true })
await needle('patch', callback, webhookPayload, { json: true })

// 4. Cleanup
fs.unlinkSync(path)
} catch (err) {

// If we get any error, let the webhook know about it
Raven.captureException(err)
await needle('post', callback, { error: err }, { json: true })
await needle('patch', callback, {
certificateId: data.certificateId,
secret: config.appSecret,
error: err
}, { json: true })
}
});
})
Expand Down
140 changes: 140 additions & 0 deletions src/templates/cpp.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<html>
<style>
html, body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@font-face {
font-family: "BebasNeue";
src: url(fonts/BebasNeue-Bold.ttf) format('truetype');
}
@font-face {
font-family: "Dhanikans";
src: url(fonts/Dhanikans_Signature_2_dafont.ttf) format("truetype");
}
.container {
border: 24px solid white;
border-radius: 40px;
height: 546px;
position: relative;
background-image: url('img/bg-cpp-new.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.cb-image {
width: 170px;
height: 58px;
top: 34px;
background-image: url('img/cblogo.png');
background-size: contain;
background-repeat: no-repeat;
}
.text {
color: white;
position: absolute;
left: 32px;
font-family: Avenir;
}
.completion {
position: absolute;
top: 127px;
font-family: BebasNeue;
font-size: 60px;
color: white;
}
.completion-sub {
top: 184px;
font-size: 19px;
font-family: Avenir;
}
.name {
top: 243px;
font-family: Dhanikans;
font-size: 41px;
}
.course-text {
font-size: 20px;
width: 462px;
top: 333px
}
.batch {
top: 424px;
font-size: 16px;
}
.signature {
top: 413px;
left: 317px;
font-size: 14px;
}
.signature > img {
width: 88px;
height: 33px;
}
.verify {
font-size: 10px;
bottom: 22px;
}
.course-logo {
width: 149px;
height: 172px;
top: 62px;
left: 591px;
}
</style>
<body>
<div class="container">
<div class="cb-image text"></div>
<div class="completion text">CERTIFICATE OF COMPLETION</div>
<div class="completion-sub text">This certificate is proudly presented to</div>
<div class="name text">Mohit Yadav</div>
<div class="course-text text">for successfully completing the C++ Online Course
by Coding Blocks
</div>

<img src="img/certi-cpp.png" alt="" class="course-logo text">

<div class="batch text">
<div class="duration">15 May 2018 - 15 Aug 2018</div>
<hr>
<div>Batch</div>
</div>

<div class="batch text">
<div class="duration">15 May 2018 - 15 Aug 2018</div>
<hr>
<div>Batch</div>
</div>

<div class="signature text">
<img src="img/signmmgupta.png" alt="">
<hr>
<div>
Manmohan Gupta <br>
(Founder, Coding Blocks)
</div>
</div>

<div class="verify text">
The certificate can be verified at online.codingblocks.com/verify/c++001
</div>
</div>

</body>

</html>
5 changes: 0 additions & 5 deletions src/templates/java.hbs

This file was deleted.

0 comments on commit dd8cbef

Please sign in to comment.