Skip to content

Commit

Permalink
Merge pull request CouscousPHP#138 from leoruhland/feature/cname-meta…
Browse files Browse the repository at this point in the history
…data

Add metadata to generate a CNAME file
  • Loading branch information
mnapoli committed Dec 30, 2015
2 parents 3a7e195 + 668efb5 commit 6eb10e1
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
1 change: 1 addition & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ scripts:
- lessc --clean-css website/less/main.less website/css/all.min.css

baseUrl: http://couscous.io
cname: couscous.io

menu:
items:
Expand Down
10 changes: 5 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ scripts:
after:
- rm website/couscous.phar

# Set this variable to use a Custom Domain
# The content of this variable will be directly inserted into the CNAME file
cname: docs.yourdomain.com

# Any variable you put in this file is also available in the Twig layouts:
title: Hello!

Expand All @@ -45,8 +49,4 @@ baseUrl: http://username.github.io/your-project

## Using a Domain Name with Github Pages and Couscous

To use a CNAME for your Couscous-generated documentation so that your docs point to `docs.yourdomain.com` or something similar, first create the CNAME file and point your DNS to `yourname.github.io`, as detailed in the [Github documentation](https://help.github.com/articles/setting-up-a-custom-domain-with-github-pages/).

To deploy the CNAME file to your `gh-pages` branch automatically with Couscous, simply put the CNAME file in the `website` directory (or whatever template directory you configured) in `couscous.yml`.

Note that this will only work if the you're using embedded templates (versus remote templates). If you're using remote templates, you'll need to copy the remote templates to your repository and configure your `couscous.yml` file to use the embedded template instead.
To use a CNAME for your Couscous-generated documentation so that your docs point to `docs.yourdomain.com` or something similar, set the `cname` variable described above and point your DNS to `yourname.github.io`, as detailed in the [Github documentation](https://help.github.com/articles/setting-up-a-custom-domain-with-github-pages/).
1 change: 1 addition & 0 deletions src/Application/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DI\get('Couscous\Module\Markdown\Step\LoadMarkdownFiles'),
DI\get('Couscous\Module\Template\Step\LoadAssets'),
DI\get('Couscous\Module\Core\Step\AddImages'),
DI\get('Couscous\Module\Core\Step\AddCname'),

DI\get('Couscous\Module\Core\Step\AddFileNameToMetadata'),

Expand Down
22 changes: 22 additions & 0 deletions src/Module/Core/Step/AddCname.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Couscous\Module\Core\Step;

use Couscous\Model\Project;
use Couscous\Module\Template\Model\CnameFile;
use Couscous\Step;

/**
* Add the CNAME file to project.
*
* @author Leonardo Ruhland <[email protected]>
*/
class AddCname implements Step
{
public function __invoke(Project $project)
{
if (isset($project->metadata['cname'])) {
$project->addFile(new CnameFile('CNAME', $project->metadata['cname']));
}
}
}
28 changes: 28 additions & 0 deletions src/Module/Template/Model/CnameFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Couscous\Module\Template\Model;

use Couscous\Model\File;

/**
* @author Leonardo Ruhland <[email protected]>
*/
class CnameFile extends File
{
/**
* @var string
*/
public $content;

public function __construct($relativeFilename, $content)
{
parent::__construct($relativeFilename);

$this->content = $content;
}

public function getContent()
{
return $this->content;
}
}
33 changes: 33 additions & 0 deletions tests/UnitTest/Module/Core/Step/AddCnameTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Couscous\Tests\UnitTest\Module\Template\Step;

use Couscous\Model\Metadata;
use Couscous\Model\Project;
use Couscous\Module\Core\Step\AddCname;

/**
* @covers \Couscous\Model\Project
*/
class AddCnameTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function it_should_add_the_cname_file()
{
$project = new Project('foo', 'bar');

$project->metadata = new Metadata();
$project->metadata['cname'] = 'http://www.couscous.io';

$step = new AddCname();
$step->__invoke($project);

$cnameFiles = $project->findFilesByType('Couscous\Module\Template\Model\CnameFile');

$this->assertCount(1, $cnameFiles);

$this->assertEquals($cnameFiles['CNAME']->content, $project->metadata['cname']);
}
}
1 change: 0 additions & 1 deletion website/CNAME

This file was deleted.

0 comments on commit 6eb10e1

Please sign in to comment.