Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a post-processing step to publish the PHP package
avoids the need for using output buffering, and removes all HTML comments from the source code.
- Loading branch information
Showing
7 changed files
with
170 additions
and
12 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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "tantek/cassis", | ||
"autoload": { | ||
"files": ["cassis-loader.php"] | ||
"files": ["cassis.php"] | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
// A few tests to make sure the post-processing actually stopped the source from outputting content | ||
class PostProcessTest extends PHPUnit_Framework_TestCase { | ||
|
||
public function testEllipsize() { | ||
ob_start(); | ||
$short = ellipsize_to_word('some text', 40, '...', 10); | ||
$result = ob_get_clean(); | ||
$this->assertEquals('', $result); | ||
} | ||
|
||
public function testBase60() { | ||
ob_start(); | ||
num_to_sxg(503194); | ||
$result = ob_get_clean(); | ||
$this->assertEquals('', $result); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
<?php | ||
ob_start(); | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
ob_end_clean(); |
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,27 @@ | ||
<?php | ||
/* | ||
* After making changes to cassis.js, run this file to transform the JS into | ||
* native PHP code. This process involves removing all PHP and HTML comments, | ||
* so that no comment hacks or output buffering is required in order to use | ||
* Cassis in PHP. | ||
*/ | ||
|
||
// Load the source code, stripping any comments and whitespace from the PHP source | ||
$source = php_strip_whitespace('cassis.js'); | ||
|
||
// Remove the top comment that talks about using ob_start | ||
$source = preg_replace('/\/\* <!--.+\n\/\* <!-- /Usm', '', $source); | ||
|
||
// Remove HTML comments | ||
$source = preg_replace('/<!--(.|\s)*?-->/', '', $source); | ||
|
||
// Remove close/open PHP tags | ||
$source = preg_replace('/\?>\s+<\?php/', '', $source); | ||
|
||
// Remove trailing HTML comment tag (and PHP tag since we can do that safely) | ||
$source = preg_replace('/\?> -->$/', '', $source); | ||
|
||
// Put each function on its own line | ||
$source = preg_replace('/function /', "\n$0", $source); | ||
|
||
file_put_contents('cassis.php', $source); |