Skip to content

Commit 9af44cc

Browse files
committed
Further decouple grunt-postmark from mailmason.
Per @derekrushforth's comments on ActiveCampaign/grunt-postmark#3. [This](ActiveCampaign/grunt-postmark#3 (comment)) will break things for folks who are already using these changes (@gcoombe and @jmas) as we're now looking for `lowerCamel` variable names instead of `Title` cased ones. Just means a quick find/replace for `Name`/`name, `Subject`/`subject`, etc. I've internally changed the implementation of `postmark-templates-upload` to support in-memory `htmlBody` and `textBody` as well as lazy loaded paths `htmlSrc` and `textSrc` as @hybernaut originally had it. I didn't actually notice how far my changes had deviated from the default options for the `postmark-templates-upload` task when I filed the PR, but I actually like the idea of loading the template files instead of expecting them to be passed along as task data.
1 parent 19bc8c5 commit 9af44cc

File tree

5 files changed

+23
-37
lines changed

5 files changed

+23
-37
lines changed

Gruntfile.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,23 @@ module.exports = function(grunt) {
317317
options: {
318318
src: [path.email_src],
319319
dist: path.dist,
320-
outputFile: '<%= config.templates.output_file || config.templates.file %>'
320+
file: '<%= config.templates.file %>'
321321
}
322322
},
323323

324-
'postmark-templates-output': {
324+
'postmark-templates-upload': {
325325
options: {
326-
outputFile: '<%= config.templates.output_file || config.templates.file %>',
327-
cleanOutput: '<%= config.templates.clean_output %>'
326+
ephemeralUploadResultsProperty: '<%= config.templates && config.templates.ephemeralUploadResultsProperty %>'
328327
}
329328
},
330329

331-
'postmark-templates-upload': grunt.file.readJSON(
332-
config.templates.output_file
333-
? config.templates.output_file
334-
: config.templates.file
335-
)
330+
'postmark-templates-output': {
331+
options: {
332+
outputFile: '<%= config.templates && config.templates.output_file || config.templates && config.templates.file %>',
333+
cleanOutput: '<%= config.templates && config.templates.clean_output %>',
334+
ephemeralUploadResultsProperty: '<%= config.templates && config.templates.ephemeralUploadResultsProperty %>'
335+
}
336+
},
336337
});
337338

338339

@@ -355,7 +356,7 @@ module.exports = function(grunt) {
355356
grunt.registerTask('flood', ['testBuild', 'postmark:flood']);
356357

357358
// Upload
358-
grunt.registerTask('upload', ['default', 'postmark-templates-generate', 'postmark-templates-reload-templates', 'postmark-templates']);
359+
grunt.registerTask('upload', ['default', 'postmark-templates-generate', 'postmark-templates']);
359360

360361
// Before sending tests via Postmark, ensure that test builds with inlined CSS are generated
361362
grunt.registerTask('testBuild', ['default', 'copy:testTemplates', 'premailer:html']);

example_config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"overwrite": true
5353
},
5454
"templates": {
55-
"file": "templates.json"
55+
"file": "templates.json",
56+
"cleanOutput": true,
57+
"ephemeralUploadResultsProperty": "postmark-templates-upload-results"
5658
}
5759
}

previews.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
var list_item = document.createElement('li')
7070
var anchor = document.createElement('a')
7171
anchor.setAttribute('href', '#' + key)
72-
anchor.appendChild(document.createTextNode(templates[key]['Name'] || templates[key]['name']))
72+
anchor.appendChild(document.createTextNode(templates[key]['name']))
7373
list_item.appendChild(anchor)
7474
list_item.appendChild(document.createTextNode(' - ' + templates[key]['description']))
7575
toc.appendChild(list_item)
@@ -85,7 +85,7 @@
8585
guide_link.setAttribute('target', '_blank')
8686
guide_link.setAttribute('rel', 'noopener noreferrer')
8787
guide_link.appendChild(document.createTextNode('📖 View Best Practices Guide'))
88-
heading.appendChild(document.createTextNode(templates[key]['Name'] || templates[key]['name']))
88+
heading.appendChild(document.createTextNode(templates[key]['name']))
8989
heading.setAttribute('id', key)
9090
description.appendChild(document.createTextNode(templates[key]['description']))
9191
description.appendChild(guide_link)

tasks/grunt-postmark-templates-generate.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ module.exports = function (grunt) {
1212

1313
var options = this.options();
1414
var templatePaths = grunt.file.expand(options.src);
15-
var templateObjects = grunt.file.readJSON(grunt.config.get('config.templates.file'));
15+
var templateObjects = grunt.file.readJSON(options.file);
1616

1717
templatePaths.map(function (templatePath) {
1818
try {
1919
var templateFile = yaml.loadFront(grunt.file.read(templatePath));
2020
var templateName = path.basename(templatePath, '.hbs');
2121
var templateContents = {
22-
Name: templateObjects[templateName] && templateObjects[templateName].name || templateName,
23-
HtmlBody: grunt.file.read(path.join(options.dist, templateName + '.html')),
24-
TextBody: grunt.file.read(path.join(options.dist, templateName + '.txt'))
22+
name: templateObjects[templateName] && templateObjects[templateName].name || templateName,
23+
htmlSrc: path.join(options.dist, templateName + '.html'),
24+
textSrc: path.join(options.dist, templateName + '.txt')
2525
};
2626

2727
if (templateFile.name) {
28-
templateContents.Name = templateFile.name;
28+
templateContents.name = templateFile.name;
2929
}
3030

3131
if (templateFile.subject) {
32-
templateContents.Subject = templateFile.subject;
32+
templateContents.subject = templateFile.subject;
3333
}
3434

3535
if (!templateObjects[templateName]) {
@@ -45,6 +45,6 @@ module.exports = function (grunt) {
4545
}
4646
});
4747

48-
grunt.file.write(grunt.config.get('config.templates.file'), JSON.stringify(templateObjects, null, 2));
48+
grunt.config('postmark-templates-upload', templateObjects);
4949
});
5050
};

tasks/grunt-postmark-templates-reload-templates.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)