Skip to content

Commit

Permalink
Init Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasRu committed Aug 8, 2023
1 parent 9717acb commit 3b5f67a
Show file tree
Hide file tree
Showing 50 changed files with 5,682 additions and 1 deletion.
79 changes: 79 additions & 0 deletions .cfformat.json
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
}
43 changes: 43 additions & 0 deletions .github/workflows/static.yml
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
6 changes: 6 additions & 0 deletions Application.cfc
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";

}
21 changes: 21 additions & 0 deletions LICENSE.txt
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.
153 changes: 153 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# HtmlHelper.cfc

---

***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">
<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 &amp; 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 &#x1f600; &#x1f929; around the &#x1f30e;&#x21;&#x21;&#x21; </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 )&#59;

#### 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 &quot;&euro;, &auml;, &amp;, &eacute;, &szlig;&quot; and I even might tend to add a &gt; &#x28;greater sign&#x29; directly into my html &#x1f632;, because I&#x27;m a lazy content writer and I don&#x27;t like adding those as html encoded characters manually&#x21; </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 " &amp; 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 ensure inner a better 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 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 sharing with you. If you like/are 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:** &nbsp;[cfml-htmlhelper](https://github.com/andreasRu/cfml-htmlhelper)
> - **Issues/Requests:** &nbsp;[cfml-htmlhelper issues](https://github.com/andreasRu/cfml-htmlhelper/issues)
> - **License:** &nbsp;[MIT License](https://github.com/andreasRu/cfml-htmlhelper/blob/master/LICENSE.txt)
> - **Software :**&nbsp;[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:** &nbsp;[Visit here](https://www.rhein-berg-digital.de/en/andreasru-github-io-imprint)
> - **Privacy Policy:** &nbsp;[Visit the hosters Site Policy](https://docs.github.com/en/site-policy) and the [authors](https://www.rhein-berg-digital.de/en/lucee-admin-lang-editor-privacy-policy)
42 changes: 42 additions & 0 deletions cftasks/generateStaticHTML.cfc
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();

print.boldCyanLine( "Minifying content" );
minifiedfilecontent = htmlHelperService.minifyHtml( result.filecontent );
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!" );
}

}
Loading

0 comments on commit 3b5f67a

Please sign in to comment.