Skip to content

Instantly share code, notes, and snippets.

@renan
Last active December 15, 2015 13:49
Show Gist options
  • Select an option

  • Save renan/5270437 to your computer and use it in GitHub Desktop.

Select an option

Save renan/5270437 to your computer and use it in GitHub Desktop.
diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
index b54e4d5..316c618 100644
--- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
+++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
@@ -605,6 +605,22 @@ class HtmlHelperTest extends CakeTestCase {
}
/**
+ * testCssWithFullBase method
+ *
+ * @return void
+ */
+ public function testCssWithFullBase() {
+ Configure::write('Asset.filter.css', false);
+ $here = $this->Html->url('/', true);
+
+ $result = $this->Html->css('screen', null, array('fullBase' => true));
+ $expected = array(
+ 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $here . 'css/screen.css')
+ );
+ $this->assertTags($result, $expected);
+ }
+
+/**
* testPluginCssLink method
*
* @return void
@@ -977,6 +993,30 @@ class HtmlHelperTest extends CakeTestCase {
}
/**
+ * testScriptWithFullBase method
+ *
+ * @return void
+ */
+ public function testScriptWithFullBase() {
+ $here = $this->Html->url('/', true);
+
+ $result = $this->Html->script('foo', array('fullBase' => true));
+ $expected = array(
+ 'script' => array('type' => 'text/javascript', 'src' => $here . 'js/foo.js')
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
+ $expected = array(
+ array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/foobar.js')),
+ '/script',
+ array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/bar.js')),
+ '/script',
+ );
+ $this->assertTags($result, $expected);
+ }
+
+/**
* test a script file in the webroot/theme dir.
*
* @return void
diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php
index 18587a3..f82d221 100644
--- a/lib/Cake/View/Helper/HtmlHelper.php
+++ b/lib/Cake/View/Helper/HtmlHelper.php
@@ -398,6 +398,7 @@ class HtmlHelper extends AppHelper {
* - `block` Set the name of the block link/style tag will be appended to. This overrides the `inline`
* option.
* - `plugin` False value will prevent parsing path as a plugin
+ * - `fullBase` If true the url will get a full address for the css file.
*
* @param string|array $path The name of a CSS style sheet or an array containing names of
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
@@ -429,6 +430,7 @@ class HtmlHelper extends AppHelper {
$url = $path;
} else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));
+ $options = array_diff_key($options, array('fullBase' => ''));
if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
@@ -488,6 +490,7 @@ class HtmlHelper extends AppHelper {
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
* included once, use false to allow the same script to be included more than once per request.
* - `plugin` False value will prevent parsing path as a plugin
+ * - `fullBase` If true the url will get a full address for the script file.
*
* @param string|array $url String or array of javascript files to include
* @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
@@ -523,6 +526,7 @@ class HtmlHelper extends AppHelper {
if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js'));
+ $options = array_diff_key($options, array('fullBase' => ''));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment