Skip to content
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

Horizontal Ruler Helper #40

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/helpers/ruler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Add a horizontal ruler to your email
*
* @example
* {{{ruler color="#ec6225" width="60px" height="3px" spacing="15px"}}}
*
* Attribute Options
* color: Must be hex color value
* width: Can be percentage (50%) or pixel (50px) unit
* height: Defaults to pixel unit
* spacing: Default to pixel unit
*
*/

module.exports = function(options) {

// Trim Non-Numberic Chracters
String.prototype.trimUnit = function() { return this.replace(/\D/g, ''); }

// Variables & Options
var
color = options.hash.color,
spacing = options.hash.spacing.trimUnit(),
height = options.hash.height.trimUnit(),
width = options.hash.width,
widthType = '',
trimWidth = width.trimUnit(),
spacer = '';

// Set Undefined Options
if (typeof color === 'undefined') color = '';
if (typeof height === 'undefined') height = '';
if (typeof width === 'undefined') width = '';
if (typeof spacing === 'undefined') {
spacer = '';
} else {
spacer = '<tr height="'+spacing+'"><td height="'+spacing+'"></td></tr>';
};

// Set Width Variables
if(width.match('%$')) {
widthType = width = trimWidth+'%';
} else if (width.match('px$')) {
widthType = trimWidth+'px';
width = trimWidth;
} else {
widthType = 'auto';
width = trimWidth;
}

// HTML Output
var ruler = '\
<table align="center" border="0" cellpadding="0" cellspacing="0" width="'+width+'" height="'+height+'" style="width:'+widthType+' !important; height: '+height+'px !important;">\
'+spacer+'\
<tr height="'+height+'">\
<td bgcolor="'+color+'" align="center" valign="top" width="'+width+'" height="'+height+'" style="font-size: 0%; line-height:'+height+'px; mso-line-height-rule:exactly;">\
<img src="https://spacergif.org/spacer.gif" width="'+width+'" height="'+height+'" />\
</td>\
</tr>\
'+spacer+'\
</table>\
';

return ruler;
}