Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57304

Minify or strip comments from mustache templates

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Test comments stripping

      1) Set theme to boost (note, if already boost then purge caches to wipe out locally cached templates)
      2) Open network tab in chrome
      3) Click new message button
      4) Then click the messages button in the bottom of the messages pane.
      5) Observe the network requests for service-nologin.php and find the request for "message_area_contacts" template - see following request pay load.

      [{"index":0,"methodname":"core_output_load_template","args":{"component":"core_message","template":"message_area_contacts","themename":"boost"}}]
      

      Observe the response for this request no longer contains comments:

      [{"error":false,"data":"\n{{#contacts}}\n    {{> core_message\/message_area_contact }}\n{{\/contacts}}\n{{^contacts}}\n    <div class=\"nocontacts\" data-region=\"no-contacts\">\n        {{#isconversation}}\n            {{#str}}nomessages, message{{\/str}}\n        {{\/isconversation}}\n        {{^isconversation}}\n            {{#str}}nocontacts, message{{\/str}}\n        {{\/isconversation}}\n    <\/div>\n{{\/contacts}}\n"}]
      

      Regression test template library

      1) Open the template library tool

      /admin/tool/templatelibrary/index.php

      2) Set component to 'forum'
      3) Click on link "mod_forum/forum_post_email_htmlemail"

      Expected outcome:

      You can see "Lorem ipsum dolor" text in Example area
      Documentation area is populated (text starting "Template which defines a forum post for sending in a single-post HTML email.")

      Show
      Test comments stripping 1) Set theme to boost (note, if already boost then purge caches to wipe out locally cached templates) 2) Open network tab in chrome 3) Click new message button 4) Then click the messages button in the bottom of the messages pane. 5) Observe the network requests for service-nologin.php and find the request for "message_area_contacts" template - see following request pay load. [{"index":0,"methodname":"core_output_load_template","args":{"component":"core_message","template":"message_area_contacts","themename":"boost"}}] Observe the response for this request no longer contains comments: [{"error":false,"data":"\n{{#contacts}}\n {{> core_message\/message_area_contact }}\n{{\/contacts}}\n{{^contacts}}\n <div class=\"nocontacts\" data-region=\"no-contacts\">\n {{#isconversation}}\n {{#str}}nomessages, message{{\/str}}\n {{\/isconversation}}\n {{^isconversation}}\n {{#str}}nocontacts, message{{\/str}}\n {{\/isconversation}}\n <\/div>\n{{\/contacts}}\n"}] Regression test template library 1) Open the template library tool /admin/tool/templatelibrary/index.php 2) Set component to 'forum' 3) Click on link "mod_forum/forum_post_email_htmlemail" Expected outcome: You can see "Lorem ipsum dolor" text in Example area Documentation area is populated (text starting "Template which defines a forum post for sending in a single-post HTML email.")
    • Affected Branches:
      MOODLE_32_STABLE, MOODLE_33_STABLE
    • Fixed Branches:
      MOODLE_34_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-57304_template_comments_fix

      Description

      I was looking at some of the mustache templates returned via ajax and was surprised to see the copyright preamble and documentation comments in each of them. For small templates this is many times the size of the actual code:

      "{{!    This file is part of Moodle - http://moodle.org/    Moodle is free software: you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    Moodle is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.}}{{!    @template core/hover_tooltip    Displays a tooltip on hover.    Classes required for JS:    * none    Data attributes required for JS:    * none    Context variables required for this template:    * none}}<div class="hover-tooltip-container">    {{$anchor}}{{/anchor}}    <div class="hover-tooltip">        {{$tooltip}}{{/tooltip}}    </div></div>"
      

        Attachments

          Activity

            People

            • Votes:
              6 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/Nov/17