Skip to content

Commit

Permalink
Fix some bugs in the combined JS/CSS code (most of which I introduced
Browse files Browse the repository at this point in the history
in my last refactor):

1) Actually combine the JS (I was only combining the CSS)
2) Add line breaks between the files and comment them so that we can
   find a specific file inside the blob.
3) Add an HTML comment to help developers figure out why they can't
   find their CSS/JS.
  • Loading branch information
bharat committed Jun 30, 2009
1 parent 325203e commit 95b900d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/gallery/libraries/Admin_View.php
Expand Up @@ -100,7 +100,7 @@ public function __call($function, $args) {

if ($function == "head") {
array_unshift($blocks, $this->combine_files($this->css, "css"));
array_unshift($blocks, $this->combine_files($this->css, "javascript"));
array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
}

if (Session::instance()->get("debug")) {
Expand Down
13 changes: 7 additions & 6 deletions modules/gallery/libraries/Gallery_View.php
Expand Up @@ -74,7 +74,7 @@ protected function combine_files($files, $type) {
$links = array();
$key = array();

foreach (array_keys($this->css) as $file) {
foreach (array_keys($files) as $file) {
$path = DOCROOT . $file;
if (file_exists($path)) {
$stats = stat($path);
Expand All @@ -95,9 +95,9 @@ protected function combine_files($files, $type) {
$contents = "";
foreach ($links as $link) {
if ($type == "css") {
$contents .= $this->process_css($link);
$contents .= "/* $link */\n" . $this->process_css($link) . "\n";
} else {
$contents .= file_get_contents($link);
$contents .= "/* $link */\n" . file_get_contents($link) . "\n";
}
}

Expand All @@ -109,10 +109,11 @@ protected function combine_files($files, $type) {
}

if ($type == "css") {
return html::stylesheet("combined/css/$key", "screen,print,projection", true);
return "<!-- LOOKING FOR YOUR CSS? It's all been combined into the link below -->\n" .
html::stylesheet("combined/css/$key", "screen,print,projection", true);
} else {
// Handcraft the script link because html::script will add a .js extenstion
return html::script("combined/javascript/$key", true);
return "<!-- LOOKING FOR YOUR JAVASCRIPT? It's all been combined into the link below -->\n" .
html::script("combined/javascript/$key", true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/libraries/Theme_View.php
Expand Up @@ -217,7 +217,7 @@ public function __call($function, $args) {

if ($function == "head") {
array_unshift($blocks, $this->combine_files($this->css, "css"));
array_unshift($blocks, $this->combine_files($this->css, "javascript"));
array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
}

if (Session::instance()->get("debug")) {
Expand Down

0 comments on commit 95b900d

Please sign in to comment.