Skip to content
Browse files

Added ability to configure fuelphp root path

  • Loading branch information...
1 parent cc00915 commit f9515ea84cf6675cbfe910b52c49560994a41db7 @assembledadam assembledadam committed with
Showing with 17 additions and 5 deletions.
  1. +12 −5 classes/casset.php
  2. +5 −0 config/casset.php
View
17 classes/casset.php
@@ -34,6 +34,11 @@ class Casset {
protected static $asset_url = null;
/**
+ * @var string The URL to be prepanded to all assets.
+ */
+ protected static $root_path = null;
+
+ /**
* @var array The folders in which css, js, and images can be found.
*/
protected static $default_folders = array(
@@ -144,6 +149,8 @@ public static function _init()
static::$asset_url = preg_replace('#^https?://#','//', \Uri::base(false));
static::$asset_url = rtrim(static::$asset_url, '/') . '/';
+ static::$root_path = \Config::get('casset.root_path', DOCROOT);
+
static::$default_folders = array(
'css' => \Config::get('casset.css_dir', static::$default_folders['css']),
'js' => \Config::get('casset.js_dir', static::$default_folders['js']),
@@ -791,7 +798,7 @@ public static function render_js($group = false, $options = array(), $attr_dep =
}
if ($inline)
{
- $content = file_get_contents(DOCROOT.static::$cache_path.$filename);
+ $content = file_get_contents(static::$root_path.static::$cache_path.$filename);
if ($options['gen_tags'])
$ret .= html_tag('script', $attr, PHP_EOL.$content.PHP_EOL).PHP_EOL;
else
@@ -892,7 +899,7 @@ public static function render_css($group = false, $options = array(), $attr_dep
}
if ($inline)
{
- $content = file_get_contents(DOCROOT.static::$cache_path.$filename);
+ $content = file_get_contents(static::$root_path.static::$cache_path.$filename);
// We'll need to fix the uris, unless they were rewritten absolutely to start with
$content = static::css_rewrite_uris($content, static::$cache_path.$filename, \Uri::string());
if ($options['gen_tags'])
@@ -1147,7 +1154,7 @@ protected static function combine($type, $file_group, $minify, $inline)
if (strpos($file['file'], '//') !== false)
continue;
- $mod = filemtime(DOCROOT.$file['file']);
+ $mod = filemtime(static::$root_path.$file['file']);
if ($mod > $last_mod)
$last_mod = $mod;
}
@@ -1157,7 +1164,7 @@ protected static function combine($type, $file_group, $minify, $inline)
}, $file_group)).($minify ? 'min' : '').$last_mod).'.'.$type;
$rel_filepath = static::$cache_path.'/'.$filename;
- $abs_filepath = DOCROOT.$rel_filepath;
+ $abs_filepath = static::$root_path.$rel_filepath;
$needs_update = (!file_exists($abs_filepath));
if ($needs_update)
@@ -1318,7 +1325,7 @@ public static function clear_css_cache($before = 'now')
protected static function clear_cache_base($filter = '*', $before = 'now')
{
$before = strtotime($before);
- $files = glob(DOCROOT.static::$cache_path.$filter);
+ $files = glob(static::$root_path.static::$cache_path.$filter);
foreach ($files as $file)
{
if (filemtime($file) < $before)
View
5 config/casset.php
@@ -48,6 +48,11 @@
'url' => null,
/**
+ * Absolute path to your Fuel root. If null/falsy, this will default to DOCROOT
+ */
+ 'root_path' => null,
+
+ /**
* Asset Sub-folders
*
* Names for the js and css folders (inside the asset path).

0 comments on commit f9515ea

Please sign in to comment.
Something went wrong with that request. Please try again.