-
Notifications
You must be signed in to change notification settings - Fork 36
Using Mailer inside another package support #51
Changes from all commits
ab4dea1
c1afabd
aed4b7a
5c871ee
46d95fe
37bbde4
2065624
5044bac
3ca0b2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ const factory = (options) => { | |
check(template, Match.ObjectIncluding({ | ||
path: String, | ||
name: String, | ||
packageFolderName: Match.Optional(String), | ||
scss: Match.Optional(String), | ||
css: Match.Optional(String), | ||
layout: Match.Optional(Match.OneOf(Boolean, { | ||
|
@@ -121,7 +122,7 @@ const factory = (options) => { | |
let content = null; | ||
|
||
try { | ||
content = Utils.readFile(template.path); | ||
content = Utils.readFile(template.path, template.packageFolderName); | ||
} catch (ex) { | ||
Utils.Logger.error(`Could not read template file: ${template.path}`, TAG); | ||
return false; | ||
|
@@ -130,7 +131,7 @@ const factory = (options) => { | |
const layout = template.layout || options.layout; | ||
|
||
if (layout && template.layout !== false) { | ||
const layoutContent = Utils.readFile(layout.path); | ||
const layoutContent = Utils.readFile(layout.path, template.packageFolderName); | ||
SSR.compileTemplate(layout.name, layoutContent, { | ||
language: settings.language | ||
}); | ||
|
@@ -195,7 +196,7 @@ const factory = (options) => { | |
// the layout in `<style>` tags. Ideal for media queries. | ||
if (template.extraCSS) { | ||
try { | ||
css = Utils.readFile(template.extraCSS); | ||
css = Utils.readFile(template.extraCSS, template.packageFolderName); | ||
} catch (ex) { | ||
Utils.Logger.error( | ||
`Could not add extra CSS when rendering ${templateName}: ${ex.message}`, TAG); | ||
|
@@ -271,7 +272,7 @@ const factory = (options) => { | |
} | ||
}; | ||
|
||
const init = () => { | ||
const initFactory = () => { | ||
if (options.templates) { | ||
_.each(options.templates, (template, name) => { | ||
template.name = name; | ||
|
@@ -288,7 +289,7 @@ const factory = (options) => { | |
precompile: compile, | ||
render: render, | ||
send: sendEmail, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for renaming the public There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I am not renaming the public interface, because I am renaming the private interface to something different in order _not to _ overwrite this public interface with the extend call, because the way it was before the first call to The goal of this was to enable several init calls to add templates and helpers from several places to the Mailer global. One in main app, and one in the package for example. But I may have gone a bit too fast: it's not taking into account global helpers name overriding for example... |
||
init | ||
initFactory | ||
}; | ||
}; | ||
|
||
|
@@ -302,5 +303,5 @@ Mailer.init = function(opts) { | |
obj.use(Routing); | ||
} | ||
|
||
obj.init(); | ||
obj.initFactory(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,13 @@ const developmentPrivateDir = () => { | |
return path.join(meteorRoot, 'private'); | ||
}; | ||
|
||
const developmentPackagesPrivateDir = () => { | ||
if (!isDevEnv()) | ||
return; | ||
const meteorRoot = process.cwd().replace(/(\.meteor.*)/g, ''); | ||
return path.join(meteorRoot, '.meteor', 'local', 'build', 'programs', 'server', 'assets', 'packages'); | ||
}; | ||
|
||
const productionPrivateDir = () => { | ||
if (isDevEnv()) | ||
return; | ||
|
@@ -40,8 +47,10 @@ const productionPrivateDir = () => { | |
const privateDir = process.env.BUNDLE_PATH || process.env.APP_DIR || productionPrivateDir(); | ||
|
||
let ROOT = privateDir && path.join(privateDir, 'programs', 'server', 'assets', 'app'); | ||
let PACKAGES_ROOT = privateDir && path.join(privateDir, 'programs','server', 'assets', 'packages'); | ||
|
||
ROOT = ROOT || developmentPrivateDir(); | ||
PACKAGES_ROOT = PACKAGES_ROOT || developmentPackagesPrivateDir(); | ||
|
||
Utils = { | ||
// Takes an HTML string and outputs a text version of it. Catches and logs errors. | ||
|
@@ -110,12 +119,12 @@ Utils = { | |
let content = html; | ||
|
||
if (template.css) { | ||
const css = Utils.readFile(template.css); | ||
const css = Utils.readFile(template.css, template.packageFolderName); | ||
content = juice.inlineContent(content, css, juiceOpts); | ||
} | ||
|
||
if (template.scss) { | ||
const scss = Utils.toCSS(template.scss); | ||
const scss = Utils.toCSS(template.scss, template.packageFolderName); | ||
content = juice.inlineContent(content, scss, juiceOpts); | ||
} | ||
|
||
|
@@ -131,27 +140,31 @@ Utils = { | |
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' + html; | ||
}, | ||
|
||
readFile: function(relativePathFromApp) { | ||
const file = path.join(ROOT, relativePathFromApp); | ||
readFile: function(relativePathFromApp, packageFolderName) { | ||
const file = packageFolderName ? | ||
path.join(PACKAGES_ROOT, packageFolderName, relativePathFromApp) | ||
: path.join(ROOT, relativePathFromApp); | ||
|
||
try { | ||
return fs.readFileSync(file, { | ||
encoding: 'utf8' | ||
}); | ||
|
||
} catch (ex) { | ||
Utils.Logger.error(`Could not find file: ${file}, ${ex.message}`, TAG); | ||
throw new Meteor.Error(500, `Could not find file: ${file}`, ex.message); | ||
} | ||
}, | ||
|
||
// Take a path to a SCSS file and compiles it to CSS with `node-sass`. | ||
toCSS: function(scss) { | ||
toCSS: function(scss, packageFolderName) { | ||
if (!Package['chrisbutler:node-sass']) { | ||
Utils.Logger.warn('Sass support is opt-in since lookback:[email protected]. Please add chrisbutler:node-sass from Atmosphere and try again.', TAG); | ||
return Utils.readFile(scss); | ||
} | ||
|
||
const file = path.join(ROOT, scss); | ||
const file = packageFolderName ? | ||
path.join(PACKAGES_ROOT, packageFolderName, scss) | ||
: path.join(ROOT, scss); | ||
const sass = Package['chrisbutler:node-sass'].sass; | ||
|
||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ Package.onUse(function(api) { | |
'underscore', | ||
'email', | ||
'sacha:[email protected]', | ||
'meteorhacks:ssr@2.1.2', | ||
'meteorhacks:ssr@2.2.0', | ||
'meteorhacks:[email protected]' | ||
], where); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some docs on what to pass as
packageFolderName
in README?