forked from zamronypj/fano-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
17 changed files
with
955 additions
and
314 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,18 @@ | ||
This program contains | ||
--------------------------------------------------------------------------------- | ||
CSSMin | ||
https://www.gocher.me/CSSMin | ||
|
||
Copyright (c) 2007-2020, Udo Schmal <udo.schmal@t-online.de> | ||
|
||
Permission to use, copy, modify, and/or distribute the software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. | ||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR | ||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 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,52 @@ | ||
(*!------------------------------------------------------------ | ||
* Fano CLI Application (https://fanoframework.github.io) | ||
* | ||
* @link https://github.com/fanoframework/fano-cli | ||
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara | ||
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) | ||
*------------------------------------------------------------- *) | ||
unit MinifierIntf; | ||
|
||
interface | ||
|
||
{$MODE OBJFPC} | ||
{$H+} | ||
|
||
type | ||
|
||
(*!-------------------------------------- | ||
* Interface for class that having capability | ||
* to minify string | ||
* | ||
* @author Zamrony P. Juhara <zamronypj@yahoo.com> | ||
*---------------------------------------*) | ||
IMinifier = interface | ||
['{64B1B128-EB1A-46A7-8385-42B2A10656C3}'] | ||
|
||
(*!-------------------------------------- | ||
* minify type, for example 'css', 'js' | ||
*--------------------------------------- | ||
* @return minified type | ||
*---------------------------------------*) | ||
function contentType() : string; | ||
|
||
(*!-------------------------------------- | ||
* minify string | ||
*--------------------------------------- | ||
* @param inputStr input string to minify | ||
* @return minified string | ||
*---------------------------------------*) | ||
function minify(const inputStr : string) : string; | ||
|
||
(*!-------------------------------------- | ||
* minify file | ||
*--------------------------------------- | ||
* @param inputFile path of file to minify | ||
* @param outputFile path of minified file | ||
*---------------------------------------*) | ||
procedure minifyFile(const inputFile : string; const outputFile : string); | ||
end; | ||
|
||
implementation | ||
|
||
end. |
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,94 @@ | ||
(*!------------------------------------------------------------ | ||
* Fano CLI Application (https://fanoframework.github.io) | ||
* | ||
* @link https://github.com/fanoframework/fano-cli | ||
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara | ||
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) | ||
*------------------------------------------------------------- *) | ||
unit CssMinifierImpl; | ||
|
||
interface | ||
|
||
{$MODE OBJFPC} | ||
{$H+} | ||
|
||
uses | ||
|
||
MinifierIntf; | ||
|
||
type | ||
|
||
(*!-------------------------------------- | ||
* Interface for class that having capability | ||
* to minify CSS | ||
* | ||
* @author Zamrony P. Juhara <zamronypj@yahoo.com> | ||
*---------------------------------------*) | ||
TCssMinifier = class (TInterfacedObject, IMinifier) | ||
public | ||
(*!-------------------------------------- | ||
* minify type, for example 'css', 'js' | ||
*--------------------------------------- | ||
* @return minified type | ||
*---------------------------------------*) | ||
function contentType() : string; | ||
|
||
(*!-------------------------------------- | ||
* minify string | ||
*--------------------------------------- | ||
* @param inputStr input string to minify | ||
* @return minified string | ||
*---------------------------------------*) | ||
function minify(const inputStr : string) : string; | ||
|
||
(*!-------------------------------------- | ||
* minify file | ||
*--------------------------------------- | ||
* @param inputFile path of file to minify | ||
* @param outputFile path of minified file | ||
*---------------------------------------*) | ||
procedure minifyFile(const inputFile : string; const outputFile : string); | ||
end; | ||
|
||
implementation | ||
|
||
uses | ||
|
||
Classes, | ||
SysUtils, | ||
cssmin; | ||
|
||
(*!-------------------------------------- | ||
* minify type | ||
*--------------------------------------- | ||
* @return minified type | ||
*---------------------------------------*) | ||
function TCssMinifier.contentType() : string; | ||
begin | ||
result := 'css'; | ||
end; | ||
|
||
(*!-------------------------------------- | ||
* minify string | ||
*--------------------------------------- | ||
* @param inputStr input string to minify | ||
* @return minified string | ||
*---------------------------------------*) | ||
function TCssMinifier.minify(const inputStr : string) : string; | ||
begin | ||
result := cssmin.cssMin(inputStr); | ||
end; | ||
|
||
|
||
(*!-------------------------------------- | ||
* minify file | ||
*--------------------------------------- | ||
* @param inputFile path of file to minify | ||
* @param outputFile path of minified file | ||
*---------------------------------------*) | ||
procedure TCssMinifier.minifyFile(const inputFile : string; const outputFile : string); | ||
begin | ||
cssMinFile(inputFile, outputFile); | ||
end; | ||
|
||
end. |
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,122 @@ | ||
(*!------------------------------------------------------------ | ||
* Fano CLI Application (https://fanoframework.github.io) | ||
* | ||
* @link https://github.com/fanoframework/fano-cli | ||
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara | ||
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT) | ||
*------------------------------------------------------------- *) | ||
unit JsMinifierImpl; | ||
|
||
interface | ||
|
||
{$MODE OBJFPC} | ||
{$H+} | ||
|
||
uses | ||
|
||
MinifierIntf, | ||
jsminifier; | ||
|
||
type | ||
|
||
(*!-------------------------------------- | ||
* Interface for class that having capability | ||
* to minify JS | ||
* | ||
* @author Zamrony P. Juhara <zamronypj@yahoo.com> | ||
*---------------------------------------*) | ||
TJsMinifier = class (TInterfacedObject, IMinifier) | ||
private | ||
fMinifier : TJSONMinifier; | ||
public | ||
constructor create(); | ||
destructor destroy(); override; | ||
|
||
(*!-------------------------------------- | ||
* minify type, for example 'css', 'js' | ||
*--------------------------------------- | ||
* @return minified type | ||
*---------------------------------------*) | ||
function contentType() : string; | ||
|
||
(*!-------------------------------------- | ||
* minify string | ||
*--------------------------------------- | ||
* @param inputStr input string to minify | ||
* @return minified string | ||
*---------------------------------------*) | ||
function minify(const inputStr : string) : string; | ||
|
||
(*!-------------------------------------- | ||
* minify file | ||
*--------------------------------------- | ||
* @param inputFile path of file to minify | ||
* @param outputFile path of minified file | ||
*---------------------------------------*) | ||
procedure minifyFile(const inputFile : string; const outputFile : string); | ||
end; | ||
|
||
implementation | ||
|
||
uses | ||
|
||
Classes, | ||
SysUtils; | ||
|
||
constructor TJsMinifier.create(); | ||
begin | ||
fMinifier := TJSONMinifier.create(nil); | ||
end; | ||
|
||
destructor TJsMinifier.destroy(); | ||
begin | ||
fMinifier.free(); | ||
inherited destroy(); | ||
end; | ||
|
||
(*!-------------------------------------- | ||
* minify type | ||
*--------------------------------------- | ||
* @return minified type | ||
*---------------------------------------*) | ||
function TJsMinifier.contentType() : string; | ||
begin | ||
result := 'js'; | ||
end; | ||
|
||
(*!-------------------------------------- | ||
* minify string | ||
*--------------------------------------- | ||
* @param inputStr input string to minify | ||
* @return minified string | ||
*---------------------------------------*) | ||
function TJsMinifier.minify(const inputStr : string) : string; | ||
var asrc, adst : TStringStream; | ||
begin | ||
asrc := TStringStream.create(inputStr); | ||
try | ||
adst := TStringStream.create(''); | ||
try | ||
fMinifier.execute(asrc, adst); | ||
result := adst.datastring; | ||
finally | ||
adst.free(); | ||
end; | ||
finally | ||
asrc.free(); | ||
end; | ||
end; | ||
|
||
|
||
(*!-------------------------------------- | ||
* minify file | ||
*--------------------------------------- | ||
* @param inputFile path of file to minify | ||
* @param outputFile path of minified file | ||
*---------------------------------------*) | ||
procedure TJsMinifier.minifyFile(const inputFile : string; const outputFile : string); | ||
begin | ||
fMinifier.execute(inputFile, outputFile); | ||
end; | ||
|
||
end. |
Oops, something went wrong.