Skip to content

Commit

Permalink
merged branch llaville/templates (PR fabpot-graveyard#63)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Commits
-------

fe426eb allow to customize templates location (for each channel)

Discussion
----------

Customize templates location and use different theme

Hello,

On my way to use our own template with Pirum, I've first created Pirus [1].
Now as I don't want to follow Pirum updates, I propose this PR with its explain at [2]

Tell me if you think that this request could be include or not in Pirum.

Regards

[1] https://github.com/llaville/Pirus
[2] http://php5.laurent-laville.org/pirus/pirum.html

---------------------------------------------------------------------------

by llaville at 2013-01-09T17:11:47Z

Hello to all readers,

My Pull Request is now a reality it you want to try it : it's [Pirus](https://github.com/llaville/Pirus) 2.0

Depending of Fabien answer, just in case he don"t want to integrate, I'll continue to maintain my forked version even if I'm the only user of Pirus. So keep serene, for the future of this fork !

Current version is based on the latest repository version of Pirum, and interface is the same.
As soon as it will be new feature to Pirum, I'll merge it to Pirus and release a new version.

See the [getting started](http://php5.laurent-laville.org/pirus/manual/current/en/getting-started.html) part of my documentation to learn more about the configuration ability.

Regards,
  • Loading branch information
fabpot committed Mar 8, 2013
2 parents 4be11da + fe426eb commit 645526b
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions pirum
Expand Up @@ -212,6 +212,7 @@ class Pirum_Builder
protected $server;
protected $packages;
protected $formatter;
protected $templateConf;

public function __construct($targetDir, $formatter = false)
{
Expand Down Expand Up @@ -246,6 +247,29 @@ class Pirum_Builder

$this->server->url = rtrim($this->server->url, '/');

if (DIRECTORY_SEPARATOR == '/') {
$configFile = '.pirumrc';
} else {
$configFile = 'pirum.ini';
}

$defaultConf = array(
'pirum' => array(
'template' => '',
'templatedir' => dirname(__FILE__) . '/templates'
)
);
if (file_exists(dirname(__FILE__) . "/$configFile")) {
$customConf = parse_ini_file($configFile, true);
if ($customConf === false) {
// if config file could not be parsed; use default values
$customConf = array();
}
} else {
$customConf = array();
}
$this->templateConf = array_merge($defaultConf, $customConf);

$this->formatter = $formatter;
$this->targetDir = $targetDir;
$this->buildDir = sys_get_temp_dir().'/pirum_build_'.uniqid();
Expand Down Expand Up @@ -396,12 +420,42 @@ EOF;
file_put_contents($this->buildDir.'/feed.xml', $index);
}

protected function getTemplateFile($name)
{
if (array_key_exists($this->targetDir, $this->templateConf)) {
// check first if a specific server template is defined
$templateConf = $this->templateConf[$this->targetDir];
if (isset($templateConf['templatedir'])) {
$dir = $templateConf['templatedir'];
} else {
// fallback to default template location
$dir = $this->templateConf['pirum']['templatedir'];
}
$file = $dir;
if (isset($templateConf['template'])
&& !empty($templateConf['template'])
) {
$file .= '/' . $templateConf['template'];
}
} else {
// use default template
$file = $this->templateConf['pirum']['templatedir'];
if (!empty($this->templateConf['pirum']['template'])) {
$file .= '/' . $this->templateConf['pirum']['template'];
}
}
$file .= "/$name";

return $file;
}

protected function buildCss()
{
if (file_exists($file = dirname(__FILE__).'/templates/pirum.css') ||
if (file_exists($file = $this->getTemplateFile('pirum.css')) ||
file_exists($file = $this->buildDir.'/templates/pirum.css')) {
$content = file_get_contents($file);
} else {
// fallback in case of external template is not readable
$content = <<<EOF
/*
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Expand Down Expand Up @@ -440,8 +494,8 @@ EOF;
$this->formatter and print $this->formatter->formatSection('INFO', "Building index.");

$version = Pirum_CLI::version();

if (file_exists($file = dirname(__FILE__).'/templates/index.html') ||
if (file_exists($file = $this->getTemplateFile('index.html')) ||
file_exists($file = $this->buildDir.'/templates/index.html')) {
ob_start();
include $file;
Expand All @@ -451,7 +505,7 @@ EOF;

return;
}

// fallback in case of external template is not readable
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Expand Down

0 comments on commit 645526b

Please sign in to comment.