Skip to content

Commit

Permalink
Twig.
Browse files Browse the repository at this point in the history
  • Loading branch information
simensen committed Aug 10, 2012
1 parent 6d0e1f3 commit 2831b1e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 15 deletions.
36 changes: 33 additions & 3 deletions Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Configuration extends BaseConfiguration
*
* @var array
*/
private $exclusions = array();
private $excludes = array();

/**
* Ignore patterns
Expand Down Expand Up @@ -100,13 +100,23 @@ public function addExclude($pattern)
$pattern = substr($pattern, 2);
}

if (!in_array($pattern, $this->exclusions)) {
$this->exclusions[] = $pattern;
if (!in_array($pattern, $this->excludes)) {
$this->excludes[] = $pattern;
}

return $this;
}

/**
* Excludes
*
* @return array
*/
public function excludes()
{
return $this->excludes;
}

/**
* Set ignores
*
Expand Down Expand Up @@ -145,6 +155,16 @@ public function addIgnore($pattern)
return $this;
}

/**
* Ignores
*
* @return array
*/
public function ignores()
{
return $this->ignores;
}

/**
* Set raws
*
Expand Down Expand Up @@ -182,6 +202,16 @@ public function addRaw($pattern)
return $this;
}

/**
* Raws
*
* @return array
*/
public function raws()
{
return $this->raws;
}

/**
* Set source directory
*
Expand Down
23 changes: 16 additions & 7 deletions Sculpin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
*/
class Sculpin
{
const EVENT_BEFORE_RUN = 'sculpin.core.beforeRun';
const EVENT_BEFORE_RUN_AGAIN = 'sculpin.core.beforeRunAgain';
const EVENT_AFTER_RUN = 'sculpin.core.afterRun';
const EVENT_BEFORE_RUN = 'sculpin.core.before_run';
const EVENT_BEFORE_RUN_AGAIN = 'sculpin.core.before_run_again';
const EVENT_AFTER_RUN = 'sculpin.core.after_run';

const EVENT_BEFORE_CONVERT = 'sculpin.core.beforeConvert';
const EVENT_AFTER_CONVERT = 'sculpin.core.afterConvert';
const EVENT_BEFORE_CONVERT = 'sculpin.core.before_convert';
const EVENT_AFTER_CONVERT = 'sculpin.core.after_convert';

const EVENT_BEFORE_FORMAT = 'sculpin.core.beforeFormat';
const EVENT_AFTER_FORMAT = 'sculpin.core.afterFormat';
const EVENT_BEFORE_FORMAT = 'sculpin.core.before_format';
const EVENT_AFTER_FORMAT = 'sculpin.core.after_format';

/**
* Configuration
Expand Down Expand Up @@ -104,9 +104,16 @@ public function run(DataSourceInterface $dataSource, SourceSet $sourceSet)
$permalink = $this->permalinkFactory->create($source);
$source->setPermalink($permalink);
$this->convertSource($source);
$originalContent = $source->content();
if ($source->canBeFormatted()) {
$source->setContent($this->formatSourcePage($source));
}

print " !!!!! " . $source->sourceId() . "\n";
print " {{{{{ " . $source->content() . " }}}}}\n\n";
if ($originalContent !== $source->content()) {
print " <<<<< " . $originalContent . " >>>>>\n\n";
}
}

$this->eventDispatcher->dispatch(self::EVENT_AFTER_RUN, new SourceSetEvent($sourceSet));
Expand Down Expand Up @@ -196,6 +203,8 @@ public function buildFormatContext($templateId, $template, $context)
public function registerFormatter($name, FormatterInterface $formatter)
{
$this->formatters[$name] = $formatter;

$this->configuration->setDefaultFormatter($name);
}

/**
Expand Down
58 changes: 53 additions & 5 deletions Source/FilesystemDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sculpin\Core\Source;

use dflydev\util\antPathMatcher\AntPathMatcher;
use Sculpin\Core\Configuration\Configuration;
use Sculpin\Core\Finder\FinderFactory;

Expand Down Expand Up @@ -42,6 +43,9 @@ class FilesystemDataSource implements DataSourceInterface
*/
protected $sourceDir;

protected $finderFactory;
protected $matcher;

/**
* Since time
*
Expand All @@ -52,15 +56,17 @@ class FilesystemDataSource implements DataSourceInterface
/**
* Constructor.
*
* @param Configuration $configuration Configuration
* @param string $sourceDir Source directory
* @param FinderFactory $finderFactory Finder factory
* @param Configuration $configuration Configuration
* @param string $sourceDir Source directory
* @param FinderFactory $finderFactory Finder factory
* @param AntPathMatcher $matcher Matcher
*/
public function __construct(Configuration $configuration, $sourceDir, FinderFactory $finderFactory = null)
public function __construct(Configuration $configuration, $sourceDir, FinderFactory $finderFactory = null, AntPathMatcher $matcher = null)
{
$this->configuration = $configuration;
$this->sourceDir = $sourceDir;
$this->finderFactory = $finderFactory ?: new FinderFactory;
$this->matcher = $matcher ?: new AntPathMatcher;
$this->sinceTime = '1970-01-01T00:00:00Z';
}

Expand All @@ -71,6 +77,9 @@ public function refresh(SourceSet $sourceSet)
{
$sinceTimeLast = $this->sinceTime;

// We regenerate the whole site if an excluded file changes.
$excludedFilesHaveChanged = false;

$files = $this
->finderFactory->create()
->files()
Expand All @@ -79,9 +88,48 @@ public function refresh(SourceSet $sourceSet)
->in($this->sourceDir);

foreach ($files as $file) {
$isRaw = false; // UPDATE
print $file->getRelativePathname()."\n";
foreach ($this->configuration->ignores() as $pattern) {
if (!$this->matcher->isPattern($pattern)) {
continue;
}
if ($this->matcher->match($pattern, $file->getRelativePathname())) {
// Ignored files are completely ignored.
continue 2;
}
}
foreach ($this->configuration->excludes() as $pattern) {
if (!$this->matcher->isPattern($pattern)) {
continue;
}
if ($this->matcher->match($pattern, $file->getRelativePathname())) {
$excludedFilesHaveChanged = true;
continue 2;
}
}

$isRaw = false;

foreach ($this->configuration->raws() as $pattern) {
if (!$this->matcher->isPattern($pattern)) {
continue;
}
if ($this->matcher->match($pattern, $file->getRelativePathname())) {
$isRaw = true;
break;
}
}

$source = new FileSource($file, $isRaw, true);
$sourceSet->mergeSource($source);
}

if ($excludedFilesHaveChanged) {
// If any of the exluded files have changed we should
// mark all of the sources as having changed.
foreach ($sourceSet->allSources() as $source) {
$source->setHasChanged();
}
}
}
}

0 comments on commit 2831b1e

Please sign in to comment.