Skip to content

Commit

Permalink
Combine write() and dryrun() methods into run(), with the last argume…
Browse files Browse the repository at this point in the history
…nt determining method
  • Loading branch information
mogelbrod committed May 19, 2016
1 parent e050cd2 commit f026234
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
6 changes: 2 additions & 4 deletions core/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function siteAction() {
$builder = new Builder();
$confirm = r::is('POST') and r::get('confirm');

if ($confirm) $builder->write($site);
else $builder->dryrun($site);
$builder->run($site, $confirm);

$data = [
'mode' => 'site',
Expand Down Expand Up @@ -48,8 +47,7 @@ function pageAction($uri) {
$data['error'] = "Error: Cannot find page for \"$uri\"";
}
else {
if ($confirm) $builder->write($page);
else $builder->dryrun($page);
$builder->run($page, $confirm);
$data['summary'] = $builder->summary;
}
return $builder->htmlReport($data);
Expand Down
51 changes: 17 additions & 34 deletions core/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,61 +425,44 @@ protected function showFatalError() {
/**
* Build or rebuild static content
* @param Page|Pages|Site $content Content to write to the static folder
* @param boolean $write Build pages - set to false to dry-run
* @return array
*/
public function write($content) {
public function run($content, $write=true) {
$this->summary = [];

// Kill PHP Error reporting when building pages, to "catch" PHP errors
// from the pages or their controllers (and plugins etc.). We're going
// to try to hande it ourselves
$level = error_reporting();
$catchErrors = c::get('plugin.staticbuilder.catcherrors', false);
if ($catchErrors) {
$this->shutdown = function () { $this->showFatalError(); };
register_shutdown_function($this->shutdown);
error_reporting(0);
if ($write) {
// Kill PHP Error reporting when building pages, to "catch" PHP errors
// from the pages or their controllers (and plugins etc.). We're going
// to try to hande it ourselves
$level = error_reporting();
$catchErrors = c::get('plugin.staticbuilder.catcherrors', false);
if ($catchErrors) {
$this->shutdown = function () { $this->showFatalError(); };
register_shutdown_function($this->shutdown);
error_reporting(0);
}
}

if ($content instanceof Site) {
foreach ($this->assets as $from=>$to) {
$this->copyAsset($from, $to, true);
$this->copyAsset($from, $to, $write);
}
foreach ($this->routes as $route) {
$this->buildRoute($route, true);
$this->buildRoute($route, $write);
}
}
foreach($this->getPages($content) as $page) {
$this->buildPage($page, true);
$this->buildPage($page, $write);
}

// Restore error reporting if building pages worked
if ($catchErrors) {
if ($write && $catchErrors) {
error_reporting($level);
$this->shutdown = function () {};
}
}

/**
* Build or rebuild static content
* @param Page|Pages|Site $content Content to write to the static folder
* @return array
*/
public function dryrun($content) {
$this->summary = [];
if ($content instanceof Site) {
foreach ($this->assets as $from=>$to) {
$this->copyAsset($from, $to, false);
}
foreach ($this->routes as $route) {
$this->buildRoute($route, false);
}
}
foreach($this->getPages($content) as $page) {
$this->buildPage($page, false);
}
}

/**
* Render the HTML report page
*
Expand Down

0 comments on commit f026234

Please sign in to comment.