Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improving logging, error reporting and error handling:

- Don't include inner exception messages in new exceptions.
- Show exception stack anywhere and exception is displayed.
- `debug` mode should now only be for showing source code (call stacks, etc.)
- `debug` mode gets correctly set in `chef serve`.
- Server now supports configuration variants.
- Simplified code for applying configuration variants.
- Removed useless banner from baker output and CLI.
- Use pretty colors on Mac/Linux for console output when baking or serving.
- Re-added all `chef` commands to the parser, regardless of whether the current
  directory is a website or not. That was pretty stupid actually.
- Global options like `--root` or `--debug` are now really global.
- Added a cache key to help invalidate cached config files when a breaking code
  change is written.
- Modified the system error pages to show updated information about error
  reporting.

--HG--
rename : build/messages/_content/pages/404.html => build/messages/_content/pages/error404.html
  • Loading branch information...
commit 14ecf26deb3b3a8e272abb59a7847e12b3dd223f 1 parent cf8cc92
@ludovicchabant authored
Showing with 1,241 additions and 259 deletions.
  1. +2 −3 build/messages/_content/pages/_index.html
  2. 0  build/messages/_content/pages/{404.html → error404.html}
  3. +0 −20 build/messages/_content/pages/welcome.html
  4. +1 −4 build/messages/_content/templates/error.html
  5. +55 −19 composer.lock
  6. +1 −1  libs/autoload.php
  7. +47 −14 libs/composer/ClassLoader.php
  8. +6 −6 libs/composer/autoload_classmap.php
  9. +1 −0  libs/composer/autoload_namespaces.php
  10. +15 −7 libs/composer/autoload_real.php
  11. +52 −2 libs/composer/installed.json
  12. +297 −0 libs/pear/Console/Color2.php
  13. +297 −0 libs/pear/Console_Color2/Console/Color2.php
  14. +19 −0 libs/pear/Console_Color2/LICENSE
  15. +19 −0 libs/pear/Console_Color2/README
  16. +28 −0 libs/pear/Console_Color2/composer.json
  17. +109 −0 libs/pear/Console_Color2/package.xml
  18. +1 −4 res/messages/critical.html
  19. +1 −4 res/messages/error.html
  20. +3 −23 res/messages/{welcome.html → error404.html}
  21. +7 −3 src/PieCrust/Baker/PageBaker.php
  22. +34 −40 src/PieCrust/Baker/PieCrustBaker.php
  23. +1 −1  src/PieCrust/Baker/ProcessingTreeRunner.php
  24. +35 −28 src/PieCrust/Chef/Chef.php
  25. +61 −0 src/PieCrust/Chef/ChefLog.php
  26. +0 −8 src/PieCrust/Chef/Commands/BakeCommand.php
  27. +12 −3 src/PieCrust/Chef/Commands/ServeCommand.php
  28. +1 −1  src/PieCrust/Data/PieCrustData.php
  29. +2 −2 src/PieCrust/Page/PageLoader.php
  30. +69 −33 src/PieCrust/PieCrustConfiguration.php
  31. +16 −0 src/PieCrust/PieCrustDefaults.php
  32. +17 −27 src/PieCrust/Runner/PieCrustErrorHandler.php
  33. +32 −6 src/PieCrust/Server/PieCrustServer.php
View
5 build/messages/_content/pages/_index.html
@@ -4,10 +4,9 @@
Here are the **PieCrust** system message pages:
-* [New Website Welcome]({{ pcurl('welcome') }})
* [Requirements Not Met]({{ pcurl('requirements') }})
-* [Not Found]({{ pcurl('404') }})
* [Error]({{ pcurl('error') }})
+* [Not Found]({{ pcurl('error404') }})
* [Critical Error]({{ pcurl('critical') }})
-This very page you're ready, however, is only here for convenience.
+This very page you're reading, however, is only here for convenience.
View
0  build/messages/_content/pages/404.html → build/messages/_content/pages/error404.html
File renamed without changes
View
20 build/messages/_content/pages/welcome.html
@@ -1,20 +0,0 @@
----
-title: Welcome To Your New Website
----
-
-It looks like you have a fresh install of **PieCrust**. Thanks for downloading
-it and trying it out! You're almost ready to start writing your own stuff:
-
-* Create a `_content` directory at the root of your website (probably next to the
- `_piecrust` directory).
-* Inside it, create the following:
- * A `config.yml` text file (this will contain your website's global settings, like its title).
- * A `templates` directory (this will contain things like HTML layouts).
- * A `pages` directory (this will contain the contents of your pages).
-* Create a default template, appropriately called `default.html`. Use the
- {% raw %}`{{content|raw}}`{% endraw %} tag to indicate where the page contents
- should go.
-* Create your main page, called `_index.html` and put whatever you want in it.
-* Refresh your browser!
-
-For more information, be sure to check out the [documentation](http://bolt80.com/piecrust/doc).
View
5 build/messages/_content/templates/error.html
@@ -2,9 +2,6 @@
{% block footer %}
{% pcformat textile %}
-p(note). To see your custom error pages, make sure you don't initialize *PieCrust*
- with the @debug@ parameter, and don't turn on the @site/display_errors@ configuration
- setting. To see detailed errors, on the other hand, use the @--debug@ parameter
- in @chef@, append @?!debug@ to the URL, or turn on @site/display_errors@.
+p(note). You're seeing this because something wrong happend. To see detailed errors with callstacks, run chef with the @--debug@ parameter, append @?!debug@ to the URL, or initialize the @PieCrust@ object with @{'debug'=>true}@. On the other hand, to see you custom error pages, set the @site/display_errors@ setting to @false@.
{% endpcformat %}
{% endblock %}
View
74 composer.lock
@@ -1,5 +1,5 @@
{
- "hash": "1acb904b9147801ea29d7d90d09b6616",
+ "hash": "1580c1c230a5e9d9829869ec71835d82",
"packages": [
{
"name": "bolt80/stupidhttp",
@@ -19,7 +19,6 @@
"php": ">= 5.3.0"
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"psr-0": {
"StupidHttp_": "lib"
@@ -38,9 +37,9 @@
"homepage": "http://bolt80.com/stupidhttp",
"keywords": [
"http",
- "web",
+ "net",
"server",
- "net"
+ "web"
]
},
{
@@ -53,7 +52,6 @@
"shasum": null
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"classmap": [
"geshi.php"
@@ -70,7 +68,6 @@
"shasum": null
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"classmap": [
"lessc.inc.php",
@@ -87,8 +84,7 @@
"reference": null,
"shasum": null
},
- "type": "library",
- "installation-source": "dist"
+ "type": "library"
},
{
"name": "markdown/markdown-extra",
@@ -99,8 +95,7 @@
"reference": null,
"shasum": null
},
- "type": "library",
- "installation-source": "dist"
+ "type": "library"
},
{
"name": "mikey179/vfsStream",
@@ -120,7 +115,6 @@
"php": ">=5.3.0"
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs": "src/main/php"
@@ -141,7 +135,6 @@
"shasum": null
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"classmap": [
"Mustache.php",
@@ -150,6 +143,54 @@
}
},
{
+ "name": "pear/Console_Color2",
+ "version": "0.1.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/pear/Console_Color2",
+ "reference": "0.1.2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/pear/Console_Color2/zipball/0.1.2",
+ "reference": "0.1.2",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.0.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Console_Color2": ""
+ }
+ },
+ "notification-url": "http://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Daniel O'Connor",
+ "email": "daniel.oconnor@gmail.com"
+ },
+ {
+ "name": "Stefan Walk",
+ "email": "et@php.net"
+ },
+ {
+ "name": "Scott Mattocks",
+ "email": "scottmattocks@php.net"
+ }
+ ],
+ "description": "This Class allows you to easily use ANSI console colors in your application.",
+ "homepage": "https://github.com/pear/Console_Color2",
+ "keywords": [
+ "console"
+ ],
+ "time": "2012-10-23 04:52:18"
+ },
+ {
"name": "smartypants/smartypants",
"version": "1.0",
"dist": {
@@ -158,8 +199,7 @@
"reference": null,
"shasum": null
},
- "type": "library",
- "installation-source": "dist"
+ "type": "library"
},
{
"name": "smartypants/smartypants-typographer",
@@ -170,8 +210,7 @@
"reference": null,
"shasum": null
},
- "type": "library",
- "installation-source": "dist"
+ "type": "library"
},
{
"name": "symfony/yaml",
@@ -192,7 +231,6 @@
"php": ">=5.3.2"
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Yaml": ""
@@ -228,7 +266,6 @@
"shasum": null
},
"type": "library",
- "installation-source": "dist",
"autoload": {
"classmap": [
"classTextile.php"
@@ -258,7 +295,6 @@
"dev-master": "1.8-dev"
}
},
- "installation-source": "dist",
"autoload": {
"psr-0": {
"Twig_": "lib/"
View
2  libs/autoload.php
@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
-return ComposerAutoloaderInit::getLoader();
+return ComposerAutoloaderInit00e7b338a0a4cad77486eca10d4846fc::getLoader();
View
61 libs/composer/ClassLoader.php
@@ -75,31 +75,64 @@ public function addClassMap(array $classMap)
}
/**
- * Registers a set of classes
+ * Registers a set of classes, merging with any others previously set.
*
- * @param string $prefix The classes prefix
- * @param array|string $paths The location(s) of the classes
+ * @param string $prefix The classes prefix
+ * @param array|string $paths The location(s) of the classes
+ * @param bool $prepend Prepend the location(s)
*/
- public function add($prefix, $paths)
+ public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
- foreach ((array) $paths as $path) {
- $this->fallbackDirs[] = $path;
+ if ($prepend) {
+ $this->fallbackDirs = array_merge(
+ (array) $paths,
+ $this->fallbackDirs
+ );
+ } else {
+ $this->fallbackDirs = array_merge(
+ $this->fallbackDirs,
+ (array) $paths
+ );
}
return;
}
- if (isset($this->prefixes[$prefix])) {
+ if (!isset($this->prefixes[$prefix])) {
+ $this->prefixes[$prefix] = (array) $paths;
+
+ return;
+ }
+ if ($prepend) {
+ $this->prefixes[$prefix] = array_merge(
+ (array) $paths,
+ $this->prefixes[$prefix]
+ );
+ } else {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths
);
- } else {
- $this->prefixes[$prefix] = (array) $paths;
}
}
/**
+ * Registers a set of classes, replacing any others previously set.
+ *
+ * @param string $prefix The classes prefix
+ * @param array|string $paths The location(s) of the classes
+ */
+ public function set($prefix, $paths)
+ {
+ if (!$prefix) {
+ $this->fallbackDirs = (array) $paths;
+
+ return;
+ }
+ $this->prefixes[$prefix] = (array) $paths;
+ }
+
+ /**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
@@ -162,14 +195,14 @@ public function loadClass($class)
*/
public function findFile($class)
{
- if (isset($this->classMap[$class])) {
- return $this->classMap[$class];
- }
-
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
+ if (isset($this->classMap[$class])) {
+ return $this->classMap[$class];
+ }
+
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
@@ -202,6 +235,6 @@ public function findFile($class)
return $file;
}
- $this->classMap[$class] = false;
+ return $this->classMap[$class] = false;
}
}
View
12 libs/composer/autoload_classmap.php
@@ -6,14 +6,14 @@
$baseDir = dirname($vendorDir);
return array(
- 'easyparse' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
- 'tagparse' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
- 'nodecounter' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
- 'lessify' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
- 'MustacheLoader' => $baseDir . '/libs/mustache/mustache/MustacheLoader.php',
'GeSHi' => $baseDir . '/libs/geshi/geshi/geshi.php',
- 'lessc' => $baseDir . '/libs/lessphp/lessphp/lessc.inc.php',
'Mustache' => $baseDir . '/libs/mustache/mustache/Mustache.php',
'MustacheException' => $baseDir . '/libs/mustache/mustache/Mustache.php',
+ 'MustacheLoader' => $baseDir . '/libs/mustache/mustache/MustacheLoader.php',
'Textile' => $baseDir . '/libs/textile/textile/classTextile.php',
+ 'easyparse' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
+ 'lessc' => $baseDir . '/libs/lessphp/lessphp/lessc.inc.php',
+ 'lessify' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
+ 'nodecounter' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
+ 'tagparse' => $baseDir . '/libs/lessphp/lessphp/lessify.inc.php',
);
View
1  libs/composer/autoload_namespaces.php
@@ -12,6 +12,7 @@
'StupidHttp_' => $vendorDir . '/bolt80/stupidhttp/lib',
'PieCrust' => array($baseDir . '/src/', $baseDir . '/tests/src/'),
'Log' => $baseDir . '/libs/pear',
+ 'Console_Color2' => $vendorDir . '/pear/Console_Color2/',
'Console' => $baseDir . '/libs/pear',
'Benchmark_' => $baseDir . '/libs/pear',
);
View
22 libs/composer/autoload_real.php
@@ -2,19 +2,27 @@
// autoload_real.php generated by Composer
-require __DIR__ . '/ClassLoader.php';
-
-class ComposerAutoloaderInit
+class ComposerAutoloaderInit00e7b338a0a4cad77486eca10d4846fc
{
private static $loader;
+ public static function loadClassLoader($class)
+ {
+ if ('Composer\Autoload\ClassLoader' === $class) {
+ require __DIR__ . '/ClassLoader.php';
+ }
+ }
+
public static function getLoader()
{
- if (null !== static::$loader) {
- return static::$loader;
+ if (null !== self::$loader) {
+ return self::$loader;
}
- static::$loader = $loader = new \Composer\Autoload\ClassLoader();
+ spl_autoload_register(array('ComposerAutoloaderInit00e7b338a0a4cad77486eca10d4846fc', 'loadClassLoader'));
+ self::$loader = $loader = new \Composer\Autoload\ClassLoader();
+ spl_autoload_unregister(array('ComposerAutoloaderInit00e7b338a0a4cad77486eca10d4846fc', 'loadClassLoader'));
+
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
@@ -32,7 +40,7 @@ public static function getLoader()
$loader->addClassMap($classMap);
}
- $loader->register();
+ $loader->register(true);
return $loader;
}
View
54 libs/composer/installed.json
@@ -262,9 +262,9 @@
"homepage": "http://bolt80.com/stupidhttp",
"keywords": [
"http",
- "web",
+ "net",
"server",
- "net"
+ "web"
]
},
{
@@ -296,5 +296,55 @@
"BSD"
],
"homepage": "http://vfs.bovigo.org/"
+ },
+ {
+ "name": "pear/Console_Color2",
+ "version": "0.1.2",
+ "version_normalized": "0.1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/pear/Console_Color2",
+ "reference": "0.1.2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/pear/Console_Color2/zipball/0.1.2",
+ "reference": "0.1.2",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.0.0"
+ },
+ "time": "2012-10-23 04:52:18",
+ "type": "library",
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Console_Color2": ""
+ }
+ },
+ "notification-url": "http://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Daniel O'Connor",
+ "email": "daniel.oconnor@gmail.com"
+ },
+ {
+ "name": "Stefan Walk",
+ "email": "et@php.net"
+ },
+ {
+ "name": "Scott Mattocks",
+ "email": "scottmattocks@php.net"
+ }
+ ],
+ "description": "This Class allows you to easily use ANSI console colors in your application.",
+ "homepage": "https://github.com/pear/Console_Color2",
+ "keywords": [
+ "console"
+ ]
}
]
View
297 libs/pear/Console/Color2.php
@@ -0,0 +1,297 @@
+<?php
+/**
+ * Color.php
+ *
+ * PHP version 5
+ *
+ * Copyright (c) 2007 Stefan Walk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * @category Console
+ * @package Console_Color2
+ * @author Stefan Walk <et@php.net>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @link http://pear.php.net/package/Console_Color2
+ */
+
+
+
+/**
+ * A simple class to use ANSI Colorcodes.
+ *
+ * Of all the functions, you probably only want to use convert() and escape().
+ * They are easier to use. However, if you want to access colorcodes more
+ * directly, look into the other functions.
+ *
+ * @category Console
+ * @package Console_Color
+ * @author Stefan Walk <et@php.net>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @link http://pear.php.net/package/Console_Color
+ */
+class Console_Color2
+{
+
+ protected $color_codes;
+
+ public function __construct() {
+ $this->setColorCodes(array(
+ 'color' => array(
+ 'black' => 30,
+ 'red' => 31,
+ 'green' => 32,
+ 'brown' => 33,
+ 'blue' => 34,
+ 'purple' => 35,
+ 'cyan' => 36,
+ 'grey' => 37,
+ 'yellow' => 33
+ ),
+ 'style' => array(
+ 'normal' => 0,
+ 'bold' => 1,
+ 'light' => 1,
+ 'underscore' => 4,
+ 'underline' => 4,
+ 'blink' => 5,
+ 'inverse' => 6,
+ 'hidden' => 8,
+ 'concealed' => 8
+ ),
+ 'background' => array(
+ 'black' => 40,
+ 'red' => 41,
+ 'green' => 42,
+ 'brown' => 43,
+ 'yellow' => 43,
+ 'blue' => 44,
+ 'purple' => 45,
+ 'cyan' => 46,
+ 'grey' => 47
+ )
+ )
+ );
+ }
+
+ public function setColorCodes($color_codes)
+ {
+ $this->color_codes = $color_codes;
+ }
+
+ public function getColorCodes()
+ {
+ return $this->color_codes;
+ }
+
+ /**
+ * Returns an ANSI-Controlcode
+ *
+ * Takes 1 to 3 Arguments: either 1 to 3 strings containing the name of the
+ * FG Color, style and BG color, or one array with the indices color, style
+ * or background.
+ *
+ * @param mixed $color Optional.
+ * Either a string with the name of the foreground
+ * color, or an array with the indices 'color',
+ * 'style', 'background' and corresponding names as
+ * values.
+ * @param string $style Optional name of the style
+ * @param string $background Optional name of the background color
+ *
+ * @return string
+ */
+ public function color($color = null, $style = null, $background = null) // {{{
+ {
+ $colors = $this->getColorCodes();
+ if (is_array($color)) {
+ $style = isset($color['style']) ? $color['style'] : null;
+ $background = isset($color['background']) ? $color['background'] : null;
+ $color = isset($color['color']) ? $color['color'] : null;
+ }
+
+ if ($color == 'reset') {
+ return "\033[0m";
+ }
+
+ $code = array();
+ if (isset($style)) {
+ $code[] = $colors['style'][$style];
+ }
+
+ if (isset($color)) {
+ $code[] = $colors['color'][$color];
+ }
+
+ if (isset($background)) {
+ $code[] = $colors['background'][$background];
+ }
+
+ if (empty($code)) {
+ $code[] = 0;
+ }
+
+ $code = implode(';', $code);
+ return "\033[{$code}m";
+ } // }}}
+
+ /**
+ * Returns a FG color controlcode
+ *
+ * @param string $name Name of controlcode
+ *
+ * @return string
+ */
+ public function fgcolor($name)
+ {
+ $colors = $this->getColorCodes();
+
+ return "\033[".$colors['color'][$name].'m';
+ }
+
+ /**
+ * Returns a style controlcode
+ *
+ * @param string $name Name of controlcode
+ *
+ * @return string
+ */
+ function bgcolor($name)
+ {
+ $colors = $this->getColorCodes();
+ return "\033[".$colors['background'][$name].'m';
+ }
+
+ /**
+ * Converts colorcodes in the format %y (for yellow) into ansi-control
+ * codes. The conversion table is: ('bold' meaning 'light' on some
+ * terminals). It's almost the same conversion table irssi uses.
+ * <pre>
+ * text text background
+ * ------------------------------------------------
+ * %k %K %0 black dark grey black
+ * %r %R %1 red bold red red
+ * %g %G %2 green bold green green
+ * %y %Y %3 yellow bold yellow yellow
+ * %b %B %4 blue bold blue blue
+ * %m %M %5 magenta bold magenta magenta
+ * %p %P magenta (think: purple)
+ * %c %C %6 cyan bold cyan cyan
+ * %w %W %7 white bold white white
+ *
+ * %F Blinking, Flashing
+ * %U Underline
+ * %8 Reverse
+ * %_,%9 Bold
+ *
+ * %n Resets the color
+ * %% A single %
+ * </pre>
+ * First param is the string to convert, second is an optional flag if
+ * colors should be used. It defaults to true, if set to false, the
+ * colorcodes will just be removed (And %% will be transformed into %)
+ *
+ * @param string $string String to convert
+ * @param bool $colored Should the string be colored?
+ *
+ * @return string
+ */
+ public function convert($string, $colored = true)
+ {
+ static $conversions = array ( // static so the array doesn't get built
+ // everytime
+ // %y - yellow, and so on... {{{
+ '%y' => array('color' => 'yellow', 'style' => 'normal'),
+ '%g' => array('color' => 'green', 'style' => 'normal'),
+ '%b' => array('color' => 'blue', 'style' => 'normal'),
+ '%r' => array('color' => 'red', 'style' => 'normal'),
+ '%p' => array('color' => 'purple', 'style' => 'normal'),
+ '%m' => array('color' => 'purple', 'style' => 'normal'),
+ '%c' => array('color' => 'cyan', 'style' => 'normal'),
+ '%w' => array('color' => 'grey', 'style' => 'normal'),
+ '%k' => array('color' => 'black', 'style' => 'normal'),
+ '%n' => array('color' => 'reset' ),
+ '%Y' => array('color' => 'yellow', 'style' => 'light'),
+ '%G' => array('color' => 'green', 'style' => 'light'),
+ '%B' => array('color' => 'blue', 'style' => 'light'),
+ '%R' => array('color' => 'red', 'style' => 'light'),
+ '%P' => array('color' => 'purple', 'style' => 'light'),
+ '%M' => array('color' => 'purple', 'style' => 'light'),
+ '%C' => array('color' => 'cyan', 'style' => 'light'),
+ '%W' => array('color' => 'grey', 'style' => 'light'),
+ '%K' => array('color' => 'black', 'style' => 'light'),
+ '%N' => array('color' => 'reset', 'style' => 'light'),
+ '%3' => array('background' => 'yellow'),
+ '%2' => array('background' => 'green' ),
+ '%4' => array('background' => 'blue' ),
+ '%1' => array('background' => 'red' ),
+ '%5' => array('background' => 'purple'),
+ '%6' => array('background' => 'cyan' ),
+ '%7' => array('background' => 'grey' ),
+ '%0' => array('background' => 'black' ),
+ // Don't use this, I can't stand flashing text
+ '%F' => array('style' => 'blink'),
+ '%U' => array('style' => 'underline'),
+ '%8' => array('style' => 'inverse'),
+ '%9' => array('style' => 'bold'),
+ '%_' => array('style' => 'bold')
+ // }}}
+ );
+
+ if ($colored) {
+ $string = str_replace('%%', '% ', $string);
+ foreach ($conversions as $key => $value) {
+ $string = str_replace($key, $this->color($value),
+ $string);
+ }
+ $string = str_replace('% ', '%', $string);
+
+ } else {
+ $string = preg_replace('/%((%)|.)/', '$2', $string);
+ }
+
+ return $string;
+ }
+
+ /**
+ * Escapes % so they don't get interpreted as color codes
+ *
+ * @param string $string String to escape
+ *
+ * @return string
+ */
+ public function escape($string)
+ {
+ return str_replace('%', '%%', $string);
+ }
+
+ /**
+ * Strips ANSI color codes from a string
+ *
+ * @param string $string String to strip
+ *
+ * @acess public
+ * @return string
+ */
+ public function strip($string)
+ {
+ return preg_replace('/\033\[[\d;]+m/', '', $string);
+ }
+
+}
View
297 libs/pear/Console_Color2/Console/Color2.php
@@ -0,0 +1,297 @@
+<?php
+/**
+ * Color.php
+ *
+ * PHP version 5
+ *
+ * Copyright (c) 2007 Stefan Walk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * @category Console
+ * @package Console_Color2
+ * @author Stefan Walk <et@php.net>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @link http://pear.php.net/package/Console_Color2
+ */
+
+
+
+/**
+ * A simple class to use ANSI Colorcodes.
+ *
+ * Of all the functions, you probably only want to use convert() and escape().
+ * They are easier to use. However, if you want to access colorcodes more
+ * directly, look into the other functions.
+ *
+ * @category Console
+ * @package Console_Color
+ * @author Stefan Walk <et@php.net>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @link http://pear.php.net/package/Console_Color
+ */
+class Console_Color2
+{
+
+ protected $color_codes;
+
+ public function __construct() {
+ $this->setColorCodes(array(
+ 'color' => array(
+ 'black' => 30,
+ 'red' => 31,
+ 'green' => 32,
+ 'brown' => 33,
+ 'blue' => 34,
+ 'purple' => 35,
+ 'cyan' => 36,
+ 'grey' => 37,
+ 'yellow' => 33
+ ),
+ 'style' => array(
+ 'normal' => 0,
+ 'bold' => 1,
+ 'light' => 1,
+ 'underscore' => 4,
+ 'underline' => 4,
+ 'blink' => 5,
+ 'inverse' => 6,
+ 'hidden' => 8,
+ 'concealed' => 8
+ ),
+ 'background' => array(
+ 'black' => 40,
+ 'red' => 41,
+ 'green' => 42,
+ 'brown' => 43,
+ 'yellow' => 43,
+ 'blue' => 44,
+ 'purple' => 45,
+ 'cyan' => 46,
+ 'grey' => 47
+ )
+ )
+ );
+ }
+
+ public function setColorCodes($color_codes)
+ {
+ $this->color_codes = $color_codes;
+ }
+
+ public function getColorCodes()
+ {
+ return $this->color_codes;
+ }
+
+ /**
+ * Returns an ANSI-Controlcode
+ *
+ * Takes 1 to 3 Arguments: either 1 to 3 strings containing the name of the
+ * FG Color, style and BG color, or one array with the indices color, style
+ * or background.
+ *
+ * @param mixed $color Optional.
+ * Either a string with the name of the foreground
+ * color, or an array with the indices 'color',
+ * 'style', 'background' and corresponding names as
+ * values.
+ * @param string $style Optional name of the style
+ * @param string $background Optional name of the background color
+ *
+ * @return string
+ */
+ public function color($color = null, $style = null, $background = null) // {{{
+ {
+ $colors = $this->getColorCodes();
+ if (is_array($color)) {
+ $style = isset($color['style']) ? $color['style'] : null;
+ $background = isset($color['background']) ? $color['background'] : null;
+ $color = isset($color['color']) ? $color['color'] : null;
+ }
+
+ if ($color == 'reset') {
+ return "\033[0m";
+ }
+
+ $code = array();
+ if (isset($style)) {
+ $code[] = $colors['style'][$style];
+ }
+
+ if (isset($color)) {
+ $code[] = $colors['color'][$color];
+ }
+
+ if (isset($background)) {
+ $code[] = $colors['background'][$background];
+ }
+
+ if (empty($code)) {
+ $code[] = 0;
+ }
+
+ $code = implode(';', $code);
+ return "\033[{$code}m";
+ } // }}}
+
+ /**
+ * Returns a FG color controlcode
+ *
+ * @param string $name Name of controlcode
+ *
+ * @return string
+ */
+ public function fgcolor($name)
+ {
+ $colors = $this->getColorCodes();
+
+ return "\033[".$colors['color'][$name].'m';
+ }
+
+ /**
+ * Returns a style controlcode
+ *
+ * @param string $name Name of controlcode
+ *
+ * @return string
+ */
+ function bgcolor($name)
+ {
+ $colors = $this->getColorCodes();
+ return "\033[".$colors['background'][$name].'m';
+ }
+
+ /**
+ * Converts colorcodes in the format %y (for yellow) into ansi-control
+ * codes. The conversion table is: ('bold' meaning 'light' on some
+ * terminals). It's almost the same conversion table irssi uses.
+ * <pre>
+ * text text background
+ * ------------------------------------------------
+ * %k %K %0 black dark grey black
+ * %r %R %1 red bold red red
+ * %g %G %2 green bold green green
+ * %y %Y %3 yellow bold yellow yellow
+ * %b %B %4 blue bold blue blue
+ * %m %M %5 magenta bold magenta magenta
+ * %p %P magenta (think: purple)
+ * %c %C %6 cyan bold cyan cyan
+ * %w %W %7 white bold white white
+ *
+ * %F Blinking, Flashing
+ * %U Underline
+ * %8 Reverse
+ * %_,%9 Bold
+ *
+ * %n Resets the color
+ * %% A single %
+ * </pre>
+ * First param is the string to convert, second is an optional flag if
+ * colors should be used. It defaults to true, if set to false, the
+ * colorcodes will just be removed (And %% will be transformed into %)
+ *
+ * @param string $string String to convert
+ * @param bool $colored Should the string be colored?
+ *
+ * @return string
+ */
+ public function convert($string, $colored = true)
+ {
+ static $conversions = array ( // static so the array doesn't get built
+ // everytime
+ // %y - yellow, and so on... {{{
+ '%y' => array('color' => 'yellow', 'style' => 'normal'),
+ '%g' => array('color' => 'green', 'style' => 'normal'),
+ '%b' => array('color' => 'blue', 'style' => 'normal'),
+ '%r' => array('color' => 'red', 'style' => 'normal'),
+ '%p' => array('color' => 'purple', 'style' => 'normal'),
+ '%m' => array('color' => 'purple', 'style' => 'normal'),
+ '%c' => array('color' => 'cyan', 'style' => 'normal'),
+ '%w' => array('color' => 'grey', 'style' => 'normal'),
+ '%k' => array('color' => 'black', 'style' => 'normal'),
+ '%n' => array('color' => 'reset' ),
+ '%Y' => array('color' => 'yellow', 'style' => 'light'),
+ '%G' => array('color' => 'green', 'style' => 'light'),
+ '%B' => array('color' => 'blue', 'style' => 'light'),
+ '%R' => array('color' => 'red', 'style' => 'light'),
+ '%P' => array('color' => 'purple', 'style' => 'light'),
+ '%M' => array('color' => 'purple', 'style' => 'light'),
+ '%C' => array('color' => 'cyan', 'style' => 'light'),
+ '%W' => array('color' => 'grey', 'style' => 'light'),
+ '%K' => array('color' => 'black', 'style' => 'light'),
+ '%N' => array('color' => 'reset', 'style' => 'light'),
+ '%3' => array('background' => 'yellow'),
+ '%2' => array('background' => 'green' ),
+ '%4' => array('background' => 'blue' ),
+ '%1' => array('background' => 'red' ),
+ '%5' => array('background' => 'purple'),
+ '%6' => array('background' => 'cyan' ),
+ '%7' => array('background' => 'grey' ),
+ '%0' => array('background' => 'black' ),
+ // Don't use this, I can't stand flashing text
+ '%F' => array('style' => 'blink'),
+ '%U' => array('style' => 'underline'),
+ '%8' => array('style' => 'inverse'),
+ '%9' => array('style' => 'bold'),
+ '%_' => array('style' => 'bold')
+ // }}}
+ );
+
+ if ($colored) {
+ $string = str_replace('%%', '% ', $string);
+ foreach ($conversions as $key => $value) {
+ $string = str_replace($key, $this->color($value),
+ $string);
+ }
+ $string = str_replace('% ', '%', $string);
+
+ } else {
+ $string = preg_replace('/%((%)|.)/', '$2', $string);
+ }
+
+ return $string;
+ }
+
+ /**
+ * Escapes % so they don't get interpreted as color codes
+ *
+ * @param string $string String to escape
+ *
+ * @return string
+ */
+ public function escape($string)
+ {
+ return str_replace('%', '%%', $string);
+ }
+
+ /**
+ * Strips ANSI color codes from a string
+ *
+ * @param string $string String to strip
+ *
+ * @acess public
+ * @return string
+ */
+ public function strip($string)
+ {
+ return preg_replace('/\033\[[\d;]+m/', '', $string);
+ }
+
+}
View
19 libs/pear/Console_Color2/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Stefan Walk
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
View
19 libs/pear/Console_Color2/README
@@ -0,0 +1,19 @@
+This package is http://pear.php.net/package/Console_Color and has been migrated from http://svn.php.net/repository/pear/packages/Console_Color
+
+Please report all new issues via the PEAR bug tracker.
+
+If this package is marked as unmaintained and you have fixes, please submit your pull requests and start discussion on the pear-qa mailing list.
+
+To test, run either
+$ phpunit tests/
+ or
+$ pear run-tests -r
+
+To build, simply
+$ pear package
+
+To install from scratch
+$ pear install package.xml
+
+To upgrade
+$ pear upgrade -f package.xml
View
28 libs/pear/Console_Color2/composer.json
@@ -0,0 +1,28 @@
+{
+ "name": "pear/Console_Color2",
+ "description": "This Class allows you to easily use ANSI console colors in your application.",
+ "type": "library",
+ "keywords": [ "console" ],
+ "homepage": "https://github.com/pear/Console_Color2",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Daniel O'Connor",
+ "email": "daniel.oconnor@gmail.com"
+ },
+ {
+ "name": "Stefan Walk",
+ "email": "et@php.net"
+ },
+ {
+ "name": "Scott Mattocks",
+ "email": "scottmattocks@php.net"
+ }
+ ],
+ "require": {
+ "php": ">=5.0.0"
+ },
+ "autoload": {
+ "psr-0": { "Console_Color2": "" }
+ }
+}
View
109 libs/pear/Console_Color2/package.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.4" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Console_Color2</name>
+ <channel>pear.php.net</channel>
+ <summary>This Class allows you to easily use ANSI console colors in your application.</summary>
+ <description>You can use Console_Color::convert to transform colorcodes like %r into ANSI
+control codes. $console = new Console_Color2(); print $console-&gt;convert(&quot;%rHello World!%n&quot;); would print
+&quot;Hello World&quot; in red, for example.</description>
+ <lead>
+ <name>Daniel O&apos;Connor</name>
+ <user>doconnor</user>
+ <email>daniel.oconnor@gmail.com</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>Stefan Walk</name>
+ <user>et</user>
+ <email>et@php.net</email>
+ <active>no</active>
+ </lead>
+ <lead>
+ <name>Scott Mattocks</name>
+ <user>scottmattocks</user>
+ <email>scottmattocks@php.net</email>
+ <active>no</active>
+ </lead>
+ <date>2012-10-23</date>
+ <time>11:52:11</time>
+ <version>
+ <release>0.1.2</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
+ <notes>
+Bug #19626 Going from Light to Dark color does not work
+ </notes>
+ <contents>
+ <dir baseinstalldir="/" name="/">
+ <file baseinstalldir="/" md5sum="192fb4cd5fd64bf80938e955adf7f805" name="Console/Color2.php" role="php" />
+ <file baseinstalldir="/" md5sum="04c232aa258bd5c8d14b2a370fcd1292" name="examples/color_example.php" role="doc" />
+ <file baseinstalldir="/" md5sum="32593f1641504e01f9fb6df55c1c5478" name="examples/documentation" role="doc" />
+ <file baseinstalldir="/" md5sum="3d0940ae3b4c98e9f4184d2deae3ebe4" name="composer.json" role="data" />
+ <file baseinstalldir="/" md5sum="386286831b7c47adae39ddfb51d483ab" name="LICENSE" role="doc" />
+ <file baseinstalldir="/" md5sum="ea4ee09f74764a34fc99e6da91a06c62" name="README" role="doc" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.0.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.5.6</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog>
+ <release>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2011-12-18</date>
+ <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
+ <notes>
+PHP5 syntax
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.1.1</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2012-03-14</date>
+ <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
+ <notes>
+Fix undefined index E_NOTICEs [Tarcisio Gruppi]
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.1.2</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2012-10-23</date>
+ <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
+ <notes>
+Bug #19626 Going from Light to Dark color does not work
+ </notes>
+ </release>
+ </changelog>
+</package>
View
5 res/messages/critical.html
@@ -62,9 +62,6 @@
</div>
<hr />
- <p class="note">To see your custom error pages, make sure you don&#8217;t initialize <strong>PieCrust</strong>
- with the <code>debug</code> parameter, and don&#8217;t turn on the <code>site/display_errors</code> configuration
- setting. To see detailed errors, on the other hand, use the <code>--debug</code> parameter
- in <code>chef</code>, append <code>?!debug</code> to the <span class="caps">URL</span>, or turn on <code>site/display_errors</code>.</p> </div>
+ <p class="note">You&#8217;re seeing this because something wrong happend. To see detailed errors with callstacks, run chef with the <code>--debug</code> parameter, append <code>?!debug</code> to the <span class="caps">URL</span>, or initialize the <code>PieCrust</code> object with <code>{&#39;debug&#39;=&#62;true}</code>. On the other hand, to see you custom error pages, set the <code>site/display_errors</code> setting to <code>false</code>.</p> </div>
</body>
</html>
View
5 res/messages/error.html
@@ -60,9 +60,6 @@
</div>
<hr />
- <p class="note">To see your custom error pages, make sure you don&#8217;t initialize <strong>PieCrust</strong>
- with the <code>debug</code> parameter, and don&#8217;t turn on the <code>site/display_errors</code> configuration
- setting. To see detailed errors, on the other hand, use the <code>--debug</code> parameter
- in <code>chef</code>, append <code>?!debug</code> to the <span class="caps">URL</span>, or turn on <code>site/display_errors</code>.</p> </div>
+ <p class="note">You&#8217;re seeing this because something wrong happend. To see detailed errors with callstacks, run chef with the <code>--debug</code> parameter, append <code>?!debug</code> to the <span class="caps">URL</span>, or initialize the <code>PieCrust</code> object with <code>{&#39;debug&#39;=&#62;true}</code>. On the other hand, to see you custom error pages, set the <code>site/display_errors</code> setting to <code>false</code>.</p> </div>
</body>
</html>
View
26 res/messages/welcome.html → res/messages/error404.html
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
- <title>Welcome To Your New Website</title>
+ <title>Can&#039;t find the sugar!</title>
<meta name="generator" content="PieCrust" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lobster">
<style>
@@ -52,31 +52,11 @@
<div id="container">
<div id="header">
<p id="preamble">A Message From The Kitchen:</p>
- <h1>Welcome To Your New Website</h1>
+ <h1>Can&#039;t find the sugar!</h1>
</div>
<hr />
<div id="content">
- <p>It looks like you have a fresh install of <strong>PieCrust</strong>. Thanks for downloading
-it and trying it out! You're almost ready to start writing your own stuff:</p>
-
-<ul>
-<li>Create a <code>_content</code> directory at the root of your website (probably next to the
-<code>_piecrust</code> directory).</li>
-<li>Inside it, create the following:
-
-<ul>
-<li>A <code>config.yml</code> text file (this will contain your website's global settings, like its title).</li>
-<li>A <code>templates</code> directory (this will contain things like HTML layouts).</li>
-<li>A <code>pages</code> directory (this will contain the contents of your pages).</li>
-</ul></li>
-<li>Create a default template, appropriately called <code>default.html</code>. Use the
-<code>{{content|raw}}</code> tag to indicate where the page contents
-should go.</li>
-<li>Create your main page, called <code>_index.html</code> and put whatever you want in it.</li>
-<li>Refresh your browser!</li>
-</ul>
-
-<p>For more information, be sure to check out the <a href="http://bolt80.com/piecrust/doc">documentation</a>.</p>
+ <p>It looks like the page you were trying to access does not exist around here. Try going somewhere else.</p>
</div>
<hr />
View
10 src/PieCrust/Baker/PageBaker.php
@@ -91,7 +91,10 @@ public function getOutputPath(IPage $page)
if ($page->getConfig()->getValue('single_page'))
{
if ($isSubPage)
- throw new PieCrustException("Page {$page->getUri()} has `single_page` set to `true` but we're baking sub-page {$page->getPageNumber()}. What the hell?");
+ {
+ $pageRelativePath = PageHelper::getRelativePath($page);
+ throw new PieCrustException("Page '{$pageRelativePath}' has `single_page` set to `true` but we're baking sub-page {$page->getPageNumber()}. What the hell?");
+ }
$extension = pathinfo($page->getUri(), PATHINFO_EXTENSION);
if ($extension)
@@ -180,7 +183,8 @@ public function bake(IPage $page, array $extraData = null)
}
catch (Exception $e)
{
- throw new PieCrustException("Error baking page '{$page->getUri()}' (p{$page->getPageNumber()}): {$e->getMessage()}", 0, $e);
+ $pageRelativePath = PageHelper::getRelativePath($page);
+ throw new PieCrustException("Error baking page '{$pageRelativePath}' (p{$page->getPageNumber()})", 0, $e);
}
return $didBake;
@@ -293,7 +297,7 @@ protected function bakeSinglePage(PageRenderer $pageRenderer, array $extraData =
{
$destinationAssetPath = $bakeAssetDir . basename($assetPath);
if (@copy($assetPath, $destinationAssetPath) == false)
- throw new PieCrustException("Can't copy '".$assetPath."' to '".$destinationAssetPath."'.");
+ throw new PieCrustException("Can't copy '{$assetPath}' to '{$destinationAssetPath}'.");
}
}
}
View
74 src/PieCrust/Baker/PieCrustBaker.php
@@ -119,7 +119,6 @@ public function __construct(IPieCrust $pieCrust, array $bakerParameters = array(
$this->parameters = array_merge(array(
'smart' => true,
'clean_cache' => false,
- 'info_only' => false,
'config_variant' => null,
'copy_assets' => true,
'processors' => '*',
@@ -154,36 +153,19 @@ public function __construct(IPieCrust $pieCrust, array $bakerParameters = array(
$this->parameters['tag_combinations'] = $combinationsExploded;
}
- // Apply the default configuration variant, if it exists.
- $variants = $this->pieCrust->getConfig()->getValue('baker/config_variants');
- if ($variants and isset($variants['default']))
+ // Apply the specified configuration variant, if any. Otherwise,
+ // use the default variant if it exists.
+ $isDefault = false;
+ $variantName = $this->parameters['config_variant'];
+ if (!$variantName)
{
- if (!is_array($variants['default']))
- {
- throw new PieCrustException("Baker configuration variant '".$variantName."' is not an array. Check your configuration file.");
- }
- $this->pieCrust->getConfig()->merge($variants['default']);
- }
-
- // Apply the specified configuration variant, if any.
- if ($this->parameters['config_variant'])
- {
- if (!$variants)
- {
- throw new PieCrustException("No baker configuration variants have been defined. You need to create a 'baker/config_variants' section in the configuration file.");
- }
- $variantName = $this->parameters['config_variant'];
- if (!isset($variants[$variantName]))
- {
- throw new PieCrustException("Baker configuration variant '".$variantName."' does not exist. Check your configuration file.");
- }
- $configVariant = $variants[$variantName];
- if (!is_array($configVariant))
- {
- throw new PieCrustException("Baker configuration variant '".$variantName."' is not an array. Check your configuration file.");
- }
- $this->pieCrust->getConfig()->merge($configVariant);
+ $isDefault = true;
+ $variantName = 'default';
}
+ $this->pieCrust->getConfig()->applyVariant(
+ "baker/config_variants/{$variantName}",
+ !$isDefault
+ );
}
/**
@@ -193,16 +175,9 @@ public function bake()
{
$overallStart = microtime(true);
- // Display the banner.
- $bannerLevel = PEAR_LOG_DEBUG;
- if ($this->parameters['info_only'])
- $bannerLevel = PEAR_LOG_NOTICE;
- $this->logger->log("PieCrust Baker v." . PieCrustDefaults::VERSION, $bannerLevel);
- $this->logger->log(" website : " . $this->pieCrust->getRootDir(), $bannerLevel);
- $this->logger->log(" output : " . $this->getBakeDir(), $bannerLevel);
- $this->logger->log(" url : " . $this->pieCrust->getConfig()->getValueUnchecked('site/root'), $bannerLevel);
- if ($this->parameters['info_only'])
- return;
+ // Display debug information.
+ $this->logger->debug(" Bake Output: " . $this->getBakeDir());
+ $this->logger->debug(" Root URL: " . $this->pieCrust->getConfig()->getValue('site/root'));
// Setup the PieCrust environment.
if ($this->parameters['copy_assets'])
@@ -567,7 +542,26 @@ protected function getPageBakerParameters()
public static function formatTimed($startTime, $message)
{
+ static $color = null;
+ if ($color === null)
+ {
+ if (PieCrustDefaults::IS_WINDOWS())
+ $color = false;
+ else
+ $color = new \Console_Color2();
+ }
+
$endTime = microtime(true);
- return sprintf('[%8.1f ms] ', ($endTime - $startTime)*1000.0) . $message;
+ $endTimeStr = sprintf('%8.1f ms', ($endTime - $startTime)*1000.0);
+ if ($color)
+ {
+ $endTimeStr = $color->escape($endTimeStr);
+ $message = $color->escape($message);
+ return $color->convert("[%g{$endTimeStr}%n] {$message}");
+ }
+ else
+ {
+ return "[{$endTimeStr}] {$message}";
+ }
}
}
View
2  src/PieCrust/Baker/ProcessingTreeRunner.php
@@ -201,7 +201,7 @@ protected function processNode($node)
}
catch (Exception $e)
{
- throw new PieCrustException("Error processing '{$node->getPath()}': {$e->getMessage()}", 0, $e);
+ throw new PieCrustException("Error processing '{$node->getPath()}'.", 0, $e);
}
return $didBake;
}
View
63 src/PieCrust/Chef/Chef.php
@@ -101,18 +101,15 @@ public function runUnsafe($userArgc = null, $userArgv = null)
'description' => 'The PieCrust chef manages your website.',
'version' => PieCrustDefaults::VERSION
));
+ $this->addCommonOptionsAndArguments($parser);
// Sort commands by name.
$sortedCommands = $pieCrust->getPluginLoader()->getCommands();
usort($sortedCommands, function ($c1, $c2) { return strcmp($c1->getName(), $c2->getName()); });
// Add commands to the parser.
foreach ($sortedCommands as $command)
{
- if ($rootDir != null || !$command->requiresWebsite())
- {
- $commandParser = $parser->addCommand($command->getName());
- $command->setupParser($commandParser, $pieCrust);
- $this->addCommonOptionsAndArguments($commandParser);
- }
+ $commandParser = $parser->addCommand($command->getName());
+ $command->setupParser($commandParser, $pieCrust);
}
// Parse the command line.
@@ -122,7 +119,7 @@ public function runUnsafe($userArgc = null, $userArgv = null)
}
catch (Exception $e)
{
- $parser->displayError($e->getMessage());
+ $parser->displayError($e->getMessage(), false);
return 1;
}
@@ -133,22 +130,22 @@ public function runUnsafe($userArgc = null, $userArgv = null)
}
// Create the log.
- $debugMode = $result->command->options['debug'];
- $quietMode = $result->command->options['quiet'];
+ $debugMode = $result->options['debug'];
+ $quietMode = $result->options['quiet'];
if ($debugMode && $quietMode)
{
- $parser->displayError("You can't specify both --debug and --quiet.");
+ $parser->displayError("You can't specify both --debug and --quiet.", false);
return 1;
}
- $log = \Log::singleton('console', 'Chef', '', array('lineFormat' => '%{message}'));
+ $log = new ChefLog('Chef', '', array('lineFormat' => '%{message}'));
// Make the log available for debugging purposes.
$GLOBALS['__CHEF_LOG'] = $log;
// Handle deprecated stuff.
- if ($result->command->options['no_cache_old'])
+ if ($result->options['no_cache_old'])
{
$log->warning("The `--nocache` option has been renamed `--no-cache`.");
- $result->command->options['no_cache'] = true;
+ $result->options['no_cache'] = true;
}
// Run the command.
@@ -164,6 +161,12 @@ public function runUnsafe($userArgc = null, $userArgv = null)
throw new PieCrustException("No PieCrust website in '{$cwd}' ('_content/config.yml' not found!).");
}
+ if ($debugMode)
+ {
+ $log->debug("PieCrust v." . PieCrustDefaults::VERSION);
+ $log->debug(" Website: {$rootDir}");
+ }
+
$context = new ChefContext($pieCrust, $result, $log);
$context->setVerbosity($debugMode ?
'debug' :
@@ -174,35 +177,39 @@ public function runUnsafe($userArgc = null, $userArgv = null)
}
catch (Exception $e)
{
- $log->emerg(self::getErrorMessage($e, $debugMode));
+ $this->logException($log, $e, $debugMode);
return 1;
}
}
}
}
- /**
- * Formats an exception into an error message.
- */
- public static function getErrorMessage(Exception $e, $debugMode = false)
+ protected function logException($log, $e, $debugMode = false)
{
- $message = $e->getMessage();
if ($debugMode)
{
- $message .= PHP_EOL;
- $message .= PHP_EOL;
- $message .= "Debug Information" . PHP_EOL;
+ $log->emerg($e->getMessage());
+ $log->debug($e->getTraceAsString());
+ $e = $e->getPrevious();
+ while ($e)
+ {
+ $log->err("-----------------");
+ $log->err($e->getMessage());
+ $log->debug($e->getTraceAsString());
+ $e = $e->getPrevious();
+ }
+ $log->err("-----------------");
+ }
+ else
+ {
+ $log->emerg($e->getMessage());
+ $e = $e->getPrevious();
while ($e)
{
- $message .= "-----------------" . PHP_EOL;
- $message .= $e->getMessage() . PHP_EOL;
- $message .= $e->getTraceAsString();
- $message .= PHP_EOL;
+ $log->err($e->getMessage());
$e = $e->getPrevious();
}
- $message .= "-----------------" . PHP_EOL;
}
- return $message;
}
protected function addCommonOptionsAndArguments(\Console_CommandLine $parser)
View
61 src/PieCrust/Chef/ChefLog.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace PieCrust\Chef;
+
+use PieCrust\PieCrustDefaults;
+
+
+/**
+ * A PEAR log with pretty colors, at least on Mac/Linux.
+ */
+class ChefLog extends \Log_console
+{
+ protected $color;
+
+ public function __construct($name, $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG)
+ {
+ parent::Log_console($name, $ident, $conf, $level);
+
+ if (PieCrustDefaults::IS_WINDOWS())
+ $this->color = null;
+ else
+ $this->color = new \Console_Color2();
+ }
+
+ public function log($message, $priority = null)
+ {
+ if ($this->color)
+ {
+ if ($priority === null)
+ $priority = $this->_priority;
+
+ $colorCode = false;
+ switch ($priority)
+ {
+ case PEAR_LOG_EMERG:
+ case PEAR_LOG_ALERT:
+ case PEAR_LOG_CRIT:
+ $colorCode = "%R";
+ break;
+ case PEAR_LOG_ERR:
+ $colorCode = "%r";
+ break;
+ case PEAR_LOG_WARNING:
+ $colorCode = "%y";
+ break;
+ case PEAR_LOG_DEBUG:
+ $colorCode = "%K";
+ break;
+ }
+ if ($colorCode)
+ {
+ $message = $this->color->convert(
+ $colorCode .
+ $this->color->escape($message) .
+ "%n");
+ }
+ }
+
+ return parent::log($message, $priority);
+ }
+}
View
8 src/PieCrust/Chef/Commands/BakeCommand.php
@@ -50,13 +50,6 @@ public function setupParser(Console_CommandLine $bakerParser, IPieCrust $pieCrus
'action' => 'StoreTrue',
'help_name' => 'PORTABLE'
));
- $bakerParser->addOption('info_only', array(
- 'long_name' => '--info',
- 'description' => "Prints only high-level information about what the baker will do.",
- 'default' => false,
- 'action' => 'StoreTrue',
- 'help_name' => 'INFO_ONLY'
- ));
// Deprecated stuff.
$bakerParser->addOption('root_url_old', array(
@@ -106,7 +99,6 @@ public function run(ChefContext $context)
$bakerParameters = array(
'smart' => !$result->command->options['force'],
'clean_cache' => $result->command->options['force'],
- 'info_only' => $result->command->options['info_only'],
'config_variant' => $result->command->options['config_variant']
);
$baker = new PieCrustBaker($pieCrust, $bakerParameters, $context->getLog());
View
15 src/PieCrust/Chef/Commands/ServeCommand.php
@@ -50,6 +50,13 @@ public function setupParser(Console_CommandLine $serverParser, IPieCrust $pieCru
'default' => null,
'help_name' => 'LOG_FILE'
));
+ $serverParser->addOption('config_variant', array(
+ 'short_name' => '-c',
+ 'long_name' => '--config',
+ 'description' => "Apply the configuration settings from the named baker configuration variant.",
+ 'default' => null,
+ 'help_name' => 'VARIANT'
+ ));
// Deprecated stuff.
$serverParser->addOption('run_browser_old', array(
@@ -76,8 +83,9 @@ public function run(ChefContext $context)
$address = $result->command->options['address'];
$runBrowser = $result->command->options['run_browser'];
$logFile = $result->command->options['log_file'];
- $debug = $result->command->options['debug'];
- $nocache = $result->command->options['no_cache'];
+ $configVariant = $result->command->options['config_variant'];
+ $nocache = $result->options['no_cache'];
+ $debug = $result->options['debug'];
// Start serving!
$server = new PieCrustServer($rootDir,
@@ -86,7 +94,8 @@ public function run(ChefContext $context)
'address' => $address,
'log_file' => $logFile,
'debug' => $debug,
- 'cache' => !$nocache
+ 'cache' => !$nocache,
+ 'config_variant' => $configVariant
),
$context->getLog());
$server->run(array(
View
2  src/PieCrust/Data/PieCrustData.php
@@ -108,7 +108,7 @@ public function debug_info()
catch (Exception $e)
{
ob_end_clean();
- throw new PieCrustException("Error while generating the debug data: " . $e->getMessage(), 0, $e);
+ throw new PieCrustException("Error while generating the debug data.", 0, $e);
}
$output .= ob_get_clean();
$output .= '</div>' .PHP_EOL;
View
4 src/PieCrust/Page/PageLoader.php
@@ -89,7 +89,7 @@ public function load()
catch (Exception $e)
{
$relativePath = PageHelper::getRelativePath($this->page);
- throw new PieCrustException("Error loading page '{$relativePath}': {$e->getMessage()}", 0, $e);
+ throw new PieCrustException("Error loading page: {$relativePath}", 0, $e);
}
}
@@ -102,7 +102,7 @@ public function formatContents(array $rawSegments)
catch (Exception $e)
{
$relativePath = PageHelper::getRelativePath($this->page);
- throw new PieCrustException("Error formatting page '{$relativePath}': {$e->getMessage()}", 0, $e);
+ throw new PieCrustException("Error formatting page: {$relativePath}", 0, $e);
}
}
View
102 src/PieCrust/PieCrustConfiguration.php
@@ -44,6 +44,25 @@ public function __construct(array $paths = null, $cache = false)
$this->cache = $cache;
$this->fixupCallback = null;
}
+
+ /**
+ * Applies a configuration variant stored within the configuration itself.
+ */
+ public function applyVariant($path, $throwIfNotFound = true)
+ {
+ $variant = $this->getValue($path);
+ if ($variant === null)
+ {
+ if ($throwIfNotFound)
+ throw new PieCrustException("No such configuration variant found: {$path}");
+ return false;
+ }
+ if (!is_array($variant))
+ {
+ throw new PieCrustException("Configuration variant '{$path}' is not an array. Check your configuration file.");
+ }
+ $this->merge($variant);
+ }
protected function loadConfig()
{
@@ -66,6 +85,15 @@ protected function loadConfig()
throw new PieCrustException("No PieCrust configuration file is readable, or none exists: " . implode(', ', $this->paths));
}
+ // Then compute the cache key that we'll be using to further validate
+ // the cache (if the keys don't match, it means something happened like
+ // PieCrust was updated to a new version and the cache probably needs
+ // to be re-generated).
+ $cacheKey = md5(
+ "version=" . PieCrustDefaults::VERSION .
+ "&cache=" . PieCrustDefaults::CACHE_VERSION
+ );
+
// Compare the modification times of those configuration files with the
// cached JSON version.
$cache = $this->cache ? new Cache($this->cache) : null;
@@ -74,52 +102,60 @@ protected function loadConfig()
$configText = $cache->read('config', 'json');
$this->config = json_decode($configText, true);
- // If the site root URL was automatically defined, we need to re-compute
- // it in case the website is being run from a different place.
- $isAutoRoot = $this->getValue('site/is_auto_root');
- if ($isAutoRoot === true or $isAutoRoot === null)
+ // Check the cache key.
+ if (isset($this->config['__cache_key']) &&
+ $this->config['__cache_key'] == $cacheKey)
{
- $this->config['site']['root'] = ServerHelper::getSiteRoot($_SERVER);
+ // If the site root URL was automatically defined, we need to re-compute
+ // it in case the website is being run from a different place.
+ $isAutoRoot = $this->getValue('site/is_auto_root');
+ if ($isAutoRoot === true or $isAutoRoot === null)
+ {
+ $this->config['site']['root'] = ServerHelper::getSiteRoot($_SERVER);
+ }
+ return;
}
}
- else
+
+ // Either the cache doesn't exist, is out of date, or has an
+ // incorrect cache key. Parse the original config file.
+ $config = array();
+ foreach ($this->paths as $i => $path)
{
- $config = array();
- foreach ($this->paths as $i => $path)
+ try
{
- try
+ $curConfig = Yaml::parse(file_get_contents($path));
+ if ($curConfig != null)
{
- $curConfig = Yaml::parse(file_get_contents($path));
- if ($curConfig != null)
+ if ($this->fixupCallback != null)
{
- if ($this->fixupCallback != null)
- {
- $fixup = $this->fixupCallback;
- $fixup($i, $curConfig);
- }
- $config = self::mergeArrays($config, $curConfig);
+ $fixup = $this->fixupCallback;
+ $fixup($i, $curConfig);
}
- }
- catch (Exception $e)
- {
- throw new PieCrustException("An error was found in the PieCrust configuration file '{$path}': " . $e->getMessage(), 0, $e);
+ $config = self::mergeArrays($config, $curConfig);
}
}
- try
- {
- $this->config = $this->validateConfig($config);
- }
catch (Exception $e)
{
- throw new PieCrustException("Error while validating PieCrust configuration: " . $e->getMessage(), 0, $e);
- }
-
- $yamlMarkup = json_encode($this->config);
- if ($cache != null)
- {
- $cache->write('config', 'json', $yamlMarkup);
+ throw new PieCrustException("An error was found in the PieCrust configuration file: {$path}", 0, $e);
}
}
+ try
+ {
+ $this->config = $this->validateConfig($config);
+ }
+ catch (Exception $e)
+ {
+ throw new PieCrustException("Error while validating PieCrust configuration.", 0, $e);
+ }
+
+ // Create a validation key and save a JSON version in the cache.
+ $this->config['__cache_key'] = $cacheKey;
+ $yamlMarkup = json_encode($this->config);
+ if ($cache