[ADD] qweb: call directive's body
* __content__ can't be used in Python implementation because safe_eval, so use ``0`` from Python implementation instead * remove postfix from t-call tests because due to implementation details all whitespace crap following a t-name is added to rendered template in Python impl, and don't want to normalize whitespace.
This commit is contained in:
parent
2ffcff8fa9
commit
d5e3d121e3
|
@ -1,6 +1,6 @@
|
||||||
<templates>
|
<templates>
|
||||||
<t t-name="_basic-callee">ok</t>
|
<t t-name="_basic-callee">ok</t>
|
||||||
<t t-name="_callee-printsbody"><t t-esc="__content__"/></t>
|
<t t-name="_callee-printsbody"><t t-esc="0"/></t>
|
||||||
<t t-name="_callee-uses-foo"><t t-esc="foo"/></t>
|
<t t-name="_callee-uses-foo"><t t-esc="foo"/></t>
|
||||||
|
|
||||||
<t t-name="basic-caller">
|
<t t-name="basic-caller">
|
||||||
|
@ -32,11 +32,18 @@
|
||||||
</t>
|
</t>
|
||||||
<result id="with-used-setbody">ok</result>
|
<result id="with-used-setbody">ok</result>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
postfix to call removed because Python impl appends all whitespace
|
||||||
|
following called template's root to template result (+= element.tail)
|
||||||
|
-> ends up with bunch of extra whitespace in the middle of the
|
||||||
|
generated content. Could normalize, not sure current impl can be
|
||||||
|
fixed as-is
|
||||||
|
-->
|
||||||
<t t-name="inherit-context">
|
<t t-name="inherit-context">
|
||||||
<t t-set="foo" t-value="1"/>
|
<t t-set="foo" t-value="1"/>
|
||||||
<t t-call="_callee-uses-foo"/> - <t t-esc="foo"/>
|
<t t-call="_callee-uses-foo"/><!-- - <t t-esc="foo"/> -->
|
||||||
</t>
|
</t>
|
||||||
<result id="inherit-context">1 - 1</result>
|
<result id="inherit-context">1<!-- - 1 --></result>
|
||||||
|
|
||||||
<t t-name="scoped-parameter">
|
<t t-name="scoped-parameter">
|
||||||
<t t-call="_basic-callee">
|
<t t-call="_basic-callee">
|
||||||
|
|
|
@ -26,7 +26,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// TODO: templates orverwritten could be called by t-call="__super__" ?
|
// TODO: templates orverwritten could be called by t-call="__super__" ?
|
||||||
// TODO: t-set + t-value + children node == scoped variable ?
|
// TODO: t-set + t-value + children node == scoped variable ?
|
||||||
var QWeb2 = {
|
var QWeb2 = {
|
||||||
expressions_cache: {},
|
expressions_cache: {
|
||||||
|
// special case for template bodies, __content__ doesn't work in
|
||||||
|
// Python impl because safe_eval -> assert_no_dunder_name so use
|
||||||
|
// Python impl's magical 0 variable instead
|
||||||
|
'0': 'dict[0]',
|
||||||
|
},
|
||||||
RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','),
|
RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','),
|
||||||
ACTIONS_PRECEDENCE: 'foreach,if,call,set,esc,raw,js,debug,log'.split(','),
|
ACTIONS_PRECEDENCE: 'foreach,if,call,set,esc,raw,js,debug,log'.split(','),
|
||||||
WORD_REPLACEMENT: {
|
WORD_REPLACEMENT: {
|
||||||
|
@ -137,7 +142,7 @@ var QWeb2 = {
|
||||||
var new_dict = this.extend({}, old_dict);
|
var new_dict = this.extend({}, old_dict);
|
||||||
new_dict['__caller__'] = old_dict['__template__'];
|
new_dict['__caller__'] = old_dict['__template__'];
|
||||||
if (callback) {
|
if (callback) {
|
||||||
new_dict['__content__'] = callback(context, new_dict);
|
new_dict[0] = callback(context, new_dict);
|
||||||
}
|
}
|
||||||
return context.engine._render(template, new_dict);
|
return context.engine._render(template, new_dict);
|
||||||
},
|
},
|
||||||
|
@ -551,7 +556,7 @@ QWeb2.Element = (function() {
|
||||||
format_expression : function(e) {
|
format_expression : function(e) {
|
||||||
/* Naive format expression builder. Replace reserved words and variables to dict[variable]
|
/* Naive format expression builder. Replace reserved words and variables to dict[variable]
|
||||||
* Does not handle spaces before dot yet, and causes problems for anonymous functions. Use t-js="" for that */
|
* Does not handle spaces before dot yet, and causes problems for anonymous functions. Use t-js="" for that */
|
||||||
if (QWeb2.expressions_cache[e]) {
|
if (QWeb2.expressions_cache[e]) {
|
||||||
return QWeb2.expressions_cache[e];
|
return QWeb2.expressions_cache[e];
|
||||||
}
|
}
|
||||||
var chars = e.split(''),
|
var chars = e.split(''),
|
||||||
|
|
|
@ -577,7 +577,7 @@
|
||||||
</t>
|
</t>
|
||||||
<t t-name="ViewPager">
|
<t t-name="ViewPager">
|
||||||
<div class="oe_pager_value">
|
<div class="oe_pager_value">
|
||||||
<t t-raw="__content__"/>
|
<t t-raw="0"/>
|
||||||
</div>
|
</div>
|
||||||
<ul class="oe_pager_group">
|
<ul class="oe_pager_group">
|
||||||
<!--
|
<!--
|
||||||
|
@ -1373,7 +1373,7 @@
|
||||||
method="post" enctype="multipart/form-data" t-att-action="fileupload_action || '/web/binary/upload'">
|
method="post" enctype="multipart/form-data" t-att-action="fileupload_action || '/web/binary/upload'">
|
||||||
<input type="hidden" name="session_id" value="" t-if="widget.session.override_session"/>
|
<input type="hidden" name="session_id" value="" t-if="widget.session.override_session"/>
|
||||||
<input type="hidden" name="callback" t-att-value="fileupload_id"/>
|
<input type="hidden" name="callback" t-att-value="fileupload_id"/>
|
||||||
<t t-raw="__content__"/>
|
<t t-raw="0"/>
|
||||||
<input type="file" class="oe_form_binary_file" name="ufile" t-if="widget.widget!='image'"/>
|
<input type="file" class="oe_form_binary_file" name="ufile" t-if="widget.widget!='image'"/>
|
||||||
<input type="file" class="oe_form_binary_file" name="ufile" accept="image/*" t-if="widget.widget=='image'"/>
|
<input type="file" class="oe_form_binary_file" name="ufile" accept="image/*" t-if="widget.widget=='image'"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
<h3 class="modal-title"><t t-esc="title"/></h3>
|
<h3 class="modal-title"><t t-esc="title"/></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body"><t t-raw="__content__"/></div>
|
<div class="modal-body"><t t-raw="0"/></div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-primary save">Save</button>
|
<button type="button" class="btn btn-primary save">Save</button>
|
||||||
<button type="button" class="btn hidden wait" disabled="disabled"/>
|
<button type="button" class="btn hidden wait" disabled="disabled"/>
|
||||||
|
|
|
@ -269,6 +269,28 @@ evaluated *before* calling the sub-template, and can alter a local context::
|
||||||
</t>
|
</t>
|
||||||
<!-- "var" does not exist here -->
|
<!-- "var" does not exist here -->
|
||||||
|
|
||||||
|
The body of the ``call`` directive can be arbitrarily complex (not just
|
||||||
|
``set`` directives), and its rendered form will be available within the called
|
||||||
|
template as a magical ``0`` variable::
|
||||||
|
|
||||||
|
<div>
|
||||||
|
This template was called with content:
|
||||||
|
<t t-raw="0"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
being called thus::
|
||||||
|
|
||||||
|
<t t-call="other-template">
|
||||||
|
<em>content</em>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
will result in::
|
||||||
|
|
||||||
|
<div>
|
||||||
|
This template was called with content:
|
||||||
|
<em>content</em>
|
||||||
|
</div>
|
||||||
|
|
||||||
Python
|
Python
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue