Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enh component packages #444

Merged
merged 4 commits into from

2 participants

@magefad

#414, #263

In future need to make the same with widgets (which have own assets), with the division each assets in separate folder (and publish when calling).

@hijarian

OH MY GOD you replaced the member function with the global dependency, how in hell I am supposed to unit test code like that? Please, refrain from such a changes, I'm going to purge explicit usage of Yii::app() from the whole codebase altogether.

@hijarian
Owner

Packages at last! Awesome! Thank you!

@hijarian hijarian merged commit f266161 into from
@magefad magefad referenced this pull request from a commit in magefad/YiiBooster
@magefad magefad Fixes component after #444 0a1ace7
@magefad magefad referenced this pull request
Merged

Fixes component after #444 #447

@magefad magefad deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @magefad
  2. @magefad

    Fixes

    magefad authored
  3. @magefad

    added phpdoc since

    magefad authored
  4. @magefad

    Update changelog

    magefad authored
This page is out of date. Refresh to see the latest.
View
1  CHANGELOG.md
@@ -9,6 +9,7 @@ Antonio Ramirez.
### YiiBooster version 1.0.7
- **(enh)** Update x-editable-yii from 1.3.0 to 1.4.0 #413 (magefad)
+- **(enh)** Now use Yii clientScript packages functionality with ability to use custom assetsUrl, added option enableCdn (true if YII_DEBUG off, netdna.bootstrapcdn.com CDN used by default) (magefad)
### YiiBooster version 1.0.6
View
731 src/assets/css/bootstrap-combined.no-icons.min.css
731 additions, 0 deletions not shown
View
50 src/assets/packages.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Built-in client script packages.
+ *
+ * Please see {@link CClientScript::packages} for explanation of the structure
+ * of the returned array.
+ *
+ * @author Ruslan Fadeev <fadeevr@gmail.com>
+ */
+ return array(
+ 'bootstrap' => array(
+ 'baseUrl' => $this->enableCdn ? '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/' : $this->_assetsUrl,
+ 'css' => array(YII_DEBUG ? 'css/bootstrap.css' : 'css/bootstrap.min.css'),
+ ),
+ 'bootstrap.js' => array(
+ 'baseUrl' => $this->enableCdn ? '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/' : $this->_assetsUrl,
+ 'js' => array(YII_DEBUG ? 'js/bootstrap.js' : 'js/bootstrap.min.js'),
+ 'depends' => array('jquery'),
+ ),
+ 'responsive' => array(
+ 'baseUrl' => $this->enableCdn ? '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/' : $this->_assetsUrl,
+ 'css' => array(YII_DEBUG ? 'bootstrap-responsive.css' : 'bootstrap-responsive.min.css'),
+ 'depends' => array('bootstrap')
+ ),
+ 'font-awesome' => array(
+ 'baseUrl' => $this->enableCdn ? '//netdna.bootstrapcdn.com/font-awesome/3.0.2/css/' : $this->_assetsUrl,
+ 'css' => array(YII_DEBUG ? 'font-awesome.css' : 'font-awesome.min.css'),
+ ),
+ 'full.css' => array(
+ 'baseUrl' => $this->enableCdn ? '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/' : $this->_assetsUrl,
+ 'css' => array(YII_DEBUG ? 'css/bootstrap-combined.no-icons.css' : 'css/bootstrap-combined.no-icons.min.css'),
+ ),
+ 'bootstrap-yii' => array(
+ 'baseUrl' => $this->_assetsUrl,
+ 'css' => array('css/bootstrap-yii.css'),
+ ),
+ 'jquery-css' => array(
+ 'baseUrl' => $this->_assetsUrl,
+ 'css' => array('css/jquery-ui-bootstrap.css'),
+ ),
+ 'bootbox' => array(
+ 'baseUrl' => $this->_assetsUrl,
+ 'js' => array('js/bootstrap.bootbox.min.js'),
+ ),
+ 'notify' => array(
+ 'baseUrl' => $this->_assetsUrl,
+ 'css' => array('css/bootstrap-notify.css'),
+ 'js' => array('bootstrap.notify.js')
+ ),
+ );
View
201 src/components/Bootstrap.php
@@ -8,10 +8,7 @@
*
* Modified for YiiBooster
* @author Antonio Ramirez <antonio@clevertech.biz>
- * @version 1.0.6
- *
- * Added Bootstrap Modal Manager Plugin
- * @author Thiago Otaviani Vidal <thiagovidal@gmail.com>
+ * @version 1.0.7
*/
/**
@@ -20,6 +17,7 @@
class Bootstrap extends CApplicationComponent
{
// Bootstrap plugins.
+ const PLUGIN_AFFIX = 'affix';
const PLUGIN_ALERT = 'alert';
const PLUGIN_BUTTON = 'button';
const PLUGIN_CAROUSEL = 'carousel';
@@ -36,7 +34,6 @@ class Bootstrap extends CApplicationComponent
const PLUGIN_DATEPICKER = 'bdatepicker';
const PLUGIN_REDACTOR = 'redactor';
const PLUGIN_MARKDOWNEDITOR = 'markdowneditor';
- const PLUGIN_AFFIX = 'affix';
const PLUGIN_DATERANGEPICKER = 'daterangepicker';
const PLUGIN_HTML5EDITOR = 'wysihtml5';
const PLUGIN_COLORPICKER = 'colorpicker';
@@ -103,12 +100,17 @@ class Bootstrap extends CApplicationComponent
public $enableBootboxJS = true;
/**
- * @var bool enable [bootstrap notifier](https://github.com/Nijikokun/bootstrap-notify). Default value is `true`
- * @see [https://github.com/Nijikokun/bootstrap-notify](https://github.com/Nijikokun/bootstrap-notify]
+ * @var bool enable bootstrap notifier. Default value is `true`
+ * @see https://github.com/Nijikokun/bootstrap-notify
*/
public $enableNotifierJS = true;
/**
+ * @var boolean|null enable use cdn servers for assets. Defaults to true if not YII_DEBUG, else false
+ */
+ public $enableCdn = false;
+
+ /**
* @var bool|null Whether to republish assets on each request. Defaults to YII_DEBUG, resulting in a the republication of all YiiBooster-assets
* on each request if the application is in debug mode. Passing null to this option restores
* the default handling of CAssetManager of YiiBooster assets.
@@ -117,6 +119,16 @@ class Bootstrap extends CApplicationComponent
public $forceCopyAssets = false;
/**
+ * @var array list of script packages (name=>package spec).
+ * This property keeps a list of named script packages, each of which can contain
+ * a set of CSS and/or JavaScript script files, and their dependent package names.
+ * By calling {@link registerPackage}, one can register a whole package of client
+ * scripts together with their dependent packages and render them in the HTML output.
+ * @since 1.0.7
+ */
+ public $packages = array();
+
+ /**
* @var string handles the assets folder path.
*/
protected $_assetsUrl;
@@ -134,11 +146,47 @@ public function init()
if (Yii::app() instanceof CConsoleApplication || PHP_SAPI == 'cli')
return;
+ if ($this->enableCdn === null)
+ $this->enableCdn = !YII_DEBUG;
+
+ $this->packages = CMap::mergeArray(
+ require($this->getAssetsUrl() . DIRECTORY_SEPARATOR . 'packages.php'),
+ $this->packages
+ );
+ foreach ($this->packages as $name => $definition)
+ Yii::app()->getClientScript()->addPackage($name, $definition);
+
if ($this->coreCss !== false)
- $this->registerCoreCss();
+ $this->registerAllCss();
+ if ($this->enableJS !== false)
+ $this->registerAllScripts();
+
+ parent::init();
+ }
+
+ /**
+ * Registers all assets.
+ * @since 1.0.7
+ */
+ public function register()
+ {
+ $this->registerAllCss();
+ $this->registerAllScripts();
+ }
+ /**
+ * Registers all Bootstrap CSS files.
+ * @since 1.0.7
+ */
+ public function registerAllCss()
+ {
if ($this->responsiveCss !== false)
- $this->registerResponsiveCss();
+ {
+ Yii::app()->getClientScript()->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
+ Yii::app()->getClientScript()->registerPackage('full.css');
+ }
+ else
+ $this->registerCoreCss();
if ($this->fontAwesomeCss !== false)
$this->registerFontAwesomeCss();
@@ -148,11 +196,15 @@ public function init()
if ($this->jqueryCss !== false)
$this->registerJQueryCss();
+ }
- if ($this->enableJS !== false)
- $this->registerCoreScripts();
-
- parent::init();
+ /**
+ * Registers all Bootstrap JavaScript files.
+ */
+ public function registerAllScripts()
+ {
+ $this->registerCoreScripts();
+ $this->registerTooltipAndPopover();
}
/**
@@ -160,7 +212,7 @@ public function init()
*/
public function registerCoreCss()
{
- $this->registerAssetCss('bootstrap' . (!YII_DEBUG ? '.min' : '') . '.css');
+ Yii::app()->getClientScript()->registerPackage('bootstrap');
}
/**
@@ -169,10 +221,8 @@ public function registerCoreCss()
*/
public function registerResponsiveCss()
{
- /** @var CClientScript $cs */
- $cs = Yii::app()->getClientScript();
- $cs->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
- $cs->registerCssFile($this->getAssetsUrl() . '/css/bootstrap-responsive' . (!YII_DEBUG ? '.min' : '') . '.css');
+ Yii::app()->getClientScript()->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
+ Yii::app()->getClientScript()->registerPackage('responsive');
}
/**
@@ -181,7 +231,7 @@ public function registerResponsiveCss()
*/
public function registerFontAwesomeCss()
{
- $this->registerAssetCss('font-awesome' . (!YII_DEBUG ? '.min' : '') . '.css');
+ Yii::app()->getClientScript()->registerPackage('font-awesome');
}
/**
@@ -190,7 +240,7 @@ public function registerFontAwesomeCss()
*/
public function registerYiiCss()
{
- $this->registerAssetCss('bootstrap-yii.css');
+ Yii::app()->getClientScript()->registerPackage('bootstrap-yii');
}
/**
@@ -199,7 +249,7 @@ public function registerYiiCss()
public function registerJQueryCss()
{
Yii::app()->getClientScript()->scriptMap['jquery-ui.css'] = $this->getAssetsUrl() . '/css/jquery-ui-bootstrap.css';
- $this->registerAssetCss('jquery-ui-bootstrap.css');
+ Yii::app()->getClientScript()->registerPackage('jquery-css');
}
/**
* Registers a specific css in the asset's css folder
@@ -217,36 +267,59 @@ public function registerAssetCss($cssFile, $media = '')
*/
public function registerCoreScripts()
{
- $this->registerJS(Yii::app()->clientScript->coreScriptPosition);
- $this->registerTooltip();
+ /* @var CClientScript $cs */
+ $cs = Yii::app()->getClientScript();
+ $cs->registerPackage('bootstrap.js');
+
+ if ($this->enableBootboxJS)
+ $cs->registerPackage('bootbox');
+
+ if ($this->enableNotifierJS)
+ $cs->registerPackage('notify');
+ }
+
+ /**
+ * Registers the Tooltip and Popover plugins.
+ * @since 1.0.7
+ */
+ public function registerTooltipAndPopover()
+ {
$this->registerPopover();
+ $this->registerTooltip();
}
/**
- * Registers the Bootstrap JavaScript.
- * @param int $position the position of the JavaScript code.
- * @see CClientScript::registerScriptFile
+ * Registers the Bootstrap popover plugin.
+ * @param string $selector the CSS selector
+ * @param array $options the plugin options
+ * @see http://twitter.github.com/bootstrap/javascript.html#popover
+ * @since 0.9.8
*/
- public function registerJS($position = CClientScript::POS_HEAD)
+ public function registerPopover($selector = 'body', $options = array())
{
- /* @var CClientScript $cs */
- $cs = Yii::app()->getClientScript();
- $cs->registerCoreScript('jquery');
+ $this->registerTooltip(); // Popover requires the tooltip plugin
+ if (!isset($options['selector']))
+ $options['selector'] = '[rel=popover]';
- /* enable bootboxJS? */
- if ($this->enableBootboxJS)
- $cs->registerScriptFile($this->getAssetsUrl() . '/js/bootstrap.bootbox.min.js', $position);
+ $this->registerPlugin(self::PLUGIN_POPOVER, $selector, $options, $this->popoverSelector);
+ }
- /* enable bootstrap notifier ? */
- if ($this->enableNotifierJS)
- {
- // notifier requires a style
- $cs->registerCssFile($this->getAssetsUrl() . '/css/bootstrap-notify.css');
- $cs->registerScriptFile($this->getAssetsUrl() . '/js/bootstrap.notify.js', $position);
- }
- $cs->registerScriptFile($this->getAssetsUrl() . '/js/bootstrap' . (!YII_DEBUG ? '.min' : '') . '.js', $position);
+ /**
+ * Registers the Bootstrap tooltip plugin.
+ * @param string $selector the CSS selector
+ * @param array $options the plugin options
+ * @see http://twitter.github.com/bootstrap/javascript.html#tooltip
+ * @since 0.9.8
+ */
+ public function registerTooltip($selector = 'body', $options = array())
+ {
+ if (!isset($options['selector']))
+ $options['selector'] = '[rel=tooltip]';
+
+ $this->registerPlugin(self::PLUGIN_TOOLTIP, $selector, $options, $this->tooltipSelector);
}
+
/**
* Register a specific js file in the asset's js folder
* @param string $jsFile
@@ -355,25 +428,6 @@ public function registerScrollSpy($selector = null, $options = array())
}
/**
- * Registers the Bootstrap popover plugin.
- * @param string $selector the CSS selector
- * @param array $options the plugin options
- * @see http://twitter.github.com/bootstrap/javascript.html#popover
- * @since 0.9.8
- */
- public function registerPopover($selector = null, $options = array())
- {
- $this->registerTooltip(); // Popover requires the tooltip plugin
- if (!isset($options['selector']))
- {
- $options['selector'] = '[rel=popover]';
- if (null === $selector)
- $selector = 'body';
- }
- $this->registerPlugin(self::PLUGIN_POPOVER, $selector, $options, $this->popoverSelector);
- }
-
- /**
* Registers the Bootstrap tabs plugin.
* @param string $selector the CSS selector
* @param array $options the plugin options
@@ -386,24 +440,6 @@ public function registerTabs($selector = null, $options = array())
}
/**
- * Registers the Bootstrap tooltip plugin.
- * @param string $selector the CSS selector
- * @param array $options the plugin options
- * @see http://twitter.github.com/bootstrap/javascript.html#tooltip
- * @since 0.9.8
- */
- public function registerTooltip($selector = null, $options = array())
- {
- if (!isset($options['selector']))
- {
- $options['selector'] = '[rel=tooltip]';
- if (null === $selector)
- $selector = 'body';
- }
- $this->registerPlugin(self::PLUGIN_TOOLTIP, $selector, $options, $this->tooltipSelector);
- }
-
- /**
* Registers the Bootstrap typeahead plugin.
* @param string $selector the CSS selector
* @param array $options the plugin options
@@ -481,7 +517,7 @@ public function registerAffix($selector = null, $options = array())
public function registerDateRangePlugin($selector, $options = array(), $callback = null)
{
$key = __CLASS__ . '.' . md5(self::PLUGIN_DATERANGEPICKER . $selector . serialize($options) . $callback);
- Yii::app()->clientScript->registerScript($key, '$("' . $selector . '").daterangepicker(' . CJavaScript::encode($options) . ($callback ? ', ' . CJavaScript::encode($callback) : '') . ');');
+ Yii::app()->getClientScript()->registerScript($key, '$("' . $selector . '").daterangepicker(' . CJavaScript::encode($options) . ($callback ? ', ' . CJavaScript::encode($callback) : '') . ');');
}
@@ -514,7 +550,7 @@ protected function registerPlugin($name, $selector = null, $options = array(), $
{
$key = __CLASS__ . '.' . md5($name . $selector . serialize($options) . $defaultSelector);
$options = !empty($options) ? CJavaScript::encode($options) : '';
- Yii::app()->clientScript->registerScript($key, "jQuery('{$selector}').{$name}({$options});");
+ Yii::app()->getClientScript()->registerScript($key, "jQuery('{$selector}').{$name}({$options});");
}
}
@@ -528,8 +564,7 @@ public function getAssetsUrl()
return $this->_assetsUrl;
else
{
- $assetsPath = Yii::getPathOfAlias('bootstrap.assets');
- $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, $this->forceCopyAssets);
+ $assetsUrl = Yii::app()->assetManager->publish(Yii::getPathOfAlias('bootstrap.assets'), false, -1, $this->forceCopyAssets);
return $this->_assetsUrl = $assetsUrl;
}
}
@@ -540,6 +575,6 @@ public function getAssetsUrl()
*/
public function getVersion()
{
- return '1.0.6';
+ return '1.0.7';
}
}
Something went wrong with that request. Please try again.