Skip to content

Commit

Permalink
Added new options for filteriing extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Feb 15, 2014
1 parent 2eac330 commit c2b3fa4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/Herbie/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function __construct($sitePath, array $values = array())
$this['menu'] = $this->share(function () use ($app, $config) {
$cache = $app['cache.data'];
$path = $config['pages']['path'];
$builder = new Menu\MenuCollectionBuilder($this['parser'], $cache);
$extensions = $config['pages']['extensions'];
$builder = new Menu\MenuCollectionBuilder($this['parser'], $cache, $extensions);
return $builder->build($path);
});

Expand All @@ -116,7 +117,8 @@ public function __construct($sitePath, array $values = array())
$this['posts'] = $this->share(function () use ($app, $config) {
$cache = $app['cache.data'];
$path = $config['posts']['path'];
$builder = new Blog\PostCollectionBuilder($this['parser'], $cache);
$extensions = $config['posts']['extensions'];
$builder = new Blog\PostCollectionBuilder($this['parser'], $cache, $extensions);
return $builder->build($path);
});

Expand Down
8 changes: 8 additions & 0 deletions lib/Herbie/Blog/PostCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class PostCollection implements IteratorAggregate, Countable
*/
protected $items;

/**
* Constructor
*/
public function __construct()
{
$this->items = array();
}

/**
* @param PostItem $item
*/
Expand Down
13 changes: 12 additions & 1 deletion lib/Herbie/Blog/PostCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ class PostCollectionBuilder
*/
protected $cache;

/**
* @var array
*/
protected $extensions;

/**
* @param Parser $parser
* @param CacheInterface $cache
* @param array $extensions
*/
public function __construct(Parser $parser, CacheInterface $cache)
public function __construct(Parser $parser, CacheInterface $cache, array $extensions = [])
{
$this->parser = $parser;
$this->cache = $cache;
$this->extensions = $extensions;
}

/**
Expand All @@ -54,6 +61,10 @@ public function build($path)
if (substr($filename, 0, 1) == '.') {
continue;
}
$pathinfo = pathinfo($filename);
if(!in_array($pathinfo['extension'], $this->extensions)) {
continue;
}
$data = $loader->load($realpath.'/'.$filename);
$data['path'] = $realpath.'/'.$filename;
$item = new PostItem($data);
Expand Down
8 changes: 8 additions & 0 deletions lib/Herbie/Menu/MenuCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class MenuCollection implements IteratorAggregate, Countable
*/
protected $items;

/**
* Constructor
*/
public function __construct()
{
$this->items = array();
}

/**
* @param string $route
* @param MenuItem $item
Expand Down
13 changes: 12 additions & 1 deletion lib/Herbie/Menu/MenuCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ class MenuCollectionBuilder
*/
protected $cache;

/**
* @var array
*/
protected $extensions;

/**
* @param Parser $parser
* @param CacheInterface $cache
* @param array $extensions
*/
public function __construct(Parser $parser, CacheInterface $cache)
public function __construct(Parser $parser, CacheInterface $cache, array $extensions = [])
{
$this->parser = $parser;
$this->cache = $cache;
$this->extensions = $extensions;
}

/**
Expand Down Expand Up @@ -65,6 +72,10 @@ public function build($path)

if ($splFileInfo->isFile()) {

if(!in_array($splFileInfo->getExtension(), $this->extensions)) {
continue;
}

$loader = new FrontMatterLoader($this->parser);
$data = $loader->load($path);

Expand Down
6 changes: 4 additions & 2 deletions lib/Herbie/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
'path' => $this['sitePath'] . '/layouts'
],
'pages' => [
'path' => $this['sitePath'] . '/pages'
'path' => $this['sitePath'] . '/pages',
'extensions' => ['md', 'markdown', 'textile', 'htm', 'html', 'rss', 'xml']
],
'posts' => [
'path' => $this['sitePath'] . '/posts'
'path' => $this['sitePath'] . '/posts',
'extensions' => ['md', 'markdown', 'textile', 'htm', 'html', 'rss', 'xml']
],
'data' => [
'path' => $this['sitePath'] . '/data',
Expand Down

0 comments on commit c2b3fa4

Please sign in to comment.