Skip to content

Commit

Permalink
Support for YAML Front Matter and choice of template
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Jan 25, 2014
1 parent 9301873 commit 13a4632
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 15 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"symfony/process": "~2.4",
"symfony/yaml": "~2.4",
"erusev/parsedown": "~0.8",
"phine/phar": "~1.0"
"phine/phar": "~1.0",
"mnapoli/front-yaml": "~1.0"
}
}
6 changes: 6 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
baseUrl: http://mnapoli.github.io/Couscous

directory: website

exclude:
- vendor
- bin

before:
- bin/compile
- cp bin/couscous.phar website/public/
Expand Down
1 change: 1 addition & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function generate(Config $config, $sourceDirectory, $targetDirectory, Out
->ignoreDotFiles(true)
->exclude(array_merge($config->exclude, array('.generated')))
->name('*.md');

foreach ($finder as $file) {
/** @var SplFileInfo $file */
$output->writeln('Processing ' . $file->getRelativePathname());
Expand Down
9 changes: 9 additions & 0 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class Page extends \stdClass
{
/**
* File name (no path).
*
* @var string
*/
public $filename;
Expand All @@ -30,6 +32,13 @@ class Page extends \stdClass
*/
public $content;

/**
* Template to use to render the page.
*
* @var string
*/
public $template = 'page';

public function __construct($filename, $content)
{
$this->filename = $filename;
Expand Down
14 changes: 13 additions & 1 deletion src/Processor/MarkdownProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Couscous\Processor;

use Couscous\Page;
use Mni\FrontYAML\Parser;

/**
* Turns Markdown to HTML.
Expand All @@ -16,6 +17,17 @@ class MarkdownProcessor implements Processor
*/
public function process(Page $page)
{
$page->content = \Parsedown::instance()->parse($page->content);
$parser = new Parser();

$document = $parser->parse($page->content);

$yaml = $document->getYAML();
if (is_array($yaml)) {
foreach ($yaml as $property => $value) {
$page->$property = $value;
}
}

$page->content = $document->getContent();
}
}
2 changes: 1 addition & 1 deletion src/Processor/TwigProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function process(Page $page)
$context = (array) $page;
$context['baseUrl'] = $this->baseUrl;

$page->content = $this->twig->render('page.twig', $context);
$page->content = $this->twig->render($page->template . '.twig', $context);
}
}
22 changes: 22 additions & 0 deletions website/home.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "page.twig" %}

{% block content %}
<div class="container">
<div class="jumbotron">
<h1>This is Couscous!</h1>
<p>
Couscous is good.
</p>
</div>

<section>
{{ content|raw }}
</section>
</div>

<footer>
<div class="container">
<p class="text-muted">This website was generated using Couscous (obviously…)</p>
</div>
</footer>
{% endblock %}
12 changes: 7 additions & 5 deletions website/page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
</div>
</div>

<div class="container">
{% block content %}

<section>
{{ content|raw }}
</section>
<div class="container">
<section>
{{ content|raw }}
</section>
</div>

</div>
{% endblock %}

<script src="{{ baseUrl }}/js/jquery-1.10.2.min.js"></script>
<script src="{{ baseUrl }}/js/bootstrap.min.js"></script>
Expand Down
22 changes: 15 additions & 7 deletions website/public/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ body {
font-size: 15px;
}

h2 {
margin-top: 30px;
}

#banner {
border-bottom: none;
}
Expand All @@ -12,18 +16,22 @@ body {
}

footer {
margin: 5em 0;
}
footer li {
float: left;
margin-right: 1.5em;
margin-bottom: 1.5em;
height: 60px;
background-color: #f5f5f5;
margin: 5em 0 0;
}
footer p {
clear: left;
text-align: center;
margin-top: 20px;
margin-bottom: 0;
}

pre.prettyprint {
border: 1px solid #ccc;
padding: 10px;
line-height: 20px;
}

.jumbotron {
margin-top: 40px;
}

0 comments on commit 13a4632

Please sign in to comment.