mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-49650 tool_templatelibrary: Change the format for template comments
The documentation comment for a template must now be marked with: @template component/templatename For it to be read by the template library. Previously it was looking for the first "non gpl license" comment which was a bit random.
This commit is contained in:
parent
9ee83b0d30
commit
1fcad8433c
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/log","core/notification","core/templates","core/config","core/str"],function(a,b,c,d,e,f,g){var h=function(b,f){g.get_string("templateselected","tool_templatelibrary",b).done(function(b){a('[data-region="displaytemplateheader"]').text(b)}).fail(d.exception);var h=f.match(/{{!([\s\S]*?)}}/g),i=0;if(null!==h)for(i=0;i<h.length;i++){var j=h[i];if(""!==j.trim()&&-1===j.indexOf("GNU General Public License")){j=j.substr(3,j.length-5),f=j;break}}a('[data-region="displaytemplatesource"]').text(f);var k=f.match(/Example context \(json\):([\s\S]*)/),l=!1;if(k){var m=k[1].trim();try{l=a.parseJSON(m)}catch(n){c.debug("Could not parse json example context for template."),c.debug(n)}}l?e.render(b,l).done(function(b,c){a('[data-region="displaytemplateexample"]').empty(),a('[data-region="displaytemplateexample"]').append(b),e.runTemplateJS(c)}).fail(d.exception):g.get_string("templatehasnoexample","tool_templatelibrary").done(function(b){a('[data-region="displaytemplateexample"]').text(b)}).fail(d.exception)},i=function(a){var c=a.split("/"),e=c.shift(),g=c.shift();b.call([{methodname:"core_output_load_template",args:{component:e,template:g,themename:f.theme},done:function(b){h(a,b)},fail:d.exception}])};return a('[data-region="list-templates"]').on("click","[data-templatename]",function(){var b=a(this).data("templatename");i(b)}),{}});
|
||||
define(["jquery","core/ajax","core/log","core/notification","core/templates","core/config","core/str"],function(a,b,c,d,e,f,g){var h=function(b,f){g.get_string("templateselected","tool_templatelibrary",b).done(function(b){a('[data-region="displaytemplateheader"]').text(b)}).fail(d.exception);var h="@template "+b,i=f.match(/{{!([\s\S]*?)}}/g),j=0;if(null!==i)for(j=0;j<i.length;j++){var k=i[j],l=k.indexOf(h);if(-1!==l){var m=l+h.length+1;k=k.substr(m,k.length-2-m),f=k;break}}a('[data-region="displaytemplatesource"]').text(f);var n=f.match(/Example context \(json\):([\s\S]*)/),o=!1;if(n){var p=n[1].trim();try{o=a.parseJSON(p)}catch(q){c.debug("Could not parse json example context for template."),c.debug(q)}}o?e.render(b,o).done(function(b,c){a('[data-region="displaytemplateexample"]').empty(),a('[data-region="displaytemplateexample"]').append(b),e.runTemplateJS(c)}).fail(d.exception):g.get_string("templatehasnoexample","tool_templatelibrary").done(function(b){a('[data-region="displaytemplateexample"]').text(b)}).fail(d.exception)},i=function(a){var c=a.split("/"),e=c.shift(),g=c.shift();b.call([{methodname:"core_output_load_template",args:{component:e,template:g,themename:f.theme},done:function(b){h(a,b)},fail:d.exception}])};return a('[data-region="list-templates"]').on("click","[data-templatename]",function(){var b=a(this).data("templatename");i(b)}),{}});
|
@ -35,19 +35,21 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
|
||||
$('[data-region="displaytemplateheader"]').text(s);
|
||||
}).fail(notification.exception);
|
||||
|
||||
// Remove the GPL from the start of the template.
|
||||
// Find the comment section marked with @template component/template.
|
||||
var marker = "@template " + templateName;
|
||||
|
||||
var sections = source.match(/{{!([\s\S]*?)}}/g);
|
||||
var i = 0;
|
||||
|
||||
// Find the first non-empty comment that is not the GPL.
|
||||
// If no sections match - show the entire file.
|
||||
if (sections !== null) {
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var section = sections[i];
|
||||
if ((section.trim() !== '') && (section.indexOf('GNU General Public License') === -1)) {
|
||||
var start = section.indexOf(marker);
|
||||
if (start !== -1) {
|
||||
// Remove {{! and }} from start and end.
|
||||
section = section.substr(3, section.length - 5);
|
||||
var offset = start + marker.length + 1;
|
||||
section = section.substr(offset, section.length - 2 - offset);
|
||||
source = section;
|
||||
break;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
// Manage competency frameworks page.
|
||||
// Template library page.
|
||||
$temp = new admin_externalpage(
|
||||
'tooltemplatelibrary',
|
||||
get_string('pluginname', 'tool_templatelibrary'),
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_templatelibrary/display_template
|
||||
|
||||
Moodle template to display another template.
|
||||
|
||||
The purpose of this template is to put scafolding in the page, so the javascript can fetch templates and
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_templatelibrary/list_templates_page
|
||||
|
||||
Moodle template to the template library
|
||||
|
||||
The purpose of this template is build the entire page for the template library (by including smaller templates).
|
||||
@ -30,7 +32,7 @@
|
||||
|
||||
}}
|
||||
<div data-region="list-templates">
|
||||
<form class="form-horizontal form-search">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label for="selectcomponent" class="control-label">{{#str}}component, tool_templatelibrary{{/str}}</label>
|
||||
<div class="controls">
|
||||
@ -45,7 +47,7 @@
|
||||
<div class="control-group">
|
||||
<label for="search" class="control-label">{{#str}}search, tool_templatelibrary{{/str}}</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="search" class="search-query" data-field="search"/>
|
||||
<input type="text" id="search" data-field="search"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_templatelibrary/search_results
|
||||
|
||||
Moodle template to display results of template search.
|
||||
|
||||
This template gets rendered by javascript when it has searched for templates.
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/notification_message
|
||||
|
||||
Moodle notification template.
|
||||
|
||||
The purpose of this template is to render a message notification.
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/notification_problem
|
||||
|
||||
Moodle notification template.
|
||||
|
||||
The purpose of this template is to render a problem notification.
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/notification_redirect
|
||||
|
||||
Moodle notification template.
|
||||
|
||||
The purpose of this template is to render a message notification.
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/notification_success
|
||||
|
||||
Moodle notification template.
|
||||
|
||||
The purpose of this template is to render a success notification.
|
||||
|
@ -15,6 +15,8 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core/pix_icon
|
||||
|
||||
Moodle pix_icon template.
|
||||
|
||||
The purpose of this template is to render a pix_icon.
|
||||
|
Loading…
x
Reference in New Issue
Block a user