Skip to content

Commit

Permalink
add support for nested styles
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeeich committed Jun 6, 2013
1 parent 9ecdc88 commit fcf97f1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions classes/Kohana/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,37 @@ static public function inject_theme_styles($needLegacyConf=FALSE) {
return;
}

if (! empty($theme)) {
$theme = "skins/%s/%s/$theme";
}
$themeMask = "skins/%s/%s/$theme";

$isDevelopment = self::is_development_controller_script($needLegacyConf);

$scripts = "/{$config->get($isDevelopment ? self::CLIENT_PAGE_TYPE_DEVELOPMENT : self::CLIENT_PAGE_TYPE_PRODUCTION)}";

$ext = $isDevelopment ? self::CLIENT_PAGE_THEME_DEVELOPMENT: self::CLIENT_PAGE_THEME_PRODUCTION;

$prefix = "/{$ext}/{$theme}.{$ext}";

if (! $isDevelopment) {
$builds = array_filter(glob(getcwd() . $scripts . '/' . sprintf($theme, $page . '.*', $ext) . '.' . $ext), function($path) use ($page) {
return preg_replace('/\.\d+$/', '', basename(dirname(dirname($path)))) === $page;
$builds = array_filter(glob(getcwd() . $scripts . '/' . sprintf($themeMask, $page . '.*', $ext) . '.' . $ext), function($path) use ($page, $prefix) {
return preg_replace('/\.\d+$/', '', basename(strstr($path, $prefix, TRUE))) === $page;
});

// и если она найдена осуществляем подмену
if (! empty($builds)) {
// берем последнюю, так как они уже отсортированы
$page = basename(dirname(dirname(array_pop($builds))));
$page = basename(strstr(array_pop($builds), $prefix, TRUE));
}
}

$theme = $scripts . '/' . sprintf($theme, $page, $ext) . '.' . $ext;
$style = $scripts . '/' . sprintf($themeMask, $page, $ext) . '.' . $ext;

$rel = 'stylesheet';

if ($isDevelopment) {
$rel .= '/' . $ext;
}

return HTML::style($theme, array( 'rel' => $rel ));
return HTML::style($style, array( 'rel' => $rel ));
}

/**
Expand Down

0 comments on commit fcf97f1

Please sign in to comment.