Skip to content

Commit cb68a64

Browse files
committed
more core delegations via string util
1 parent 2701932 commit cb68a64

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

system/core/delegates/StringUtil.cfc

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
*/
77
component singleton {
88

9+
/**
10+
* Slugify a string for URL Safety
11+
*
12+
* @str Target to slugify
13+
* @maxLength The maximum number of characters for the slug
14+
* @allow a regex safe list of additional characters to allow
15+
*/
16+
function slugify(
17+
required str,
18+
numeric maxLength = 0,
19+
allow = ""
20+
){
21+
// Cleanup and slugify the string
22+
var slug = lCase( trim( arguments.str ) );
23+
slug = replaceList(
24+
slug,
25+
"#chr( 228 )#,#chr( 252 )#,#chr( 246 )#,#chr( 223 )#",
26+
"ae,ue,oe,ss"
27+
);
28+
slug = reReplace(
29+
slug,
30+
"[^a-z0-9-\s#arguments.allow#]",
31+
"",
32+
"all"
33+
);
34+
slug = trim( reReplace( slug, "[\s-]+", " ", "all" ) );
35+
slug = reReplace( slug, "\s", "-", "all" );
36+
37+
// is there a max length restriction
38+
if ( arguments.maxlength ) {
39+
slug = left( slug, arguments.maxlength );
40+
}
41+
42+
return slug;
43+
}
44+
945
/**
1046
* Convert a string to camel case using a functional approach.
1147
*
@@ -61,10 +97,7 @@ component singleton {
6197
* @target The incoming string
6298
*/
6399
function lcFirst( required target ){
64-
return lcase( left( arguments.target, 1 ) ) & right(
65-
arguments.target,
66-
len( arguments.target ) - 1
67-
);
100+
return lCase( left( arguments.target, 1 ) ) & right( arguments.target, len( arguments.target ) - 1 );
68101
}
69102

70103
/**

system/modules/HTMLHelper/models/HTMLHelper.cfc

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ component
99
accessors=true
1010
threadSafe
1111
singleton
12-
delegates="JsonUtil@coreDelegates,Settings@cbDelegates"
12+
delegates="JsonUtil@coreDelegates,Settings@cbDelegates,StringUtil@coreDelegates"
1313
{
1414

1515
/****************************************************************
@@ -546,42 +546,6 @@ component
546546
}
547547
}
548548

549-
/**
550-
* Slugify a string for URL Safety
551-
*
552-
* @str Target to slugify
553-
* @maxLength The maximum number of characters for the slug
554-
* @allow a regex safe list of additional characters to allow
555-
*/
556-
function slugify(
557-
required str,
558-
numeric maxLength = 0,
559-
allow = ""
560-
){
561-
// Cleanup and slugify the string
562-
var slug = lCase( trim( arguments.str ) );
563-
slug = replaceList(
564-
slug,
565-
"#chr( 228 )#,#chr( 252 )#,#chr( 246 )#,#chr( 223 )#",
566-
"ae,ue,oe,ss"
567-
);
568-
slug = reReplace(
569-
slug,
570-
"[^a-z0-9-\s#arguments.allow#]",
571-
"",
572-
"all"
573-
);
574-
slug = trim( reReplace( slug, "[\s-]+", " ", "all" ) );
575-
slug = reReplace( slug, "\s", "-", "all" );
576-
577-
// is there a max length restriction
578-
if ( arguments.maxlength ) {
579-
slug = left( slug, arguments.maxlength );
580-
}
581-
582-
return slug;
583-
}
584-
585549
/**
586550
* Creates auto discovery links for RSS and ATOM feeds.
587551
*

test-harness/views/main/index.cfm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<div class="row">
1616
<div class="col-md-9">
1717

18+
<h2>#html.slugify( "html helper ' can slugify via the string util" )#</h2>
19+
1820
<section id="eventHandlers">
1921
<div class="page-header">
2022
<h2>

0 commit comments

Comments
 (0)