Merge branch 'MDL-57975-master' of git://github.com/ryanwyllie/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 8 Mar 2017 03:54:24 +0000 (11:54 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 10 Mar 2017 18:04:42 +0000 (18:04 +0000)
1  2 
lib/amd/build/templates.min.js
lib/amd/src/templates.js
lib/outputrenderers.php
version.php

index b3f4325,49d1c07..d1cb6ee
Binary files differ
@@@ -34,9 -35,10 +34,10 @@@ define(['core/mustache'
           'core/event',
           'core/yui',
           'core/log',
-          'core/truncate'
++         'core/truncate',
+          'core/user_date'
         ],
-        function(mustache, $, ajax, str, notification, coreurl, config, storage, event, Y, Log, Truncate) {
 -       function(mustache, $, ajax, str, notification, coreurl, log,
 -                config, storage, event, Y, Log, UserDate) {
++       function(mustache, $, ajax, str, notification, coreurl, config, storage, event, Y, Log, Truncate, UserDate) {
  
      // Module variables.
      /** @var {Number} uniqInstances Count of times this constructor has been called. */
          return '"' + content + '"';
      };
  
 +    /**
 +     * Shorten text helper to truncate text and append a trailing ellipsis.
 +     *
 +     * @method shortenTextHelper
 +     * @private
 +     * @param {object} context The current mustache context.
 +     * @param {string} sectionText The text to parse the arguments from.
 +     * @param {function} helper Used to render subsections of the text.
 +     * @return {string}
 +     */
 +    Renderer.prototype.shortenTextHelper = function(context, sectionText, helper) {
 +        // Non-greedy split on comma to grab section text into the length and
 +        // text parts.
 +        var regex = /(.*?),(.*)/;
 +        var parts = sectionText.match(regex);
 +        // The length is the part matched in the first set of parethesis.
 +        var length = parts[1].trim();
 +        // The length is the part matched in the second set of parethesis.
 +        var text = parts[2].trim();
 +        var content = helper(text, context);
 +        return Truncate.truncate(content, {
 +            length: length,
 +            words: true,
 +            ellipsis: '...'
 +        });
 +    };
 +
+     /**
+      * User date helper to render user dates from timestamps.
+      *
+      * @method userDateHelper
+      * @private
+      * @param {object} context The current mustache context.
+      * @param {string} sectionText The text to parse the arguments from.
+      * @param {function} helper Used to render subsections of the text.
+      * @return {string}
+      */
+     Renderer.prototype.userDateHelper = function(context, sectionText, helper) {
+         // Non-greedy split on comma to grab the timestamp and format.
+         var regex = /(.*?),(.*)/;
+         var parts = sectionText.match(regex);
+         var timestamp = helper(parts[1].trim(), context);
+         var format = helper(parts[2].trim(), context);
+         var index = this.requiredDates.length;
+         this.requiredDates.push({
+             timestamp: timestamp,
+             format: format
+         });
+         return '[[_t_' + index + ']]';
+     };
      /**
       * Add some common helper functions to all context objects passed to templates.
       * These helpers match exactly the helpers available in php.
          context.quote = function() {
            return this.quoteHelper.bind(this, context);
          }.bind(this);
 +        context.shortentext = function() {
 +          return this.shortenTextHelper.bind(this, context);
 +        }.bind(this);
+         context.userdate = function() {
+           return this.userDateHelper.bind(this, context);
+         }.bind(this);
          context.globals = {config: config};
          context.currentTheme = themeName;
      };
@@@ -91,7 -91,7 +91,8 @@@ class renderer_base 
              $quotehelper = new \core\output\mustache_quote_helper();
              $jshelper = new \core\output\mustache_javascript_helper($this->page->requires);
              $pixhelper = new \core\output\mustache_pix_helper($this);
 +            $shortentexthelper = new \core\output\mustache_shorten_text_helper();
+             $userdatehelper = new \core\output\mustache_user_date_helper();
  
              // We only expose the variables that are exposed to JS templates.
              $safeconfig = $this->page->requires->get_config_for_javascript($this->page, $this);
                               'quote' => array($quotehelper, 'quote'),
                               'js' => array($jshelper, 'help'),
                               'pix' => array($pixhelper, 'pix'),
-                              'shortentext' => array($shortentexthelper, 'shorten'));
 -                             'userdate' => array($userdatehelper, 'transform'));
++                             'shortentext' => array($shortentexthelper, 'shorten'),
++                             'userdate' => array($userdatehelper, 'transform'),
++                         );
  
              $this->mustache = new Mustache_Engine(array(
                  'cache' => $cachedir,
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2017030700.00;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2017030300.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2017030800.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.