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 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
Copy link

@IamManchanda IamManchanda Feb 22, 2017

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