Skip to content
Open
Changes from 3 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
60 changes: 60 additions & 0 deletions src/helpers/ruler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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

@IamManchanda IamManchanda Feb 22, 2017

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Indent properly .... Indentation should have 2 line spaces only instead of a tab.

If you are using editor like sublime text or atom , you can make your line space from 4 to 2 by customizing it like this below example of sublime!

"tab_size": 2,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IamManchanda thanks, I just checked preferences and tab_size is already set to 2 and translate tabs to spaces is set to true as well.

{
  // The number of spaces a tab is considered equal to
  "tab_size": 2,
  // Set to true to insert spaces when tab is pressed
  "translate_tabs_to_spaces": true,
  // Set to false to disable detection of tabs vs. spaces on load
  "detect_indentation": false,
}

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;
}