Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Renamed Zepto\Zepto::get_sitemap() to ``Zepto\Zepto::generate_nav…
Browse files Browse the repository at this point in the history
…_html()``. This method now generates pre-formatted HTML, rather than a multidimensional array
  • Loading branch information
hassankhan committed Jan 20, 2014
1 parent ab0ef4c commit c38054a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
20 changes: 14 additions & 6 deletions library/Zepto/Zepto.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,20 @@ protected function create_nav_links()
$content = $container['content'];

// Calls protected function which returns formatted array
$nav_items = $this->get_sitemap();
$nav_html = $this->generate_nav_html();

// Add to ``$container``
$this->container['nav'] = $nav_items;
$this->container['nav'] = array('nav' => $nav_html);
}

protected function get_sitemap()
protected function generate_nav_html()
{

$container = $this->container;
$settings = $container['settings'];
$file_loader = $container['file_loader'];

$nav_html = '';
// Could add a hook here maybe?
$structure = $file_loader->get_directory_map($settings['zepto']['content_dir']);

Expand All @@ -314,6 +315,11 @@ protected function get_sitemap()
// Check if ``$value`` is an array
if (is_array($value)) {

$dropdown_html = '<li class="dropdown">' . PHP_EOL
. '<a href="%s" class="dropdown-toggle" data-toggle="dropdown"> %s <b class="caret"></b></a>' . PHP_EOL
. '<ul class="dropdown-menu">' . PHP_EOL;
$nav_html .= sprintf($dropdown_html, reset($value), ucfirst($key));

foreach ($value as $file_name) {

// Add folder name to file name
Expand All @@ -326,8 +332,10 @@ protected function get_sitemap()
$url = $settings['site']['site_root'] . '/' . str_replace($filth, '', $key . '/' . $file_name);

// Run ``ucfirst()`` on ``$key`` to make it look nice
$nav_items[ucfirst($key)][$title] = $url;
$nav_html .= sprintf('<li><a href="%s"> %s </a></li>' . PHP_EOL, $url, $title);
}

$nav_html .= '</ul></li>' . PHP_EOL;
}
// If not then add to ``$nav_items``
else {
Expand All @@ -339,12 +347,12 @@ protected function get_sitemap()
// Create URL
$url = $settings['site']['site_root'] . '/' . str_replace($filth, '', $value);

$nav_items[$title] = $url;
$nav_html .= sprintf('<li><a href="%s"> %s </a></li>' . PHP_EOL, $url, $title);
}
}
}

return $nav_items;
return $nav_html;
}

// This should be moved into a plugin
Expand Down
6 changes: 1 addition & 5 deletions templates/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
<div class="inner clearfix">
<h1><a href="{{ base_url }}">{{ site_title }}</a></h1>
<ul class="nav">
{% block nav %}
{% for item in nav %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
{% endblock %}
{{ nav | raw }}
</ul>
</div>
</header>
Expand Down
18 changes: 9 additions & 9 deletions tests/Zepto/ZeptoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ public function testLoad_content()

/**
* @covers Zepto\Zepto::create_nav_links()
* @covers Zepto\Zepto::get_sitemap()
* @covers Zepto\Zepto::generate_nav_html()
*/
public function testCreateNavLinks()
{
$expected = array(
'Welcome' => 'Site root URL goes here/',
'Sub' => array(
'Sub Page Index' => 'Site root URL goes here/sub/',
'Sub Page' => 'Site root URL goes here/sub/page'
)
);
$expected = '<li><a href="Site root URL goes here/"> Welcome </a></li>' . PHP_EOL
. '<li class="dropdown">' . PHP_EOL
. '<a href="index.md" class="dropdown-toggle" data-toggle="dropdown"> Sub <b class="caret"></b></a>' . PHP_EOL
. '<ul class="dropdown-menu">' . PHP_EOL
. '<li><a href="Site root URL goes here/sub/"> Sub Page Index </a></li>' . PHP_EOL
. '<li><a href="Site root URL goes here/sub/page"> Sub Page </a></li>' . PHP_EOL
. '</ul></li>' . PHP_EOL;

$zepto = $this->object;
$this->assertEquals($expected, $zepto->container['nav']);
$this->assertEquals(array('nav' => $expected), $zepto->container['nav']);
}

/**
Expand Down

0 comments on commit c38054a

Please sign in to comment.