Skip to content

Fix compress attributes #223

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

Merged
merged 3 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions build/ploticon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* jshint quotmark:true */

'use strict';

module.exports = {
Expand Down
41 changes: 25 additions & 16 deletions tasks/util/compress_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@ var through = require('through2');
* of the plotly.js bundles
*/

var attributeNamesToRemove = [
'description', 'requiredOpts', 'otherOpts', 'hrName', 'role'
];

// ref: http://www.regexr.com/3bj6p
var regexStr = '';
attributeNamesToRemove.forEach(function(attr, i) {
// one line string with or without trailing comma
regexStr += attr + ': \'.*\'' + ',?' + '|';
// array of strings with or without trailing comma
regexStr += attr + ':.*\\n*.*\\.join\\(\\\'\\s\\\'\\)';

// attr:.*\n.*\.join\(\'\s\'\)

if(i !== attributeNamesToRemove.length-1) regexStr += '|';
});

// one line string with or without trailing comma
function makeStringRegex(attr) {
return attr + ': \'.*\'' + ',?';
}

// joined array of strings with or without trailing comma
function makeJoinedArrayRegex(attr) {
return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?';
}

// array with or without trailing comma
function makeArrayRegex(attr) {
return attr + ': \\[[\\s\\S]*?\\]' + ',?';
}

// ref: http://www.regexr.com/3cmac
var regexStr = [
makeStringRegex('description'),
makeJoinedArrayRegex('description'),
makeArrayRegex('requiredOpts'),
makeArrayRegex('otherOpts'),
makeStringRegex('hrName'),
makeStringRegex('role')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdtusz clearer, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

].join('|');

var regex = new RegExp(regexStr, 'g');

Expand Down