diff --git a/README.md b/README.md index 1bcb2f9..cc70b89 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# HtmlHelper.cfc (Vers. 0.9.3) +# HtmlHelper.cfc (Vers. 0.9.4) --- diff --git a/cftasks/generateStaticHTML.cfc b/cftasks/generateStaticHTML.cfc index 8148e06..96e7e80 100644 --- a/cftasks/generateStaticHTML.cfc +++ b/cftasks/generateStaticHTML.cfc @@ -12,16 +12,16 @@ component { fileSystemUtil.createMapping( "components", basePath & "components" ); print.boldCyanLine( "Map 'components' created." ); cfhttp( - method = "GET", + method = "GET", charset = "utf-8", - url = "http://localhost:8080/", - result = "result" + url = "http://localhost:8080/", + result = "result" ) { } print.boldCyanLine( "Retrieving http to http://localhost:8080" ); htmlHelperService = new components.HtmlHelper(); - resultFinal = result.filecontent.replacenocase( "If you want to see an enhanced version of this page, please visit https&##x3a;&##x2f;&##x2f;andreasru.github.io&##x2f;cfml-htmlhelper&##x2f;", "", "ALL" ); + resultFinal = result.filecontent.replacenocase( "If you want to see an enhanced version of this page, please visit https&##x3a;&##x2f;&##x2f;andreasru.github.io&##x2f;cfml-htmlhelper&##x2f;", "", "ALL" ); print.boldCyanLine( "Minifying content" ); minifiedfilecontent = htmlHelperService.minifyHtml( resultFinal ); print.boldCyanLine( "CfContent minified" ); diff --git a/components/HtmlHelper.cfc b/components/HtmlHelper.cfc index 0a24765..bc13117 100644 --- a/components/HtmlHelper.cfc +++ b/components/HtmlHelper.cfc @@ -1,4 +1,4 @@ -component output=false { +component output = false { /********************************************************** * HTMLHelper.cfc Version 0.9.4: @@ -14,19 +14,19 @@ component output=false { public function init() { local.service = { - "version" : "0.9.4", - "debug" : false, - "demarkerStart" : "_1.", - "demarkerEnd" : "_2.", - "debugResult" : function( htmlstring, label="", regexForDump ){ - // if set to debug force output! - if( service.debug ){ - writeoutput("
" & label & ":"); - if(structKeyExists(arguments, "regexForDump")){ - dump( htmlstring.reMatch( arguments.regexForDump ) ); - } - writeoutput("
" & encodeForHTML( htmlstring ) & "
" ); - } + "version" : "0.9.4", + "debug" : false, + "demarkerStart": "_1.", + "demarkerEnd" : "_2.", + "debugResult" : function( htmlstring, label = "", regexForDump ) { + // if set to debug force output! + if( service.debug ) { + writeOutput( "
" & label & ":" ); + if( structKeyExists( arguments, "regexForDump" ) ) { + dump( htmlstring.reMatch( arguments.regexForDump ) ); + } + writeOutput( "
" & encodeForHTML( htmlstring ) & "
" ); + } }, "reduceArrayAndReplaceString": function( arrayWithElements, contentString, replaceWith ) { replaceWith = arguments.replaceWith; @@ -37,57 +37,57 @@ component output=false { "stripMultlineComments": function( htmlcontent ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="stripMultlineComments",regexForDump= "(\s)+\/\*(.|\n)*?\*\/" ); - + service.debugResult( htmlstring = result, label = "stripMultlineComments", regexForDump = "(\s)+\/\*(.|\n)*?\*\/" ); + stringsToRemove.append( result.reMatch( "(\s)+\/\*(.|\n)*?\*\/" ), true ); result = service.reduceArrayAndReplaceString( stringsToRemove, result, "" ); - service.debugResult( htmlstring=result, label="Result" ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "stripSingleLineComments": function( htmlcontent ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="stripSingleLineComments",regexForDump="(\s)+(?:\/\/)(.*?)[\r|\n]" ); + service.debugResult( htmlstring = result, label = "stripSingleLineComments", regexForDump = "(\s)+(?:\/\/)(.*?)[\r|\n]" ); stringsToRemove.append( result.reMatch( "(\s)+(?:\/\/)(.*?)[\r|\n]" ), true ); - result = service.reduceArrayAndReplaceString( stringsToRemove, result, chr(10) ); - service.debugResult( htmlstring=result, label="Result" ); + result = service.reduceArrayAndReplaceString( stringsToRemove, result, chr( 10 ) ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "stripHtmlComments": function( htmlcontent ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="stripHtmlComments",regexForDump="" ); + service.debugResult( htmlstring = result, label = "stripHtmlComments", regexForDump = "" ); stringsToRemove.append( result.reMatch( "" ), true ); result = service.reduceArrayAndReplaceString( stringsToRemove, result, "" ); - service.debugResult( htmlstring=result, label="Result" ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "compressBlankSpaces": function( htmlcontent ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="compressBlankSpaces" ); + service.debugResult( htmlstring = result, label = "compressBlankSpaces" ); stringsToRemove.append( result.reMatch( "[ \t]+" ), true ); // compress spaces/tabs to single spaces - result = service.reduceArrayAndReplaceString( stringsToRemove, result, " " ).reReplace( "\s+[\n\r]", chr(10), "ALL" ); - service.debugResult( htmlstring=result, label="Result" ); + result = service.reduceArrayAndReplaceString( stringsToRemove, result, " " ).reReplace( "\s+[\n\r]", chr( 10 ), "ALL" ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "compressNewLines": function( htmlcontent, replaceWith ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="compressNewLines" ); - + service.debugResult( htmlstring = result, label = "compressNewLines" ); + stringsToRemove.append( result.reMatch( "[\n\r]+" ), true ); // compress spaces/tabs to single spaces result = service.reduceArrayAndReplaceString( stringsToRemove, result, arguments.replaceWith ); - service.debugResult( htmlstring=result, label="Result" ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "stripEmptySpacesBetweenHtmlElements": function( htmlcontent, replaceWith ) { stringsToRemove = []; result = arguments.htmlcontent; - service.debugResult( htmlstring=result, label="stripEmptySpacesBetweenHtmlElements" ); + service.debugResult( htmlstring = result, label = "stripEmptySpacesBetweenHtmlElements" ); stringsToRemove.append( result.reMatch( ">\s+<" ), true ); // compress spaces/tabs to single spaces result = service.reduceArrayAndReplaceString( stringsToRemove, result, arguments.replaceWith ); - service.debugResult( htmlstring=result, label="Result" ); + service.debugResult( htmlstring = result, label = "Result" ); return result; }, "encodeTrustedHtml": function( required string htmlString ) { @@ -154,7 +154,7 @@ component output=false { if( argStripHtmlComments ) { result = service.stripHtmlComments( result ); } - + if( argStripScriptAndCssComments ) { result = service.stripMultlineComments( result ); result = service.stripSingleLineComments( result ); diff --git a/docs/index.html b/docs/index.html index d981ccc..c16980f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -HtmlHelper.cfc: minifyHtml() & encodeTrustedHtml() in your CFML Projects Fork me on GitHub

HtmlHelper.cfc (Vers. 0.9.3)


Minify your CFML generated HTML at runtime!

A simple basic CFML component to

1. minifyHtml( string html required )

Converts a whitespace poluted HTML block like this

        <!DOCTYPE html>
+HtmlHelper.cfc: minifyHtml() & encodeTrustedHtml() in your CFML Projects Fork me on GitHub

HtmlHelper.cfc (Vers. 0.9.4)


Minify your CFML generated HTML at runtime!

A simple basic CFML component to

  • minify CFML generated html content
  • encode trusted HTML content containing non-compliant/unescaped characters like e.g. €, ü, ö, ß, etc. within a tags inner HTML

1. minifyHtml( string html required )

Converts a whitespace poluted HTML block like this

        <!DOCTYPE html>
         <head>
 <title>Hot CFML Page & content</title>
                     <meta charset="utf-8">