Commit 0a19949f authored by Brion Vibber's avatar Brion Vibber

Allow theme.ini to specify external CSS URLs, such as Google Font API loaders.

Example theme.ini:

  external="http://fonts.googleapis.com/css?family=Lato:100,100italic,300,300italic,400,400italic,700,700italic,900,900italic"
  include=rebase

Notes:
* URLs must be quoted in the .ini file or the .ini file parser explodes!
* To do multiples, list as external[] instead of external.
* If there's an included base theme, any externals it lists will be included first.
* All externals are loaded before any local styles.
parent 7f42e486
......@@ -267,9 +267,16 @@ class Action extends HTMLOutputter // lawsuit
function primaryCssLink($mainTheme=null, $media=null)
{
$theme = new Theme($mainTheme);
// Some themes may have external stylesheets, such as using the
// Google Font APIs to load webfonts.
foreach ($theme->getExternals() as $url) {
$this->cssLink($url, $mainTheme, $media);
}
// If the currently-selected theme has dependencies on other themes,
// we'll need to load their display.css files as well in order.
$theme = new Theme($mainTheme);
$baseThemes = $theme->getDeps();
foreach ($baseThemes as $baseTheme) {
$this->cssLink('css/display.css', $baseTheme, $media);
......
......@@ -56,6 +56,9 @@ class Theme
var $name = null;
var $dir = null;
var $path = null;
protected $metadata = null; // access via getMetadata() lazy-loader
protected $externals = null;
protected $deps = null;
/**
* Constructor
......@@ -199,9 +202,12 @@ class Theme
*/
function getDeps()
{
$chain = $this->doGetDeps(array($this->name));
array_pop($chain); // Drop us back off
return $chain;
if ($this->deps === null) {
$chain = $this->doGetDeps(array($this->name));
array_pop($chain); // Drop us back off
$this->deps = $chain;
}
return $this->deps;
}
protected function doGetDeps($chain)
......@@ -233,6 +239,20 @@ class Theme
* @return associative array of strings
*/
function getMetadata()
{
if ($this->metadata == null) {
$this->metadata = $this->doGetMetadata();
}
return $this->metadata;
}
/**
* Pull data from the theme's theme.ini file.
* @fixme calling getFile will fall back to default theme, this may be unsafe.
*
* @return associative array of strings
*/
private function doGetMetadata()
{
$iniFile = $this->getFile('theme.ini');
if (file_exists($iniFile)) {
......@@ -242,6 +262,32 @@ class Theme
}
}
/**
* Get list of any external URLs required by this theme and any
* dependencies. These are lazy-loaded from theme.ini.
*
* @return array of URL strings
*/
function getExternals()
{
if ($this->externals == null) {
$data = $this->getMetadata();
if (!empty($data['external'])) {
$ext = (array)$data['external'];
} else {
$ext = array();
}
if (!empty($data['include'])) {
$theme = new Theme($data['include']);
$ext = array_merge($ext, $theme->getExternals());
}
$this->externals = array_unique($ext);
}
return $this->externals;
}
/**
* Gets the full path of a file in a theme dir based on its relative name
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment