Skip to content

Commit 2058a24

Browse files
committed
New Version with Bower, NPM and SpeakingURL
2 parents 3fc0b43 + 4a0c0b2 commit 2058a24

File tree

5 files changed

+49
-74
lines changed

5 files changed

+49
-74
lines changed

jquery.stringToSlug.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* jQuery stringToSlug plug-in 1.3.1
2+
* jQuery stringToSlug plug-in 2.0.0
33
*
44
* Plugin HomePage http://leocaseiro.com.br/jquery-plugin-string-to-slug/
55
*
66
* Copyright (c) 2009 Leo Caseiro
77
*
8-
* Based on Edson Hilios (http://www.edsonhilios.com.br/ Algoritm
8+
* v1 Based on [Edson Hilios](http://www.edsonhilios.com.br/) Algorithm
9+
* v2 Uses [SpeakingURL](https://github.com/pid/speakingurl)
910
*
1011
*
1112
* Dual licensed under the MIT and GPL licenses:
@@ -38,7 +39,7 @@ var _stringToSlug_API = function( text, options ) {
3839
}
3940

4041
/**
41-
* from stringToSlug.space to getSlug.separator
42+
* from stringToSlug.AND to getSlug.custom
4243
*/
4344
if ( ! defaults.options.hasOwnProperty( 'custom' ) ) {
4445
defaults.options.custom = { '&': defaults.AND };

samples.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br">
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
55
<title>Samples jQuery Plugin stringToSlug | Leo Caseiro</title>
66
<meta http-equiv="content-language" content="pt-br" />
77

88
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
9+
<script src="./bower_components/speakingurl/speakingurl.min.js"></script>
910
<script type="text/javascript" src="jquery.stringToSlug.js"></script>
1011

1112
<script type="text/javascript">
@@ -214,4 +215,4 @@ <h4>Set a suffix, like an extension:</h4>
214215
<br /><br />
215216
<em><small>jQuery Plugin StringToSlug create by <a title="Create by Leo Caseiro" href="http://leocaseiro.com.br/">@leocaseiro</a></small></em>
216217
</body>
217-
</html>
218+
</html>

stringToSlug.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stringToSlug",
3-
"version": "1.3.1",
3+
"version": "2.0.0",
44
"title": "jQuery Plugin stringToSlug",
55
"description": "The stringToSlug converts any string to SLUG PERMALINK according unicode.org in most of Languages using special chars or not ())",
66
"keywords": [

tests/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
<script src="qunit.js"></script>
1212
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
13+
<script src="../bower_components/speakingurl/speakingurl.min.js"></script>
1314
<script src="../jquery.stringToSlug.js"></script>
1415
<script src="tests.js"></script>
1516
</body>
16-
</html>
17+
</html>

tests/tests.js

Lines changed: 39 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,99 @@
1-
$('body').append('<input id="text" type="hidden" /><input type="hidden" id="permalink" />');
2-
$('#text').stringToSlug();
1+
function setupBefore() {
2+
$('body').append('<input id="text" type="hidden" /><input type="hidden" id="permalink" />');
3+
}
4+
5+
function teardownAfter() {
6+
$('#text').remove();
7+
}
38

4-
function fromToTest(preText, resultExpect, fieldInput) {
5-
$('#' + fieldInput)
9+
function fromToTest(preText, resultExpect, params) {
10+
params = params || {};
11+
$('#text').stringToSlug(params);
12+
13+
$('#text')
614
.val(preText)
715
.trigger('blur');
816

917
var result = $('#permalink').val();
1018
equal(result, resultExpect, preText + ': ' + result);
1119
}
1220

13-
module('Languages support');
14-
test( "Brazilian Portuguese", function() {
15-
16-
var preText = 'Acentuação tem que ficar! Bonita e sem acento!';
17-
var resultExpect = 'acentuacao-tem-que-ficar-bonita-e-sem-acento';
18-
19-
fromToTest(preText, resultExpect, 'text');
20-
21-
});
22-
23-
test( "English", function() {
24-
25-
var preText = 'Accent has to stay! Beautiful and without accent!';
26-
var resultExpect = 'accent-has-to-stay-beautiful-and-without-accent';
27-
28-
fromToTest(preText, resultExpect, 'text');
2921

22+
test('speakingurl Dependency', function(){
23+
strictEqual(true, typeof getSlug !== 'undefined', 'getURL() passed');
3024
});
3125

32-
test( "Slovak", function() {
33-
34-
var preText = 'vyhľadával NIEKOĽKÝMI';
35-
var resultExpect = 'vyhladaval-niekolkymi';
36-
37-
fromToTest(preText, resultExpect, 'text');
38-
26+
module('Features', {
27+
setup: setupBefore,
28+
teardown: teardownAfter
3929
});
4030

41-
test( "Turkish", function() {
42-
43-
var preText = 'İnsan oğulları üzerine ecdadım Bumın hakan, İstemi hakan tahta oturmuş;';
44-
var resultExpect = 'insan-ogullari-uzerine-ecdadim-bumin-hakan-istemi-hakan-tahta-oturmus';
45-
46-
fromToTest(preText, resultExpect, 'text');
47-
48-
});
49-
50-
module('Commands and functionality');
51-
5231
test( "Replace", function() {
53-
var fieldInput = 'no-parentheses';
54-
$('body'). append('<input id="' + fieldInput + '" type="hidden" />');
55-
$('#' + fieldInput).stringToSlug({
32+
var params = {
5633
replace: /\s?\([^\)]*\)/gi
57-
});
34+
};
5835

5936
var preText = "I'll be alone (because Ill be removed)!";
60-
var resultExpect = 'ill-be-alone';
37+
var resultExpect = 'i-ll-be-alone';
6138

62-
fromToTest(preText, resultExpect, fieldInput);
39+
fromToTest(preText, resultExpect, params);
6340
});
6441

6542
test( "Space", function() {
66-
var fieldInput = 'space';
67-
$('body'). append('<input id="' + fieldInput + '" type="hidden" />');
68-
$('#' + fieldInput).stringToSlug({
43+
var params = {
6944
space: '_'
70-
});
45+
};
7146

7247
var preText = "The space is an undescore";
7348
var resultExpect = 'the_space_is_an_undescore';
7449

75-
fromToTest(preText, resultExpect, fieldInput);
50+
fromToTest(preText, resultExpect, params);
7651
});
7752

7853
test( "Prefix", function() {
79-
var fieldInput = 'prefix';
80-
$('body'). append('<input id="' + fieldInput + '" type="hidden" />');
81-
$('#' + fieldInput).stringToSlug({
54+
var params = {
8255
prefix: 'http://'
83-
});
56+
};
8457

8558
var preText = "I will get a prefix!";
8659
var resultExpect = 'http://i-will-get-a-prefix';
8760

88-
fromToTest(preText, resultExpect, fieldInput);
61+
fromToTest(preText, resultExpect, params);
8962
});
9063

9164

9265
test( "Suffix", function() {
93-
var fieldInput = 'sufix';
94-
$('body'). append('<input id="' + fieldInput + '" type="hidden" />');
95-
$('#' + fieldInput).stringToSlug({
66+
var params = {
9667
suffix: '.jpg'
97-
});
68+
};
9869

9970
var preText = "I will get a suffix!";
10071
var resultExpect = 'i-will-get-a-suffix.jpg';
10172

102-
fromToTest(preText, resultExpect, fieldInput);
73+
fromToTest(preText, resultExpect, params);
10374
});
10475

10576
test( "& AND", function() {
106-
var fieldInput = 'and';
107-
$('body'). append('<input id="' + fieldInput + '" type="hidden" />');
108-
$('#' + fieldInput).stringToSlug({
77+
var params = {
10978
AND: 'e'
110-
});
79+
};
11180

11281
var preText = "Man & Woman";
11382
var resultExpect = 'man-e-woman';
11483

115-
fromToTest(preText, resultExpect, fieldInput);
84+
fromToTest(preText, resultExpect, params);
11685
});
11786

11887

119-
module('Bugs fixed');
88+
module('Bug fixes', {
89+
setup: setupBefore,
90+
teardown: teardownAfter
91+
});
12092

12193
test( "“ and ” (Undefined chars)", function() {
12294

12395
var preText = "A text betweet quotes “ and ” are not going to be a problem!";
12496
var resultExpect = 'a-text-betweet-quotes-and-are-not-going-to-be-a-problem';
12597

126-
fromToTest(preText, resultExpect, 'text');
127-
});
98+
fromToTest(preText, resultExpect);
99+
});

0 commit comments

Comments
 (0)