Code style updates.
This commit is contained in:
+1
-4
@@ -819,10 +819,7 @@ class Mustache {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _getPartial($tag_name) {
|
protected function _getPartial($tag_name) {
|
||||||
if (
|
if ((is_array($this->_partials) || $this->_partials instanceof ArrayAccess) && isset($this->_partials[$tag_name])) {
|
||||||
(is_array($this->_partials) || $this->_partials instanceof ArrayAccess)
|
|
||||||
&& isset($this->_partials[$tag_name])
|
|
||||||
) {
|
|
||||||
return $this->_partials[$tag_name];
|
return $this->_partials[$tag_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
-37
@@ -2,12 +2,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A commandline script to create an example and the needed files
|
* A commandline script to create an example and the needed files:
|
||||||
* use like this:
|
|
||||||
* $ bin/create_example.php my_new_example
|
|
||||||
*
|
*
|
||||||
* and the folder my_new_example will be created in the examples/ folder containing 3 files
|
* $ bin/create_example.php my_new_example
|
||||||
*
|
*
|
||||||
|
* ... and the folder my_new_example will be created in the examples/ folder containing 3 files:
|
||||||
|
*
|
||||||
|
* my_new_example/my_new_example.mustache
|
||||||
|
* my_new_example/my_new_example.txt
|
||||||
|
* my_new_example/MyNewExample.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// some constants
|
// some constants
|
||||||
@@ -36,10 +39,10 @@ define('EXAMPLE_PATH', realpath(dirname(__FILE__) . DS . ".." . DS . "examples")
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getLowerCaseName($name) {
|
function getLowerCaseName($name) {
|
||||||
return preg_replace_callback("/([A-Z])/", create_function (
|
return preg_replace_callback("/([A-Z])/", create_function (
|
||||||
'$match',
|
'$match',
|
||||||
'return "_" . strtolower($match[1]);'
|
'return "_" . strtolower($match[1]);'
|
||||||
), lcfirst($name));
|
), lcfirst($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,10 +58,10 @@ function getLowerCaseName($name) {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getUpperCaseName($name) {
|
function getUpperCaseName($name) {
|
||||||
return preg_replace_callback("/_([a-z])/", create_function (
|
return preg_replace_callback("/_([a-z])/", create_function (
|
||||||
'$match',
|
'$match',
|
||||||
'return strtoupper($match{1});'
|
'return strtoupper($match{1});'
|
||||||
), ucfirst($name));
|
), ucfirst($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,8 +73,8 @@ function getUpperCaseName($name) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function out($value) {
|
function out($value) {
|
||||||
echo $value . "\n";
|
echo $value . "\n";
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,8 +90,8 @@ function out($value) {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function buildPath($directory, $filename = null, $extension = null) {
|
function buildPath($directory, $filename = null, $extension = null) {
|
||||||
return out(EXAMPLE_PATH . DS . $directory.
|
return out(EXAMPLE_PATH . DS . $directory.
|
||||||
($extension !== null && $filename !== null ? DS . $filename. "." . $extension : ""));
|
($extension !== null && $filename !== null ? DS . $filename. "." . $extension : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,9 +103,9 @@ function buildPath($directory, $filename = null, $extension = null) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function createDirectory($directory) {
|
function createDirectory($directory) {
|
||||||
if(!@mkdir(buildPath($directory))) {
|
if(!@mkdir(buildPath($directory))) {
|
||||||
die("FAILED to create directory\n");
|
die("FAILED to create directory\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,13 +120,13 @@ function createDirectory($directory) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function createFile($directory, $filename, $extension, $content = "") {
|
function createFile($directory, $filename, $extension, $content = "") {
|
||||||
$handle = @fopen(buildPath($directory, $filename, $extension), "w");
|
$handle = @fopen(buildPath($directory, $filename, $extension), "w");
|
||||||
if($handle) {
|
if($handle) {
|
||||||
fwrite($handle, $content);
|
fwrite($handle, $content);
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
} else {
|
} else {
|
||||||
die("FAILED to create file\n");
|
die("FAILED to create file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,12 +144,12 @@ function createFile($directory, $filename, $extension, $content = "") {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function main($example_name) {
|
function main($example_name) {
|
||||||
$lowercase = getLowerCaseName($example_name);
|
$lowercase = getLowerCaseName($example_name);
|
||||||
$uppercase = getUpperCaseName($example_name);
|
$uppercase = getUpperCaseName($example_name);
|
||||||
createDirectory($lowercase);
|
createDirectory($lowercase);
|
||||||
createFile($lowercase, $lowercase, "mustache");
|
createFile($lowercase, $lowercase, "mustache");
|
||||||
createFile($lowercase, $lowercase, "txt");
|
createFile($lowercase, $lowercase, "txt");
|
||||||
createFile($lowercase, $uppercase, "php", <<<CONTENT
|
createFile($lowercase, $uppercase, "php", <<<CONTENT
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class {$uppercase} extends Mustache {
|
class {$uppercase} extends Mustache {
|
||||||
@@ -154,16 +157,16 @@ class {$uppercase} extends Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CONTENT
|
CONTENT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if enougth arguments are given
|
// check if enougth arguments are given
|
||||||
if(count($argv) > 1) {
|
if(count($argv) > 1) {
|
||||||
// get the name of the example
|
// get the name of the example
|
||||||
$example_name = $argv[1];
|
$example_name = $argv[1];
|
||||||
|
|
||||||
main($example_name);
|
main($example_name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo USAGE;
|
echo USAGE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user