-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: php lint added Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * improvement of the code Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * moving debug message to helper Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * refactor: removal of package discover due to stand-alone package Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding HtmlCompressor class Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding HtmlCompressor class Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding HtmlCompressor class Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * refactor: SideEffects fix Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding php configuration class and test Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding phplint in ci/cd Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding yui compressor Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> * adding online reference for the yui compressor Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com> --------- Signed-off-by: Vallabh Kansagara <vrkansagara@gmail.com>
- Loading branch information
1 parent
28f54a8
commit d660b27
Showing
18 changed files
with
394 additions
and
220 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
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,7 @@ | ||
|
||
### yui compresso info | ||
|
||
~~~bash | ||
http://yui.github.io/yuicompressor/ | ||
cat test.js | java -jar ../bin/yuicompressor-2.4.8.jar --type=js > test.min.js | ||
~~~ |
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,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
find "$1" -type f \ | ||
-path "$(pwd)/vendor/*" -prune -o \ | ||
-wholename "$(pwd)/*.php" -print0 | \ | ||
xargs -0 -n1 -P4 php -l -n -d error_reporting="E_ALL" | \ | ||
(! grep -v "No syntax errors detected" ) |
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
alert('Test'); |
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
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,152 @@ | ||
<?php | ||
|
||
namespace Vrkansagara\LaraOutPress; | ||
|
||
/** | ||
* @copyright Copyright (c) 2015-2023 Vallabh Kansagara <vrkansagara@gmail.com> | ||
* @license https://opensource.org/licenses/BSD-3-Clause New BSD License | ||
*/ | ||
class HtmlCompressor | ||
{ | ||
public function init(string $content) | ||
{ | ||
$whiteSpaceRules = [ | ||
'/(\s)+/s' => '\\1',// shorten multiple whitespace sequences | ||
"#>\s+<#" => ">\n<", // Strip excess whitespace using new line | ||
"#\n\s+<#" => "\n<",// strip excess whitespace using new line | ||
'/\>[^\S ]+/s' => '>', | ||
// Strip all whitespaces after tags, except space | ||
'/[^\S ]+\</s' => '<',// strip whitespaces before tags, except space | ||
/** | ||
* '/\s+ # Match one or more whitespace characters | ||
* (?! # but only if it is impossible to match... | ||
* [^<>]* # any characters except angle brackets | ||
* > # followed by a closing bracket. | ||
* ) # End of lookahead | ||
* /x', | ||
*/ | ||
|
||
//Remove all whitespaces except content between html tags. | ||
//MOST DANGEROUS | ||
// '/\s+(?![^<>]*>)/x' => '', | ||
]; | ||
$commentRules = [ | ||
"/<!--.*?-->/ms" => '',// Remove all html comment., | ||
]; | ||
$replaceWords = [ | ||
//OldWord will be replaced by the NewWord | ||
// OldWord <-> NewWord DO NOT REMOVE THIS LINE. {REFERENCE LINE} | ||
//'/\bOldWord\b/i' =>'NewWord' | ||
]; | ||
|
||
$allRules = array_merge( | ||
$replaceWords, | ||
$commentRules, | ||
$whiteSpaceRules | ||
); | ||
|
||
$buffer = $this->compressJscript($content); | ||
$buffer = preg_replace( | ||
array_keys($allRules), | ||
array_values($allRules), | ||
$buffer | ||
); | ||
return $buffer; | ||
} | ||
/** | ||
* This method will no longer support. | ||
* | ||
* @note Code arked as @deprecated but for reference only. | ||
* @param $buffer | ||
* @return null|string|string[] Compressed output | ||
* @deprecated | ||
* | ||
*/ | ||
public static function compress($buffer) | ||
{ | ||
/** | ||
* To remove useless whitespace from generated HTML, except for Javascript. | ||
* [Regex Source] | ||
* https://github.com/bcit-ci/codeigniter/wiki/compress-html-output | ||
* http://stackoverflow.com/questions/5312349/minifying-final-html-output-using-regular-expressions-with-codeigniter | ||
* %# Collapse ws everywhere but in blacklisted elements. | ||
* (?> # Match all whitespaces other than single space. | ||
* [^\S ]\s* # Either one [\t\r\n\f\v] and zero or more ws, | ||
* | \s{2,} # or two or more consecutive-any-whitespace. | ||
* ) # Note: The remaining regex consumes no text at all... | ||
* (?= # Ensure we are not in a blacklist tag. | ||
* (?: # Begin (unnecessary) group. | ||
* (?: # Zero or more of... | ||
* [^<]++ # Either one or more non-"<" | ||
* | < # or a < starting a non-blacklist tag. | ||
* (?!/?(?:textarea|pre)\b) | ||
* )*+ # (This could be "unroll-the-loop"ified.) | ||
* ) # End (unnecessary) group. | ||
* (?: # Begin alternation group. | ||
* < # Either a blacklist start tag. | ||
* (?>textarea|pre)\b | ||
* | \z # or end of file. | ||
* ) # End alternation group. | ||
* ) # If we made it here, we are not in a blacklist tag. | ||
* %ix | ||
*/ | ||
$regexRemoveWhiteSpace | ||
= '%(?>[^\S ]\s*| \s{2,})(?=(?:(?:[^<]++| <(?!/?(?:textarea|pre)\b))*+)(?:<(?>textarea|pre)\b|\z))%ix'; | ||
$new_buffer = preg_replace($regexRemoveWhiteSpace, '', $buffer); | ||
// We are going to check if processing has working | ||
if ($new_buffer === null) { | ||
$new_buffer = $buffer; | ||
} | ||
|
||
return $new_buffer; | ||
} | ||
|
||
public function compressJscript($buffer) | ||
{ | ||
// JavaScript compressor by John Elliot <jj5@jj5.net> | ||
$replace = [ | ||
'#\'([^\n\']*?)/\*([^\n\']*)\'#' => "'\1/'+\'\'+'*\2'", | ||
// remove comments from ' strings | ||
'#\"([^\n\"]*?)/\*([^\n\"]*)\"#' => '"\1/"+\'\'+"*\2"', | ||
// remove comments from " strings | ||
'#/\*.*?\*/#s' => "",// strip C style comments | ||
'#[\r\n]+#' => "\n", | ||
// remove blank lines and \r's | ||
'#\n([ \t]*//.*?\n)*#s' => "\n", | ||
// strip line comments (whole line only) | ||
'#([^\\])//([^\'"\n]*)\n#s' => "\\1\n", | ||
// strip line comments | ||
// (that aren't possibly in strings or regex's) | ||
'#\n\s+#' => "\n",// strip excess whitespace | ||
'#\s+\n#' => "\n",// strip excess whitespace | ||
'#(//[^\n]*\n)#s' => "\\1\n", | ||
// extra line feed after any comments left | ||
// (important given later replacements) | ||
'#/([\'"])\+\'\'\+([\'"])\*#' => "/*" | ||
// restore comments in strings | ||
]; | ||
$script = preg_replace(array_keys($replace), $replace, $buffer); | ||
$replace = [ | ||
"&&\n" => "&&", | ||
"||\n" => "||", | ||
"(\n" => "(", | ||
")\n" => ")", | ||
"[\n" => "[", | ||
"]\n" => "]", | ||
"+\n" => "+", | ||
",\n" => ",", | ||
"?\n" => "?", | ||
":\n" => ":", | ||
";\n" => ";", | ||
"{\n" => "{", | ||
// "}\n" => "}", (because I forget to put semicolons after function assignments) | ||
"\n]" => "]", | ||
"\n)" => ")", | ||
"\n}" => "}", | ||
"\n\n" => "\n", | ||
]; | ||
$script = str_replace(array_keys($replace), $replace, $script); | ||
return trim($script); | ||
} | ||
} |
Oops, something went wrong.