Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Nov 26, 2020
2 parents b083624 + 2535121 commit 69d4667
Show file tree
Hide file tree
Showing 17 changed files with 955 additions and 314 deletions.
18 changes: 18 additions & 0 deletions NOTICE
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.
---------------------------------------------------------------------------------
52 changes: 52 additions & 0 deletions src/Libs/Minifier/Contracts/MinifierIntf.pas
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.
94 changes: 94 additions & 0 deletions src/Libs/Minifier/Implementations/CssMinifierImpl.pas
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.
122 changes: 122 additions & 0 deletions src/Libs/Minifier/Implementations/JsMinifierImpl.pas
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.
Loading

0 comments on commit 69d4667

Please sign in to comment.