-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5c2f6b5
Showing
48 changed files
with
5,695 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"alignment.consecutive.assignments":false, | ||
"alignment.consecutive.params":false, | ||
"alignment.consecutive.properties":false, | ||
"alignment.doc_comments":true, | ||
"array.empty_padding":false, | ||
"array.multiline.comma_dangle":false, | ||
"array.multiline.element_count":4, | ||
"array.multiline.leading_comma":false, | ||
"array.multiline.leading_comma.padding":false, | ||
"array.multiline.min_length":40, | ||
"array.padding":true, | ||
"binary_operators.newline_indent":false, | ||
"binary_operators.padding":true, | ||
"brackets.padding":true, | ||
"comment.asterisks":"align", | ||
"for_loop_semicolons.padding":true, | ||
"function_anonymous.empty_padding":false, | ||
"function_anonymous.group_to_block_spacing":"spaced", | ||
"function_anonymous.multiline.comma_dangle":false, | ||
"function_anonymous.multiline.element_count":4, | ||
"function_anonymous.multiline.leading_comma":false, | ||
"function_anonymous.multiline.leading_comma.padding":true, | ||
"function_anonymous.multiline.min_length":40, | ||
"function_anonymous.padding":false, | ||
"function_anonymous.spacing_to_group":false, | ||
"function_call.casing.builtin":"cfdocs", | ||
"function_call.casing.userdefined":"ignored", | ||
"function_call.empty_padding":false, | ||
"function_call.multiline.comma_dangle":false, | ||
"function_call.multiline.element_count":4, | ||
"function_call.multiline.leading_comma":false, | ||
"function_call.multiline.leading_comma.padding":true, | ||
"function_call.multiline.min_length":40, | ||
"function_call.padding":true, | ||
"function_declaration.empty_padding":false, | ||
"function_declaration.group_to_block_spacing":"spaced", | ||
"function_declaration.multiline.comma_dangle":false, | ||
"function_declaration.multiline.element_count":4, | ||
"function_declaration.multiline.leading_comma":false, | ||
"function_declaration.multiline.leading_comma.padding":true, | ||
"function_declaration.multiline.min_length":40, | ||
"function_declaration.padding":true, | ||
"function_declaration.spacing_to_group":false, | ||
"indent_size":4, | ||
"keywords.block_to_keyword_spacing":"spaced", | ||
"keywords.empty_group_spacing":false, | ||
"keywords.group_to_block_spacing":"spaced", | ||
"keywords.padding_inside_group":true, | ||
"keywords.spacing_to_block":"spaced", | ||
"keywords.spacing_to_group":false, | ||
"max_columns":1000, | ||
"metadata.key_value.padding":true, | ||
"metadata.multiline.element_count":4, | ||
"metadata.multiline.min_length":40, | ||
"method_call.chain.multiline":10, | ||
"newline":"os", | ||
"param.key_value.padding":true, | ||
"param.multiline.element_count":4, | ||
"param.multiline.min_length":40, | ||
"parentheses.padding":true, | ||
"property.key_value.padding":true, | ||
"property.multiline.element_count":4, | ||
"property.multiline.min_length":40, | ||
"strings.attributes.quote":"double", | ||
"strings.convertNestedQuotes":true, | ||
"strings.quote":"double", | ||
"struct.empty_padding":false, | ||
"struct.multiline.comma_dangle":false, | ||
"struct.multiline.element_count":4, | ||
"struct.multiline.leading_comma":false, | ||
"struct.multiline.leading_comma.padding":true, | ||
"struct.multiline.min_length":40, | ||
"struct.padding":true, | ||
"struct.quote_keys":false, | ||
"struct.separator":": ", | ||
"tab_indent":true, | ||
"tags.lowercase":true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Simple workflow for deploying static content to GitHub Pages | ||
name: Deploy static content to Pages | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["master"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Single deploy job since we're just deploying | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
# Upload entire repository | ||
path: './docs' | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
component displayname = "Application" output = "false" hint = "Handle the application" { | ||
|
||
this.charset.web = "UTF-8"; | ||
this.charset.resource = "UTF-8"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Claudio Andreas Rüger at https://www.rhein-berg-digital.de | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# HtmlHelper.cfc (Vers. 1.0.0) | ||
|
||
--- | ||
|
||
***Minify your CFML generated HTML at runtime!*** | ||
|
||
If you want to see an enhanced version of this page, please visit [https://andreasru.github.io/cfml-htmlhelper/](https://andreasru.github.io/cfml-htmlhelper/) | ||
|
||
## 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"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> /* some comment | ||
*/ | ||
.someClass{ | ||
font-size: 1rem; /* set font size */ } </style> | ||
|
||
<meta name="description" content="Just some Example"> | ||
<link rel="stylesheet" href="css/main.css"> | ||
</head> <body> | ||
<!-- Say "Hello" to the CFML coders! --> <p>Hello to all CFML devs 😀 🤩 around the 🌎!!! </p> | ||
<script> /* this is just some | ||
embedded JavaScript */ | ||
console.log('Log Something'); // this is just some Javascript </script> </body> </html> | ||
|
||
#### ... into a minified HTML version like this | ||
|
||
<!DOCTYPE html><head><title>Hot CFML Page & content</title><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><style> .someClass{ font-size: 1rem; } </style><meta name="description" content="Just some Example"><link rel="stylesheet" href="css/main.css"></head><body><p>Hello to all CFML devs 😀 🤩 around the 🌎!!! </p><script> console.log('Log Something');</script></body></html> | ||
|
||
The function `minifyHtml()` minifies CFML generated html content by: | ||
|
||
> - stripping HTML comments | ||
> - stripping JavaScript multline comments | ||
> - stripping JavaScript singleline comments | ||
> - stripping CSS comments | ||
> - stripping whitespaces, such as all double tabs/spaces/newlines | ||
> - honouring and preserving the content within `<pre></pre>` or `<code></code>` tags as submitted | ||
### 2. encodeTrustedHTML( string trustedHtml required ); | ||
|
||
#### Converts HTML from a trusted source with unencoded characters like this | ||
|
||
<div class="someClass"> | ||
I tend to add "€, ä, &, é, ß" and I | ||
even might tend to add a > (greater sign) | ||
directly into my html 😲, because I'm | ||
a lazy content writer and I don't like | ||
adding those as html encoded characters manually! | ||
</div> | ||
|
||
#### ... into proper html like this | ||
|
||
<div class="someClass"> I tend to add "€, ä, &, é, ß" and I even might tend to add a > (greater sign) directly into my html 😲, because I'm a lazy content writer and I don't like adding those as html encoded characters manually! </div> | ||
|
||
The function `encodeTrustedHTML()` detects and encodes unencoded characters, but preserves valid HTML-Entities and HTML-Tags already present in the submitted HTML. | ||
|
||
### 3. Examples | ||
|
||
Example of minifying a whitespace overfilled WordPress page with `minifyHtml()`: | ||
|
||
<!--- /examples/cfhttpMinifyHtml.cfm: minifyHtml() ---> | ||
<!--- Make sure to override admin setting and read template with correct charset(UTF-8) ---> | ||
<cfprocessingdirective pageEncoding="UTF-8"> | ||
<cfscript> | ||
// get whitespace polluted wordpress page! | ||
cfhttp(method="GET", charset="utf-8", url="https://news.microsoft.com/source/", result="result" ) {}; | ||
htmlHelperService=new components.HtmlHelper(); | ||
cfcontent( reset = "true" ); | ||
writeoutput( | ||
htmlHelperService.minifyHtml( result.filecontent ) | ||
); | ||
</cfscript> | ||
|
||
Example of encoding a trusted HTML block to escape unescaped characters with `encodeTrustedHtml()`: | ||
|
||
<!--- /examples/encodeTrustedHtml.cfm: encodeTrustedHtml() ---> | ||
<!--- Make sure to override admin setting and read template with correct charset(UTF-8) ---> | ||
<cfprocessingdirective pageEncoding="UTF-8"> | ||
<cfsavecontent variable="someHtmlBlock"> | ||
<div> | ||
I'm adding some unescaped HTML directly into my HTML! | ||
I't doesn't matter if they have already been encoded or not. | ||
E.g " & or & " will both create the same source. Add | ||
letters like ä, ö, Ä, ü, é, punctuations like ~, >, ⁋, ※, | ||
currencies like $, €, £, ¥, ₹, symbols like ©, ®, ™, Ω, | ||
arrows like →, ↖, ↳, ⇗, emojis like 👋 🤚 🖐 ✋ and they will be encoded properly. | ||
</div> | ||
</cfsavecontent> | ||
<cfscript> | ||
htmlHelperService=new components.HtmlHelper(); | ||
cfcontent( reset = "true" ); | ||
writeoutput( | ||
htmlHelperService.encodeTrustedHtml ( someHtmlBlock ) | ||
); | ||
</cfscript> | ||
|
||
### Service Functions as Lambda Expression | ||
|
||
**HtmlHelper.cfc** passes the functions minifyHtml() and encodeTrustedHtml() as Lambda Expressions to enhance inner local scoping ([see code here at GitHub](https://github.com/andreasRu/cfml-htmlhelper/blob/cc91c88a5e744a27d5006accb5ed9e54cd5e7dc5/components/HtmlHelper.cfc#L16)): | ||
|
||
![cfml html minifier](images/dumpStruct.webp) | ||
|
||
### Tips & Security Advisory | ||
|
||
> - **IMPORTANT SECURITY NOTICE:** `encodeTrustedHtml()` MUST NOT be used to avoid XSS, because it only encodes unencoded characters of the inner HTML (within the body of tags). This function will accept any submitted HTML, JavaScript and Styles and output it as submitted(!) without encoding it for XSS mitigation. For XSS prevention of untrusted HTML you **MUST** continue to use `encodeForHTML()`, `encodeForHTMLAttribute()`, `encodeForJavascript()`, `encodeFor...()` respectively. | ||
> - The Regex patterns are set to work with CFMLs default 'Perl' Regex-Engine | ||
> - When using `encodeTrustedHTML()` always make sure to keep all the charsets among the stream "in sync". Having different charsets for templates, web charset, charset http headers, or resource charsets may have unpredictable wrong html-entities and characters. | ||
> - `encodeTrustedHTML()` is typically used when you have a fronted CMS with a HTML-Editor where you can manually add custom HTML to a database. | ||
> - You get best performance when you use `minifyHtml()` only once during the request flow, e.g. at the end of the CFML processing. A good location could be the **Application.cfc** at the end of the `onRequest()` function. | ||
### Downloads | ||
|
||
> - **Raw HtmlHelper.cfc component**: [Download](https://raw.githubusercontent.com/andreasRu/cfml-htmlhelper/master/components/HtmlHelper.cfc) | ||
> - **Repository as ZIP-File**: [Download](https://github.com/andreasRu/cfml-htmlhelper/archive/refs/heads/master.zip) | ||
> - **Example minifyHtml()**: [Download](https://raw.githubusercontent.com/andreasRu/cfml-htmlhelper/master/examples/minifyHtml.cfm) | ||
> - **Example Cfhttp & minifyHtml()**: [Download](https://raw.githubusercontent.com/andreasRu/cfml-htmlhelper/master/examples/cfhttpMinifyHtml.cfm) | ||
> - **Example encodeTrustedHTML()**: [Download](https://raw.githubusercontent.com/andreasRu/cfml-htmlhelper/master/examples/encodeTrustedHtml.cfm) | ||
### Run repository locally | ||
|
||
To test or watch the code running locally, you'll need CommandBox as dependency: | ||
|
||
> 1. Download the [Repository as ZIP-File](https://github.com/andreasRu/cfml-htmlhelper/archive/refs/heads/master.zip) | ||
> 2. Unzip it | ||
> 3. Run `server.bat` on Windows or `server.sh`on MacOs/Linux | ||
> 4. Wait for commandBox open the browser and load the page | ||
### Donations | ||
|
||
I'm not taking anything for this but if you like or you're using it, I kindly ask you to donate to the **Lucee Organization** to make this awesome cfengine even better: | ||
|
||
[Lucee Open Collective Donation](https://opencollective.com/lucee) ❤️ | ||
|
||
### About | ||
|
||
> - **Author:** Andreas at [Rhein Berg Digital](https://www.rhein-berg-digital.de), <a href="https://www.linkedin.com/in/claudio-andreas-r%C3%BCger-259000199/" target="_blank" rel="nofollow">LinkedIn</a> | ||
> - **GitHub:** [cfml-htmlhelper](https://github.com/andreasRu/cfml-htmlhelper) | ||
> - **Issues/Requests:** [cfml-htmlhelper issues](https://github.com/andreasRu/cfml-htmlhelper/issues) | ||
> - **License:** [MIT License](https://github.com/andreasRu/cfml-htmlhelper/blob/master/LICENSE.txt) | ||
> - **Software :** [Lucee CFML Engine](https://www.lucee.org/) (GNU LGPL v2.1), [CommandBox](https://www.ortussolutions.com/products/commandbox) (GNU GPLv3), [highlight.js](https://highlightjs.org/) (BSD 3-Clause License, Copyright (c) 2006, Ivan Sagalaev), [normalize.css](https://github.com/necolas/normalize.css) (MIT License, Copyright (c) Nicolas Gallagher and Jonathan Neal), [github-fork-ribbon-css](https://codepo8.github.io/css-fork-on-github-ribbon/) (MIT License, Copyright (c) 2013 Simon Whitaker) | ||
> - **Imprint:** [Visit here](https://www.rhein-berg-digital.de/en/andreasru-github-io-imprint) | ||
> - **Privacy Policy:** [Visit the hosters Site Policy](https://docs.github.com/en/site-policy) and the [authors](https://www.rhein-berg-digital.de/en/andreasru-github-io-privacy-policy) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Description of task | ||
*/ | ||
component { | ||
|
||
/** | ||
* | ||
*/ | ||
function run() { | ||
var basePath = getDirectoryFromPath( getCurrentTemplatePath() ) & "../"; | ||
print.boldCyanLine( "Base path defined: " & basePath ); | ||
fileSystemUtil.createMapping( "components", basePath & "components" ); | ||
print.boldCyanLine( "Map 'components' created." ); | ||
cfhttp( | ||
method = "GET", | ||
charset = "utf-8", | ||
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 <a href=""https://andreasru.github.io/cfml-htmlhelper/"">https&##x3a;&##x2f;&##x2f;andreasru.github.io&##x2f;cfml-htmlhelper&##x2f;</a>","","ALL"); | ||
print.boldCyanLine( "Minifying content" ); | ||
minifiedfilecontent = htmlHelperService.minifyHtml( resultFinal ); | ||
print.boldCyanLine( "CfContent minified" ); | ||
|
||
print.boldCyanLine( "Writing static index.html to distro..." ); | ||
fileWrite( basePath & "docs/index.html", minifiedfilecontent, "utf-8" ); | ||
|
||
print.boldCyanLine( "Copying libs to distro..." ); | ||
directoryCopy( source = basePath & "libs", destination = basePath & "docs/libs", recurse = true ); | ||
|
||
print.boldCyanLine( "Copying images to distro..." ); | ||
directoryCopy( source = basePath & "images", destination = basePath & "docs/images", recurse = true ); | ||
|
||
|
||
print.GreenLine( "READY!" ); | ||
} | ||
|
||
} |
Oops, something went wrong.