From 71d361e071cf3ca8f7b5abeae41b8c261f8eff31 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Mon, 23 Apr 2012 22:48:16 -0500 Subject: [PATCH 1/3] Configuration option to set different server for asset files. --- application/config/application.php | 14 ++++++++++++++ laravel/bundle.php | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/application/config/application.php b/application/config/application.php index 01f07845..8923c543 100755 --- a/application/config/application.php +++ b/application/config/application.php @@ -15,6 +15,20 @@ return array( 'url' => '', + /* + |-------------------------------------------------------------------------- + | Asset URL + |-------------------------------------------------------------------------- + | + | The base URL used for your application's asset files, if you are serving + | them through a different server or a content delivery network, for + | example. If it's not set, we'll default to the application URL (above). + | Leave off the trailing slash. + | + */ + + 'asset_url' => '', + /* |-------------------------------------------------------------------------- | Application Index diff --git a/laravel/bundle.php b/laravel/bundle.php index 15b9b3da..f2949d77 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -297,7 +297,9 @@ class Bundle { { if (is_null($bundle)) return static::assets(DEFAULT_BUNDLE); - return ($bundle != DEFAULT_BUNDLE) ? URL::base()."/bundles/{$bundle}/" : URL::base().'/'; + $server = Config::get('application.asset_url', URL::base() ); + + return ($bundle != DEFAULT_BUNDLE) ? $server."/bundles/{$bundle}/" : $server.'/'; } /** From 11b0d243ff19c05ba5898081cb791266b5b4e852 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Mon, 23 Apr 2012 23:43:09 -0500 Subject: [PATCH 2/3] Fixes --- laravel/bundle.php | 4 +--- laravel/url.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/laravel/bundle.php b/laravel/bundle.php index f2949d77..32965390 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -297,9 +297,7 @@ class Bundle { { if (is_null($bundle)) return static::assets(DEFAULT_BUNDLE); - $server = Config::get('application.asset_url', URL::base() ); - - return ($bundle != DEFAULT_BUNDLE) ? $server."/bundles/{$bundle}/" : $server.'/'; + return ($bundle != DEFAULT_BUNDLE) ? "/bundles/{$bundle}/" : '/'; } /** diff --git a/laravel/url.php b/laravel/url.php index ec2de9e5..9c73526e 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -220,6 +220,18 @@ class URL { */ public static function to_asset($url, $https = null) { + + // If the URL is already well-formed, just return it + if (static::valid($url)) return $url; + + // If a base asset URL is defined in the configuration, use that and + // don't try and change links to http/https. + if ($root = Config::get('application.asset_url', false )) { + + return rtrim($root, '/').'/'.ltrim($url, '/'); + + } + if (is_null($https)) $https = Request::secure(); $url = static::to($url, $https); From 95dc06ad2f2c8baea0cc817b5101a206e615dc77 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Mon, 23 Apr 2012 23:44:31 -0500 Subject: [PATCH 3/3] whitespace fix --- application/config/application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/config/application.php b/application/config/application.php index 8923c543..8baf172b 100755 --- a/application/config/application.php +++ b/application/config/application.php @@ -15,8 +15,8 @@ return array( 'url' => '', - /* - |-------------------------------------------------------------------------- + /* + |-------------------------------------------------------------------------- | Asset URL |-------------------------------------------------------------------------- |