Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('handlebars-base', function (Y, NAME) {
2
 
3
/*!
4
Handlebars.js - Copyright (C) 2011 Yehuda Katz
5
https://raw.github.com/wycats/handlebars.js/master/LICENSE
6
*/
7
// This file contains YUI-specific wrapper code and overrides for the
8
// handlebars-base module.
9
 
10
/**
11
Handlebars is a simple template language inspired by Mustache.
12
 
13
This is a YUI port of the original Handlebars project, which can be found at
14
<https://github.com/wycats/handlebars.js>.
15
 
16
@module handlebars
17
@main handlebars
18
@since 3.5.0
19
*/
20
 
21
/**
22
Provides basic Handlebars template rendering functionality. Use this module when
23
you only need to render pre-compiled templates.
24
 
25
@module handlebars
26
@submodule handlebars-base
27
*/
28
 
29
/**
30
Handlebars is a simple template language inspired by Mustache.
31
 
32
This is a YUI port of the original Handlebars project, which can be found at
33
<https://github.com/wycats/handlebars.js>.
34
 
35
@class Handlebars
36
@since 3.5.0
37
*/
38
var Handlebars = Y.namespace('Handlebars');
39
/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
40
Handlebars.SafeString = {};
41
(function (exports) {
42
"use strict";
43
// Build out our basic SafeString type
44
function SafeString(string) {
45
  this.string = string;
46
}
47
 
48
SafeString.prototype.toString = function() {
49
  return "" + this.string;
50
};
51
 
52
exports["default"] = SafeString;
53
}(Handlebars.SafeString));
54
Handlebars.SafeString = Handlebars.SafeString['default'];
55
/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
56
Handlebars.Utils = {};
57
(function (exports, SafeString) {
58
"use strict";
59
/*jshint -W004 */
60
var escape = {
61
  "&": "&amp;",
62
  "<": "&lt;",
63
  ">": "&gt;",
64
  '"': "&quot;",
65
  "'": "&#x27;",
66
  "`": "&#x60;"
67
};
68
 
69
var badChars = /[&<>"'`]/g;
70
var possible = /[&<>"'`]/;
71
 
72
function escapeChar(chr) {
73
  return escape[chr];
74
}
75
 
76
function extend(obj /* , ...source */) {
77
  for (var i = 1; i < arguments.length; i++) {
78
    for (var key in arguments[i]) {
79
      if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
80
        obj[key] = arguments[i][key];
81
      }
82
    }
83
  }
84
 
85
  return obj;
86
}
87
 
88
exports.extend = extend;var toString = Object.prototype.toString;
89
exports.toString = toString;
90
// Sourced from lodash
91
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
92
var isFunction = function(value) {
93
  return typeof value === 'function';
94
};
95
// fallback for older versions of Chrome and Safari
96
/* istanbul ignore next */
97
if (isFunction(/x/)) {
98
  isFunction = function(value) {
99
    return typeof value === 'function' && toString.call(value) === '[object Function]';
100
  };
101
}
102
var isFunction;
103
exports.isFunction = isFunction;
104
/* istanbul ignore next */
105
var isArray = Array.isArray || function(value) {
106
  return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
107
};
108
exports.isArray = isArray;
109
 
110
function escapeExpression(string) {
111
  // don't escape SafeStrings, since they're already safe
112
  if (string instanceof SafeString) {
113
    return string.toString();
114
  } else if (string == null) {
115
    return "";
116
  } else if (!string) {
117
    return string + '';
118
  }
119
 
120
  // Force a string conversion as this will be done by the append regardless and
121
  // the regex test will do this transparently behind the scenes, causing issues if
122
  // an object's to string has escaped characters in it.
123
  string = "" + string;
124
 
125
  if(!possible.test(string)) { return string; }
126
  return string.replace(badChars, escapeChar);
127
}
128
 
129
exports.escapeExpression = escapeExpression;function isEmpty(value) {
130
  if (!value && value !== 0) {
131
    return true;
132
  } else if (isArray(value) && value.length === 0) {
133
    return true;
134
  } else {
135
    return false;
136
  }
137
}
138
 
139
exports.isEmpty = isEmpty;function appendContextPath(contextPath, id) {
140
  return (contextPath ? contextPath + '.' : '') + id;
141
}
142
 
143
exports.appendContextPath = appendContextPath;
144
}(Handlebars.Utils, Handlebars.SafeString));
145
/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
146
Handlebars.Exception = {};
147
(function (exports) {
148
"use strict";
149
 
150
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
151
 
152
function Exception(message, node) {
153
  var line;
154
  if (node && node.firstLine) {
155
    line = node.firstLine;
156
 
157
    message += ' - ' + line + ':' + node.firstColumn;
158
  }
159
 
160
  var tmp = Error.prototype.constructor.call(this, message);
161
 
162
  // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
163
  for (var idx = 0; idx < errorProps.length; idx++) {
164
    this[errorProps[idx]] = tmp[errorProps[idx]];
165
  }
166
 
167
  if (line) {
168
    this.lineNumber = line;
169
    this.column = node.firstColumn;
170
  }
171
}
172
 
173
Exception.prototype = new Error();
174
 
175
exports["default"] = Exception;
176
}(Handlebars.Exception));
177
Handlebars.Exception = Handlebars.Exception['default'];
178
/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
179
(function (exports, Utils, Exception) {
180
"use strict";
181
var VERSION = "2.0.0";
182
exports.VERSION = VERSION;var COMPILER_REVISION = 6;
183
exports.COMPILER_REVISION = COMPILER_REVISION;
184
var REVISION_CHANGES = {
185
  1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
186
  2: '== 1.0.0-rc.3',
187
  3: '== 1.0.0-rc.4',
188
  4: '== 1.x.x',
189
  5: '== 2.0.0-alpha.x',
190
  6: '>= 2.0.0-beta.1'
191
};
192
exports.REVISION_CHANGES = REVISION_CHANGES;
193
var isArray = Utils.isArray,
194
    isFunction = Utils.isFunction,
195
    toString = Utils.toString,
196
    objectType = '[object Object]';
197
 
198
function HandlebarsEnvironment(helpers, partials) {
199
  this.helpers = helpers || {};
200
  this.partials = partials || {};
201
 
202
  registerDefaultHelpers(this);
203
}
204
 
205
exports.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {
206
  constructor: HandlebarsEnvironment,
207
 
208
  logger: logger,
209
  log: log,
210
 
211
  registerHelper: function(name, fn) {
212
    if (toString.call(name) === objectType) {
213
      if (fn) { throw new Exception('Arg not supported with multiple helpers'); }
214
      Utils.extend(this.helpers, name);
215
    } else {
216
      this.helpers[name] = fn;
217
    }
218
  },
219
  unregisterHelper: function(name) {
220
    delete this.helpers[name];
221
  },
222
 
223
  registerPartial: function(name, partial) {
224
    if (toString.call(name) === objectType) {
225
      Utils.extend(this.partials,  name);
226
    } else {
227
      this.partials[name] = partial;
228
    }
229
  },
230
  unregisterPartial: function(name) {
231
    delete this.partials[name];
232
  }
233
};
234
 
235
function registerDefaultHelpers(instance) {
236
  instance.registerHelper('helperMissing', function(/* [args, ]options */) {
237
    if(arguments.length === 1) {
238
      // A missing field in a {{foo}} constuct.
239
      return undefined;
240
    } else {
241
      // Someone is actually trying to call something, blow up.
242
      throw new Exception("Missing helper: '" + arguments[arguments.length-1].name + "'");
243
    }
244
  });
245
 
246
  instance.registerHelper('blockHelperMissing', function(context, options) {
247
    var inverse = options.inverse,
248
        fn = options.fn;
249
 
250
    if(context === true) {
251
      return fn(this);
252
    } else if(context === false || context == null) {
253
      return inverse(this);
254
    } else if (isArray(context)) {
255
      if(context.length > 0) {
256
        if (options.ids) {
257
          options.ids = [options.name];
258
        }
259
 
260
        return instance.helpers.each(context, options);
261
      } else {
262
        return inverse(this);
263
      }
264
    } else {
265
      if (options.data && options.ids) {
266
        var data = createFrame(options.data);
267
        data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name);
268
        options = {data: data};
269
      }
270
 
271
      return fn(context, options);
272
    }
273
  });
274
 
275
  instance.registerHelper('each', function(context, options) {
276
    if (!options) {
277
      throw new Exception('Must pass iterator to #each');
278
    }
279
 
280
    var fn = options.fn, inverse = options.inverse;
281
    var i = 0, ret = "", data;
282
 
283
    var contextPath;
284
    if (options.data && options.ids) {
285
      contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
286
    }
287
 
288
    if (isFunction(context)) { context = context.call(this); }
289
 
290
    if (options.data) {
291
      data = createFrame(options.data);
292
    }
293
 
294
    if(context && typeof context === 'object') {
295
      if (isArray(context)) {
296
        for(var j = context.length; i<j; i++) {
297
          if (data) {
298
            data.index = i;
299
            data.first = (i === 0);
300
            data.last  = (i === (context.length-1));
301
 
302
            if (contextPath) {
303
              data.contextPath = contextPath + i;
304
            }
305
          }
306
          ret = ret + fn(context[i], { data: data });
307
        }
308
      } else {
309
        for(var key in context) {
310
          if(context.hasOwnProperty(key)) {
311
            if(data) {
312
              data.key = key;
313
              data.index = i;
314
              data.first = (i === 0);
315
 
316
              if (contextPath) {
317
                data.contextPath = contextPath + key;
318
              }
319
            }
320
            ret = ret + fn(context[key], {data: data});
321
            i++;
322
          }
323
        }
324
      }
325
    }
326
 
327
    if(i === 0){
328
      ret = inverse(this);
329
    }
330
 
331
    return ret;
332
  });
333
 
334
  instance.registerHelper('if', function(conditional, options) {
335
    if (isFunction(conditional)) { conditional = conditional.call(this); }
336
 
337
    // Default behavior is to render the positive path if the value is truthy and not empty.
338
    // The `includeZero` option may be set to treat the condtional as purely not empty based on the
339
    // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
340
    if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {
341
      return options.inverse(this);
342
    } else {
343
      return options.fn(this);
344
    }
345
  });
346
 
347
  instance.registerHelper('unless', function(conditional, options) {
348
    return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});
349
  });
350
 
351
  instance.registerHelper('with', function(context, options) {
352
    if (isFunction(context)) { context = context.call(this); }
353
 
354
    var fn = options.fn;
355
 
356
    if (!Utils.isEmpty(context)) {
357
      if (options.data && options.ids) {
358
        var data = createFrame(options.data);
359
        data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]);
360
        options = {data:data};
361
      }
362
 
363
      return fn(context, options);
364
    } else {
365
      return options.inverse(this);
366
    }
367
  });
368
 
369
  instance.registerHelper('log', function(message, options) {
370
    var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
371
    instance.log(level, message);
372
  });
373
 
374
  instance.registerHelper('lookup', function(obj, field) {
375
    return obj && obj[field];
376
  });
377
}
378
 
379
var logger = {
380
  methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
381
 
382
  // State enum
383
  DEBUG: 0,
384
  INFO: 1,
385
  WARN: 2,
386
  ERROR: 3,
387
  level: 3,
388
 
389
  // can be overridden in the host environment
390
  log: function(level, message) {
391
    if (logger.level <= level) {
392
      var method = logger.methodMap[level];
393
      if (typeof console !== 'undefined' && console[method]) {
394
        console[method].call(console, message);
395
      }
396
    }
397
  }
398
};
399
exports.logger = logger;
400
var log = logger.log;
401
exports.log = log;
402
var createFrame = function(object) {
403
  var frame = Utils.extend({}, object);
404
  frame._parent = object;
405
  return frame;
406
};
407
exports.createFrame = createFrame;
408
}(Handlebars, Handlebars.Utils, Handlebars.Exception));
409
/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
410
Handlebars.VM = {};
411
(function (exports, Utils, Exception, createFrame, COMPILER_REVISION, REVISION_CHANGES) {
412
"use strict";
413
function checkRevision(compilerInfo) {
414
  var compilerRevision = compilerInfo && compilerInfo[0] || 1,
415
      currentRevision = COMPILER_REVISION;
416
 
417
  if (compilerRevision !== currentRevision) {
418
    if (compilerRevision < currentRevision) {
419
      var runtimeVersions = REVISION_CHANGES[currentRevision],
420
          compilerVersions = REVISION_CHANGES[compilerRevision];
421
      throw new Exception("Template was precompiled with an older version of Handlebars than the current runtime. "+
422
            "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").");
423
    } else {
424
      // Use the embedded version info since the runtime doesn't know about this revision yet
425
      throw new Exception("Template was precompiled with a newer version of Handlebars than the current runtime. "+
426
            "Please update your runtime to a newer version ("+compilerInfo[1]+").");
427
    }
428
  }
429
}
430
 
431
exports.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial
432
 
433
function template(templateSpec, env) {
434
  /* istanbul ignore next */
435
  if (!env) {
436
    throw new Exception("No environment passed to template");
437
  }
438
  if (!templateSpec || !templateSpec.main) {
439
    throw new Exception('Unknown template object: ' + typeof templateSpec);
440
  }
441
 
442
  // Note: Using env.VM references rather than local var references throughout this section to allow
443
  // for external users to override these as psuedo-supported APIs.
444
  env.VM.checkRevision(templateSpec.compiler);
445
 
446
  var invokePartialWrapper = function(partial, indent, name, context, hash, helpers, partials, data, depths) {
447
    if (hash) {
448
      context = Utils.extend({}, context, hash);
449
    }
450
 
451
    var result = env.VM.invokePartial.call(this, partial, name, context, helpers, partials, data, depths);
452
 
453
    if (result == null && env.compile) {
454
      var options = { helpers: helpers, partials: partials, data: data, depths: depths };
455
      partials[name] = env.compile(partial, { data: data !== undefined, compat: templateSpec.compat }, env);
456
      result = partials[name](context, options);
457
    }
458
    if (result != null) {
459
      if (indent) {
460
        var lines = result.split('\n');
461
        for (var i = 0, l = lines.length; i < l; i++) {
462
          if (!lines[i] && i + 1 === l) {
463
            break;
464
          }
465
 
466
          lines[i] = indent + lines[i];
467
        }
468
        result = lines.join('\n');
469
      }
470
      return result;
471
    } else {
472
      throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
473
    }
474
  };
475
 
476
  // Just add water
477
  var container = {
478
    lookup: function(depths, name) {
479
      var len = depths.length;
480
      for (var i = 0; i < len; i++) {
481
        if (depths[i] && depths[i][name] != null) {
482
          return depths[i][name];
483
        }
484
      }
485
    },
486
    lambda: function(current, context) {
487
      return typeof current === 'function' ? current.call(context) : current;
488
    },
489
 
490
    escapeExpression: Utils.escapeExpression,
491
    invokePartial: invokePartialWrapper,
492
 
493
    fn: function(i) {
494
      return templateSpec[i];
495
    },
496
 
497
    programs: [],
498
    program: function(i, data, depths) {
499
      var programWrapper = this.programs[i],
500
          fn = this.fn(i);
501
      if (data || depths) {
502
        programWrapper = program(this, i, fn, data, depths);
503
      } else if (!programWrapper) {
504
        programWrapper = this.programs[i] = program(this, i, fn);
505
      }
506
      return programWrapper;
507
    },
508
 
509
    data: function(data, depth) {
510
      while (data && depth--) {
511
        data = data._parent;
512
      }
513
      return data;
514
    },
515
    merge: function(param, common) {
516
      var ret = param || common;
517
 
518
      if (param && common && (param !== common)) {
519
        ret = Utils.extend({}, common, param);
520
      }
521
 
522
      return ret;
523
    },
524
 
525
    noop: env.VM.noop,
526
    compilerInfo: templateSpec.compiler
527
  };
528
 
529
  var ret = function(context, options) {
530
    options = options || {};
531
    var data = options.data;
532
 
533
    ret._setup(options);
534
    if (!options.partial && templateSpec.useData) {
535
      data = initData(context, data);
536
    }
537
    var depths;
538
    if (templateSpec.useDepths) {
539
      depths = options.depths ? [context].concat(options.depths) : [context];
540
    }
541
 
542
    return templateSpec.main.call(container, context, container.helpers, container.partials, data, depths);
543
  };
544
  ret.isTop = true;
545
 
546
  ret._setup = function(options) {
547
    if (!options.partial) {
548
      container.helpers = container.merge(options.helpers, env.helpers);
549
 
550
      if (templateSpec.usePartial) {
551
        container.partials = container.merge(options.partials, env.partials);
552
      }
553
    } else {
554
      container.helpers = options.helpers;
555
      container.partials = options.partials;
556
    }
557
  };
558
 
559
  ret._child = function(i, data, depths) {
560
    if (templateSpec.useDepths && !depths) {
561
      throw new Exception('must pass parent depths');
562
    }
563
 
564
    return program(container, i, templateSpec[i], data, depths);
565
  };
566
  return ret;
567
}
568
 
569
exports.template = template;function program(container, i, fn, data, depths) {
570
  var prog = function(context, options) {
571
    options = options || {};
572
 
573
    return fn.call(container, context, container.helpers, container.partials, options.data || data, depths && [context].concat(depths));
574
  };
575
  prog.program = i;
576
  prog.depth = depths ? depths.length : 0;
577
  return prog;
578
}
579
 
580
exports.program = program;function invokePartial(partial, name, context, helpers, partials, data, depths) {
581
  var options = { partial: true, helpers: helpers, partials: partials, data: data, depths: depths };
582
 
583
  if(partial === undefined) {
584
    throw new Exception("The partial " + name + " could not be found");
585
  } else if(partial instanceof Function) {
586
    return partial(context, options);
587
  }
588
}
589
 
590
exports.invokePartial = invokePartial;function noop() { return ""; }
591
 
592
exports.noop = noop;function initData(context, data) {
593
    if(!data || (typeof data !== "object")) {
594
        data = {root: context};
595
    } else if(!('root' in data)) {
596
        data = createFrame(data);
597
        data.root = context;
598
    }
599
    return data;
600
}
601
}(Handlebars.VM, Handlebars.Utils, Handlebars.Exception, Handlebars.createFrame, Handlebars.COMPILER_REVISION, Handlebars.REVISION_CHANGES));
602
Handlebars.template = Handlebars.VM.template;
603
// This file contains YUI-specific wrapper code and overrides for the
604
// handlebars-base module.
605
 
606
Handlebars.VERSION += '-yui';
607
 
608
/**
609
Registers a helper function that will be made available to all templates.
610
 
611
Helper functions receive the current template context as the `this` object, and
612
can also receive arguments passed by the template.
613
 
614
@example
615
 
616
    Y.Handlebars.registerHelper('linkify', function () {
617
        return '<a href="' + Y.Escape.html(this.url) + '">' +
618
            Y.Escape.html(this.text) + '</a>';
619
    });
620
 
621
    var source = '<ul>{{#links}}<li>{{{linkify}}}</li>{{/links}}</ul>';
622
 
623
    Y.Handlebars.render(source, {
624
        links: [
625
            {url: '/foo', text: 'Foo'},
626
            {url: '/bar', text: 'Bar'},
627
            {url: '/baz', text: 'Baz'}
628
        ]
629
    });
630
 
631
@method registerHelper
632
@param {String} name Name of this helper.
633
@param {Function} fn Helper function.
634
@param {Boolean} [inverse=false] If `true`, this helper will be considered an
635
    "inverse" helper, like "unless". This means it will only be called if the
636
    expression given in the template evaluates to a false or empty value.
637
*/
638
 
639
/**
640
Registers a partial that will be made available to all templates.
641
 
642
A partial is another template that can be used to render part of a larger
643
template. For example, a website with a common header and footer across all its
644
pages might use a template for each page, which would call shared partials to
645
render the headers and footers.
646
 
647
Partials may be specified as uncompiled template strings or as compiled template
648
functions.
649
 
650
@example
651
 
652
    Y.Handlebars.registerPartial('header', '<h1>{{title}}</h1>');
653
    Y.Handlebars.registerPartial('footer', 'Copyright (c) 2011 by Me.');
654
 
655
    var source = '{{> header}} <p>Mustaches are awesome!</p> {{> footer}}';
656
 
657
    Y.Handlebars.render(source, {title: 'My Page About Mustaches'});
658
 
659
@method registerPartial
660
@param {String} name Name of this partial.
661
@param {Function|String} partial Template string or compiled template function.
662
*/
663
 
664
/**
665
Converts a precompiled template into a renderable template function.
666
 
667
@example
668
 
669
    <script src="precompiled-template.js"></script>
670
    <script>
671
    YUI().use('handlebars-base', function (Y) {
672
        // Convert the precompiled template function into a renderable template
673
        // function.
674
        var template = Y.Handlebars.template(precompiledTemplate);
675
 
676
        // Render it.
677
        template({pie: 'Pumpkin'});
678
    });
679
    </script>
680
 
681
@method template
682
@param {Function} template Precompiled Handlebars template function.
683
@return {Function} Compiled template function.
684
*/
685
 
686
// Alias for Y.Handlebars.template(), used by Y.Template.
687
Handlebars.revive = Handlebars.template;
688
 
689
// Make Y.Template.Handlebars an alias for Y.Handlebars.
690
Y.namespace('Template').Handlebars = Handlebars;
691
 
692
 
693
}, '3.18.1', {"requires": []});