1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 09:55:33 +02:00

MDL-37127 JavaScript: Add support for development using YUI Shifter

This commit is contained in:
Andrew Robert Nicols 2012-12-06 11:53:07 +00:00
parent cce0d9a100
commit a45e8fd3da
4 changed files with 44 additions and 7 deletions

@ -468,6 +468,9 @@ $CFG->admin = 'admin';
// Prevent theme caching
// $CFG->themerev = -1; // NOT FOR PRODUCTION SERVERS!
//
// Prevent JS caching
// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
//
// Prevent core_string_manager on-disk cache
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
//

@ -198,7 +198,6 @@ class page_requirements_manager {
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep.'moodle/'.$jsrev.'/',
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep,
'combine' => $this->yui3loader->combine,
'filter' => '',
'ext' => false,
'root' => 'moodle/'.$jsrev.'/', // Add the rev to the root path so that we can control caching.
'patterns' => array(
@ -1062,7 +1061,7 @@ class page_requirements_manager {
// Note: in JavaScript just use "YUI().use('overlay', function(Y) { .... });",
// this needs to be done before including any other script.
$js = "var M = {}; M.yui = {};
var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'.'+me.type;};
var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'-min.'+me.type;};
var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-(skin|core)/.test(me.name)) {me.type = 'css';p = p.replace(/-(skin|core)/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/(\-(min|debug))/, '');if (/-skin/.test(me.name)) {p.splice(p.length,0,v,'assets','skins','sam', f);} else {p.splice(p.length,0,v,'assets', f);};} else {p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');};
var yui2in3ConfigFn = function(me) {if(/-skin|reset|fonts|grids|base/.test(me.name)){me.type='css';me.path=me.path.replace(/\.js/,'.css');me.path=me.path.replace(/\/yui2-skin/,'/assets/skins/sam/yui2-skin');}};\n";
$js .= js_writer::set_variable('YUI_config', $this->YUI_config, false) . "\n";

@ -73,6 +73,7 @@ foreach ($parts as $part) {
if (empty($part)) {
continue;
}
$filecontent = '';
$part = min_clean_param($part, 'SAFEPATH');
$bits = explode('/', $part);
if (count($bits) < 2) {
@ -95,13 +96,27 @@ foreach ($parts as $part) {
}
$frankenstyle = array_shift($bits);
$filename = array_pop($bits);
$modulename = $bits[0];
$dir = get_component_directory($frankenstyle);
if ($mimetype == 'text/css') {
$bits[] = 'assets';
$bits[] = 'skins';
$bits[] = 'sam';
}
$contentfile = $dir.'/yui/'.join('/', $bits).'/'.$filename;
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
$frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename));
// By default, try and use the /yui/build directory.
$frankenstylefilename = preg_replace('/' . $modulename . '/', $frankenstylemodulename, $filename);
$contentfile = $dir . '/yui/build/' . $frankenstylemodulename . '/' . $frankenstylefilename;
// If the shifted versions don't exist, fall back to the non-shifted file.
if (!file_exists($contentfile) or !is_file($contentfile)) {
// We have to revert to the non-minified and non-debug versions.
$filename = preg_replace('/-(min|debug)\./', '.', $filename);
$contentfile = $dir . '/yui/' . join('/', $bits) . '/' . $filename;
}
} else if ($version === '2in3') {
$contentfile = "$CFG->libdir/yuilib/$part";
@ -120,7 +135,10 @@ foreach ($parts as $part) {
$content .= "\n// Combo resource $part ($location) not found!\n";
continue;
}
$filecontent = file_get_contents($contentfile);
if (empty($filecontent)) {
$filecontent = file_get_contents($contentfile);
}
$fmodified = filemtime($contentfile);
if ($fmodified > $lastmodified) {
$lastmodified = $fmodified;
@ -131,8 +149,16 @@ foreach ($parts as $part) {
if ($mimetype === 'text/css') {
if ($version == 'moodle') {
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php'.$sep.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent);
// Search for all images in the file and replace with an appropriate link to the yui_image.php script
$imagebits = array(
$sep . $version,
$frankenstyle,
$modulename,
array_shift($bits),
'$1.$2'
);
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot . '/theme/yui_image.php' . implode('/', $imagebits), $filecontent);
} else if ($version == '2in3') {
// First we need to remove relative paths to images. These are used by YUI modules to make use of global assets.
// I've added this as a separate regex so it can be easily removed once

@ -41,7 +41,6 @@ if ($slashargument = min_get_slash_argument()) {
$etag = sha1($path);
$parts = explode('/', $path);
$version = array_shift($parts);
if ($version == 'moodle' && count($parts) >= 3) {
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
define('ABORT_AFTER_CONFIG_CANCEL', true);
@ -54,7 +53,17 @@ if ($version == 'moodle' && count($parts) >= 3) {
$image = array_pop($parts);
$subdir = join('/', $parts);
$dir = get_component_directory($frankenstyle);
$imagepath = $dir.'/yui/'.$module.'/assets/skins/sam/'.$image;
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
$frankenstylemodulename = join('-', array($version, $frankenstyle, $module));
// By default, try and use the /yui/build directory.
$imagepath = $dir . '/yui/build/' . $frankenstylemodulename . '/assets/skins/sam/' . $image;
// If the shifted versions don't exist, fall back to the non-shifted file.
if (!file_exists($imagepath) or !is_file($imagepath)) {
$imagepath = $dir . '/yui/' . $module . '/assets/skins/sam/' . $image;
}
} else if ($version == 'gallery' && count($parts)==3) {
list($module, $version, $image) = $parts;
$imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image";