From notifications-return-6093-archive-asf-public=cust-asf.ponee.io@freemarker.apache.org Tue Oct 8 18:12:03 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C5C2E180654 for ; Tue, 8 Oct 2019 20:12:02 +0200 (CEST) Received: (qmail 90816 invoked by uid 500); 8 Oct 2019 18:12:02 -0000 Mailing-List: contact notifications-help@freemarker.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.apache.org Delivered-To: mailing list notifications@freemarker.apache.org Received: (qmail 90806 invoked by uid 99); 8 Oct 2019 18:12:02 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Oct 2019 18:12:02 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 1CE79E30F5 for ; Tue, 8 Oct 2019 18:12:01 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 4C2CF780749 for ; Tue, 8 Oct 2019 18:12:00 +0000 (UTC) Date: Tue, 8 Oct 2019 18:12:00 +0000 (UTC) From: =?utf-8?Q?D=C3=A1niel_D=C3=A9k=C3=A1ny_=28Jira=29?= To: notifications@freemarker.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FREEMARKER-107) Hash expansion to macro arguments (Python **kwargs style) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FREEMARKER-107?page=3Dcom.atlas= sian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D= 16947096#comment-16947096 ]=20 D=C3=A1niel D=C3=A9k=C3=A1ny commented on FREEMARKER-107: ------------------------------------------ You don't extend the macro _name_ with {{?}}, you transform the macro _valu= e_ to another macro _value_. Macros are just values, like strings, numbers,= etc. That's why you can do things like {{<#assign myAlias =3D myMacro>}} a= nd then {{<@myAlias />, or pass a macro to another macro as a parameter}}. = Or, in this case, that's why you can do this:=C2=A0{{<#assign myMacro2 =3D = myMacro?spreadArgs(myDefaults)>}} > Hash expansion to macro arguments (Python **kwargs style) > --------------------------------------------------------- > > Key: FREEMARKER-107 > URL: https://issues.apache.org/jira/browse/FREEMARKER-107 > Project: Apache Freemarker > Issue Type: New Feature > Components: engine > Affects Versions: 2.3.28 > Reporter: Pascal Proulx > Priority: Major > > Hello, > We heavily rely on Freemarker macros to build a helper template API, but = have had to make large workarounds for passing contents of hashes as macro = arguments, for several years. (In truth I should have made this ticket much= sooner!) > It would help greatly simplify our work to have hash expansion to macro a= rguments, like this: > {code:java} > <#macro myMacro arg1 arg2 arg3=3D"value3">... > <#assign myHash =3D {"arg1":"value1", "arg2":"value2"}> > <@myMacro **myHash/><#-- the hash contents are passed as parameters, inst= ead of the hash itself --> > {code} > This exists in Python: > {code:java} > def test_var_args_call(arg1, arg2, arg3): > pass > kwargs =3D {"arg3": 3, "arg2": "two"} > test_var_args_call(1, **kwargs) > {code} > Essentially the hash contents fill in any arguments not explicitly specif= ied. > For the case where arguments are specified in addition to the hash, you m= ay need to decide on a good syntax, e.g.: > {code:java} > <@myMacro arg1=3D"value1" **myHash/>{code} > This example doesn't have much precedent in freemarker syntax but is fair= ly understandable. > Although we don't need it nearly as much, the same could be done with lis= ts and function arguments: > {code:java} > <#function myFunc arg1 arg2>... > <#assign myList =3D ["val1", "val2"]> > ${myFunc(*myList)} > <#assign myList =3D ["val2"]> > ${myFunc("val1", *myList)} > {code} > Again similar to Python: > {code:java} > def test_var_args_call(arg1, arg2, arg3): > pass > args =3D ("two", 3) > test_var_args_call(1, *args) > {code} > You might want this for consistency, although in practice the hash expans= ion will be many times more useful to us. > If there's a lack a manpower I could try to see what I can do digging int= o the source, but wanted to bring this up for discussion first. It doesn't = appear hard to implement to dump a hash into the macro args map, but there = is defining the syntax. > We use Freemarker 2.3.28 at the moment. > Thank you -- This message was sent by Atlassian Jira (v8.3.4#803005)