From notifications-return-5797-archive-asf-public=cust-asf.ponee.io@freemarker.apache.org Mon Nov 26 17:02: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 DCBAC180647 for ; Mon, 26 Nov 2018 17:02:03 +0100 (CET) Received: (qmail 85547 invoked by uid 500); 26 Nov 2018 16:02:03 -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 85535 invoked by uid 99); 26 Nov 2018 16:02:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Nov 2018 16:02:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 8E770CB89A for ; Mon, 26 Nov 2018 16:02:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-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 (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id FS3LlvVsByx5 for ; Mon, 26 Nov 2018 16:02: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 DAF2A6103E for ; Mon, 26 Nov 2018 16:02: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 74DB6E0C57 for ; Mon, 26 Nov 2018 16:02: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 303B827761 for ; Mon, 26 Nov 2018 16:02:00 +0000 (UTC) Date: Mon, 26 Nov 2018 16:02:00 +0000 (UTC) From: "Pascal Proulx (JIRA)" 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: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FREEMARKER-107?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16699187#comment-16699187 ] Pascal Proulx commented on FREEMARKER-107: ------------------------------------------ I suppose I have no issues with that, as long as it doesn't add any much overhead. (the other was likely just a Map.putAll call or close) > 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 arguments, like this: > {code:java} > <#macro myMacro arg1 arg2 arg3="value3">... > <#assign myHash = {"arg1":"value1", "arg2":"value2"}> > <@myMacro **myHash/><#-- the hash contents are passed as parameters, instead of the hash itself --> > {code} > This exists in Python: > {code:java} > def test_var_args_call(arg1, arg2, arg3): > pass > kwargs = {"arg3": 3, "arg2": "two"} > test_var_args_call(1, **kwargs) > {code} > Essentially the hash contents fill in any arguments not explicitly specified. > For the case where arguments are specified in addition to the hash, you may need to decide on a good syntax, e.g.: > {code:java} > <@myMacro arg1="value1" **myHash/>{code} > This example doesn't have much precedent in freemarker syntax but is fairly understandable. > Although we don't need it nearly as much, the same could be done with lists and function arguments: > {code:java} > <#function myFunc arg1 arg2>... > <#assign myList = ["val1", "val2"]> > ${myFunc(*myList)} > <#assign myList = ["val2"]> > ${myFunc("val1", *myList)} > {code} > Again similar to Python: > {code:java} > def test_var_args_call(arg1, arg2, arg3): > pass > args = ("two", 3) > test_var_args_call(1, *args) > {code} > You might want this for consistency, although in practice the hash expansion 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 into 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)