Added initial named-assets implementation

This commit is contained in:
Andy Miller 2015-02-23 16:30:52 -07:00
parent 686ba8a3f6
commit 2fe6dda365
4 changed files with 73 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@ -55,6 +55,8 @@ assets: # Configuration for Assets Manager (JS, C
css_rewrite: true # Rewrite any CSS relative URLs during pipelining
js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file
js_minify: true # Minify the JS during pipelining
collections:
jquery: system://assets/jquery/jquery-2.1.3.min.js
errors:
display: true # Display full backtrace-style error page

View File

@ -169,6 +169,11 @@ class Assets
$this->config($asset_config);
$this->base_url = $base_url . '/';
// Register any preconfigured collections
foreach ($config->get('system.assets.collections') as $name => $collection) {
$this->registerCollection($name, (array)$collection);
}
}
/**
@ -228,7 +233,9 @@ class Assets
foreach ($asset as $a) {
$this->addCss($a, $priority, $pipeline);
}
return $this;
} elseif (isset($this->collections[$asset])) {
$this->add($this->collections[$asset], $priority, $pipeline);
return $this;
}
@ -267,7 +274,9 @@ class Assets
foreach ($asset as $a) {
$this->addJs($a, $priority, $pipeline);
}
return $this;
} elseif (isset($this->collections[$asset])) {
$this->add($this->collections[$asset], $priority, $pipeline);
return $this;
}
@ -529,17 +538,68 @@ class Assets
return $relative_path . $key;
}
/**
* Return the array of all the registered CSS assets
*
* @return array
*/
public function getCss()
{
return $this->css;
}
/**
* Return the array of all the registered JS assets
*
* @return array
*/
public function getJs()
{
return $this->js;
}
/**
* Return the array of all the registered collections
*
* @return array
*/
public function getCollections()
{
return $this->collections;
}
/**
* Determines if an asset exists as a collection, CSS or JS reference
*
* @param $asset
*
* @return bool
*/
public function exists($asset)
{
if (isset($this->collections[$asset]) ||
isset($this->css[$asset]) ||
isset($this->js[$asset])) {
return true;
} else {
return false;
}
}
/**
* Add/replace collection.
*
* @param string $collectionName
* @param array $assets
* @param bool $overwrite
*
* @return $this
*/
public function registerCollection($collectionName, Array $assets)
public function registerCollection($collectionName, Array $assets, $overwrite = false)
{
$this->collections[$collectionName] = $assets;
if ($overwrite || !isset($this->collections[$collectionName])) {
$this->collections[$collectionName] = $assets;
}
return $this;
}
@ -578,26 +638,6 @@ class Assets
return $this;
}
/**
* Get all CSS assets already added.
*
* @return array
*/
public function getCss()
{
return $this->css;
}
/**
* Get all JavaScript assets already added.
*
* @return array
*/
public function getJs()
{
return $this->js;
}
/**
* Add all CSS assets within $directory (relative to public dir).
*

View File

@ -46,9 +46,11 @@ class Debugger
public function addAssets()
{
if ($this->enabled()) {
$assets = $this->grav['assets'];
// Add jquery library
$assets->add('jquery', 101);
$this->renderer = $this->debugbar->getJavascriptRenderer();
$this->renderer->setIncludeVendors(false);