Skip to content

Commit

Permalink
Заменить свойства при создании правил
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Aug 23, 2015
1 parent cb62412 commit d5ae5d0
Show file tree
Hide file tree
Showing 71 changed files with 154 additions and 154 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -109,9 +109,9 @@ Typograf.rule({
// язык/группа/правило
name: 'common/other/parampampam',
// Очередность выполнения правил, чем меньше индекс, тем раньше выполнится правило
sortIndex: 2000,
index: 2000,
// Функция обработки правила
func: function(text) {
handler: function(text) {
return text.replace(/parampampam/g, 'tryam');
}
});
Expand Down
6 changes: 3 additions & 3 deletions gulp/utils.js
Expand Up @@ -32,7 +32,7 @@ module.exports = {
return '| ' + i + '. | [' +
rule.name + '](../src/rules/' + rule.name + '.js) | ' +
title + ' | ' +
rule.sortIndex + ' | ' +
rule.index + ' | ' +
(rule.queue || '') + ' | ' +
(rule.enabled === false || rule.disabled === true ? '' : '✓') + ' |\n';
},
Expand Down Expand Up @@ -66,9 +66,9 @@ module.exports = {
var queueA = queue[a.queue],
queueB = queue[b.queue];
if(queueA === queueB) {
if(a.sortIndex > b.sortIndex) {
if(a.index > b.index) {
return 1;
} else if(a.sortIndex < b.sortIndex) {
} else if(a.index < b.index) {
return -1;
} else {
return 0;
Expand Down
18 changes: 9 additions & 9 deletions src/main.js
Expand Up @@ -28,16 +28,16 @@ function Typograf(prefs) {
* @static
* @param {Object} rule
* @param {string} rule.name Name of rule
* @param {Function} rule.func Processing function
* @param {number} [rule.sortIndex] Sorting index for rule
* @param {Function} rule.handler Processing function
* @param {number} [rule.index] Sorting index for rule
* @param {boolean} [rule.disabled] Rule is disabled by default
* @param {Object} [rule.settings] Settings for rule
* @return {Typograf} this
*/
Typograf.rule = function(rule) {
rule.enabled = rule.enabled === false || rule.disabled === true ? false : true;
rule._lang = rule.name.split('/')[0];
rule.sortIndex = rule.sortIndex || /* istanbul ignore next */ 0;
rule.index = rule.index || /* istanbul ignore next */ 0;

Typograf.prototype._rules.push(rule);

Expand All @@ -55,15 +55,15 @@ Typograf.rule = function(rule) {
* @static
* @param {Object} rule
* @param {string} rule.name Name of rule
* @param {Function} rule.func Processing function
* @param {string} [rule.sortIndex] Sorting index for rule
* @param {Function} rule.handler Processing function
* @param {string} [rule.index] Sorting index for rule
* @return {Typograf} this
*/
Typograf.innerRule = function(rule) {
Typograf.prototype._innerRules.push(rule);

rule._lang = rule.name.split('/')[0];
rule.sortIndex = rule.sortIndex || 0;
rule.index = rule.index || 0;

if(Typograf._needSortRules) {
this._sortInnerRules();
Expand Down Expand Up @@ -98,13 +98,13 @@ Typograf._data = {};

Typograf._sortRules = function() {
Typograf.prototype._rules.sort(function(a, b) {
return a.sortIndex > b.sortIndex ? 1 : -1;
return a.index > b.index ? 1 : -1;
});
};

Typograf._sortInnerRules = function() {
Typograf.prototype._innerRules.sort(function(a, b) {
return a.sortIndex > b.sortIndex ? 1 : -1;
return a.index > b.index ? 1 : -1;
});
};

Expand Down Expand Up @@ -223,7 +223,7 @@ Typograf.prototype = {

if((rlang === 'common' || rlang === lang) && this.enabled(rule.name)) {
this._onBeforeRule && this._onBeforeRule(text);
text = rule.func.call(this, text, this._settings[rule.name]);
text = rule.handler.call(this, text, this._settings[rule.name]);
this._onAfterRule && this._onAfterRule(text);
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/escape.js
@@ -1,8 +1,8 @@
Typograf.rule({
name: 'common/html/escape',
sortIndex: 110,
index: 110,
queue: 'end',
func: function(text) {
handler: function(text) {
var entityMap = {
'&': '&amp;',
'<': '&lt;',
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/mail.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/html/mail',
sortIndex: 2000,
func: function(text) {
index: 2000,
handler: function(text) {
return text.replace(
/(^|[\s;(])([\w\-.]{2,})@([\w\-.]{2,})\.([a-z]{2,6})([)\s.,!?]|$)/gi,
'$1<a href="mailto:$2@$3.$4">$2@$3.$4</a>$5'
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/nbr.js
@@ -1,8 +1,8 @@
Typograf.rule({
name: 'common/html/nbr',
sortIndex: 110,
index: 110,
queue: 'start',
func: function(text) {
handler: function(text) {
return text.search(/<br/) === -1 ? text.replace(/\n/g, '<br/>\n') : text;
},
disabled: true
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/pbr.js
@@ -1,8 +1,8 @@
Typograf.rule({
name: 'common/html/pbr',
sortIndex: 90,
index: 90,
queue: 'end',
func: function(text) {
handler: function(text) {
if(text.search(/<(p|br)[\s\/>]/) === -1) {
if(text.search(/\n/) === -1) {
text = '<p>' + text + '</p>';
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/stripTags.js
@@ -1,8 +1,8 @@
Typograf.rule({
name: 'common/html/stripTags',
sortIndex: 100,
index: 100,
queue: 'end',
func: function(text) {
handler: function(text) {
return text.replace(/<\/?[^>]+>/g, '');
},
disabled: true
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/html/url.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/html/url',
sortIndex: 2010,
func: function(text) {
index: 2010,
handler: function(text) {
var prefix = '(http|https|ftp|telnet|news|gopher|file|wais)://',
pureUrl = '([a-zA-Z0-9\/+-=%&:_.~?]+[a-zA-Z0-9#+]*)',
re = new RegExp(prefix + pureUrl, 'g');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/afterNumber.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/nbsp/afterNumber',
sortIndex: 615,
func: function(text) {
index: 615,
handler: function(text) {
var re = '(^|\\D)(\\d{1,5}) ([' +
this.letters() +
']{2,})';
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/afterPara.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/nbsp/afterPara',
sortIndex: 610,
func: function(text) {
index: 610,
handler: function(text) {
return text.replace(/§ ?(\d|I|V|X)/g, '§\u00A0$1');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/afterShortWord.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/nbsp/afterShortWord',
sortIndex: 590,
func: function(text, settings) {
index: 590,
handler: function(text, settings) {
var len = settings.lengthShortWord,
str = '(^| |\u00A0)([' +
this.letters() +
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/beforeShortLastWord.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/nbsp/beforeShortLastWord',
sortIndex: 620,
func: function(text, settings) {
index: 620,
handler: function(text, settings) {
var punc = '.,?!:;',
re = new RegExp('([^' + punc + ']) ([' +
this.letters() + ']{1,' + settings.lengthLastWord + '}[' + punc + '])', 'gi');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/dpi.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/nbsp/dpi',
sortIndex: 1150,
func: function(text) {
index: 1150,
handler: function(text) {
return text.replace(/(\d) ?(lpi|dpi)(?!\w)/, '$1\u00A0$2');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/nbsp/nowrap.js
Expand Up @@ -6,9 +6,9 @@ function replaceNbsp($0, $1, $2, $3) {

Typograf.rule({
name: 'common/nbsp/nowrap',
sortIndex: 100,
index: 100,
queue: 'start',
func: function(text) {
handler: function(text) {
return text
.replace(/(<nowrap>)(.*?)(<\/nowrap>)/g, replaceNbsp)
.replace(/(<nobr>)(.*?)(<\/nobr>)/g, replaceNbsp);
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/number/fraction.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/number/fraction',
sortIndex: 1120,
func: function(text) {
index: 1120,
handler: function(text) {
return text.replace(/(^|\D)1\/2(\D|$)/g, '$1½$2')
.replace(/(^|\D)1\/4(\D|$)/g, '$1¼$2')
.replace(/(^|\D)3\/4(\D|$)/g, '$1¾$2');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/number/plusMinus.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/number/plusMinus',
sortIndex: 1010,
func: function(text) {
index: 1010,
handler: function(text) {
var re = new RegExp('(^| |\\>|\u00A0)\\+-(\\d)', 'g');
return text.replace(re, '$1±$2').replace(/(^\s*)\+-(\s*$)/g, '$1±$2');
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/number/times.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/number/times',
sortIndex: 1050,
func: function(text) {
index: 1050,
handler: function(text) {
return text.replace(/(\d) ?(x|х) ?(\d)/g, '$1×$3');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/other/repeatWord.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/other/repeatWord',
sortIndex: 1200,
func: function(text) {
index: 1200,
handler: function(text) {
var re = '([' +
this.letters() +
'\u0301]+) \\1([;:,.?! \n])';
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/punctuation/delDoublePunctuation.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/punctuation/delDoublePunctuation',
sortIndex: 580,
func: function(text) {
index: 580,
handler: function(text) {
return text.replace(/(,|:|;|\?){2,}/g, '$1');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/punctuation/exclamation.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/punctuation/exclamation',
sortIndex: 1150,
func: function(text) {
index: 1150,
handler: function(text) {
return text
.replace(/(^|[^!])!{2}($|[^!])/, '$1!$2')
.replace(/(^|[^!])!{4}($|[^!])/, '$1!!!$2');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/punctuation/exclamationQuestion.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/punctuation/exclamationQuestion',
sortIndex: 1140,
func: function(text) {
index: 1140,
handler: function(text) {
var re = new RegExp('(^|[^!])!\\?([^?]|$)', 'g');
return text.replace(re, '$1?!$2');
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/space/afterPunctuation.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/afterPunctuation',
sortIndex: 560,
func: function(text) {
index: 560,
handler: function(text) {
var privateLabel = Typograf._privateLabel,
reExcl = new RegExp('(!|;|\\?)([^!;?\\s[)' + privateLabel + Typograf.data('common/quot') + '])', 'g'),
reComma = new RegExp('(\\D)(,|:)([^,:.?\\s\\/' + privateLabel + '])', 'g');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/space/delBeforePercent.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delBeforePercent',
sortIndex: 600,
func: function(text) {
index: 600,
handler: function(text) {
return text.replace(/(\d)( |\u00A0)(%|‰|‱)/g, '$1$3');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/space/delBeforePunctuation.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delBeforePunctuation',
sortIndex: 550,
func: function(text) {
index: 550,
handler: function(text) {
return text.replace(/ (!|;|,|\?|\.|:)/g, '$1')
.replace(/\( /g, '(')
.replace(/([^ ])\(/g, '$1 (')
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/space/delLeadingBlanks.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delLeadingBlanks',
sortIndex: 504,
func: function(text) {
index: 504,
handler: function(text) {
return text.replace(/\n[ \t]+/g, '\n');
},
disabled: true
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/space/delRepeatN.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delRepeatN',
sortIndex: 545,
func: function(text) {
index: 545,
handler: function(text) {
return text.replace(/\n{3,}/g, '\n\n');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/space/delRepeatSpace.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delRepeatSpace',
sortIndex: 540,
func: function(text) {
index: 540,
handler: function(text) {
return text.replace(/([^\n \t])( |\t){2,}([^\n \t])/g, '$1$2$3');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/space/delTrailingBlanks.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/delTrailingBlanks',
sortIndex: 505,
func: function(text) {
index: 505,
handler: function(text) {
return text.replace(/[ \t]+\n/g, '\n');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/space/replaceTab.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/replaceTab',
sortIndex: 510,
func: function(text) {
index: 510,
handler: function(text) {
return text.replace(/\t/g, ' ');
}
});
4 changes: 2 additions & 2 deletions src/rules/common/space/trimLeft.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/trimLeft',
sortIndex: 530,
func: String.prototype.trimLeft ? function(text) {
index: 530,
handler: String.prototype.trimLeft ? function(text) {
return text.trimLeft();
} : /* istanbul ignore next */ function(text) {
return text.replace(/^[\s\uFEFF\xA0]+/g, '');
Expand Down
4 changes: 2 additions & 2 deletions src/rules/common/space/trimRight.js
@@ -1,7 +1,7 @@
Typograf.rule({
name: 'common/space/trimRight',
sortIndex: 535,
func: String.prototype.trimRight ? function(text) {
index: 535,
handler: String.prototype.trimRight ? function(text) {
return text.trimRight();
} : /* istanbul ignore next */ function(text) {
return text.replace(/[\s\uFEFF\xA0]+$/g, '');
Expand Down

0 comments on commit d5ae5d0

Please sign in to comment.