From notifications-return-5792-archive-asf-public=cust-asf.ponee.io@freemarker.apache.org Wed Nov 21 23:40:04 2018 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 [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9EFAB180668 for ; Wed, 21 Nov 2018 23:40:03 +0100 (CET) Received: (qmail 32652 invoked by uid 500); 21 Nov 2018 22:40: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 32643 invoked by uid 99); 21 Nov 2018 22:40:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Nov 2018 22:40:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5778118C47C for ; Wed, 21 Nov 2018 22:40:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id cXBer6G6wMbZ for ; Wed, 21 Nov 2018 22:40:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id DEE4E5F4E6 for ; Wed, 21 Nov 2018 22:40:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 5A050E092E for ; Wed, 21 Nov 2018 22:40:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 2408D21E7B for ; Wed, 21 Nov 2018 22:40:00 +0000 (UTC) Date: Wed, 21 Nov 2018 22:40:00 +0000 (UTC) From: "Pascal Proulx (JIRA)" To: notifications@freemarker.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (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= 16695322#comment-16695322 ]=20 Pascal Proulx edited comment on FREEMARKER-107 at 11/21/18 10:39 PM: --------------------------------------------------------------------- For inline args, that's what we did in our (much heavier) workaround: inlin= es like p=3D'direct' get priority over the hash. I think it's the natural e= xpectation and it's worked out in our code (in fact, it relies on it, shoul= d point that out). When I briefly thought about patching Freemarker, was going to use a reserv= ed keyword like _kwargs=3DmyHash, because it's easy, but it's ugly and comp= atibility breaking. So using the equals seems fine to me, with anything: **= =3DmyHash*,* -=3DmyList (maybe *=3D works if it can be given priority and p= rocessed as one token? Only you know)- (sorry it's getting late, mixed up t= he macro and function syntax) Wouldn't have a problem with "...=3D" or any other short special char eithe= r. Thanks =C2=A0 was (Author: pplx): For inline args, that's what we did in our (much heavier) workaround: inlin= es like p=3D'direct' get priority over the hash. I think it's the natural e= xpectation and it's worked out in our code (in fact, it relies on it, shoul= d point that out). When I briefly thought about patching Freemarker, was going to use a reserv= ed keyword like _kwargs=3DmyHash, because it's easy, but it's ugly and comp= atibility breaking. So using the equals seems fine to me, with anything: **= =3DmyHash, -*=3DmyList (maybe *=3D works if it can be given priority and pr= ocessed as one token? Only you know)- (sorry it's getting late, mixed up th= e macro and function syntax) Wouldn't have a problem with "...=3D" or any other short special char eithe= r.=20 Thanks =C2=A0 > 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 (v7.6.3#76005)