Skip to content

Commit 92fe62c

Browse files
committed
fix(template) Allow format attribute for {{this}} variable
Signed-off-by: jeromesimeon <[email protected]>
1 parent 22d2fe8 commit 92fe62c

File tree

9 files changed

+53
-1
lines changed

9 files changed

+53
-1
lines changed

packages/markdown-it-template/lib/template_inline.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ function template_inline(state, silent) {
119119
token = state.push('this', 'this', 0);
120120
token.content = content;
121121
token.attrs = [ ];
122+
if (format) {
123+
token.attrs.push([ 'format', format ]);
124+
}
122125
} else {
123126
token = state.push('variable', 'variable', 0);
124127
token.content = content;

packages/markdown-template/lib/templaterules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const thisRule = { // 'this' is a special variable for the current data in scope
4343
enter: (node,token,callback) => {
4444
const format = getAttr(token.attrs,'format',null);
4545
if (format) {
46-
node.$class = NS_PREFIX_TemplateMarkModel + 'VariableDefinition';
46+
node.$class = NS_PREFIX_TemplateMarkModel + 'FormattedVariableDefinition';
4747
node.format = format;
4848
}
4949
node.name = 'this';

packages/markdown-template/test/TemplateMarkTransformer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const successes = [
9797
{name:'testOptionalElse',kind:'clause'},
9898
{name:'testOptionalThisSome',kind:'clause'},
9999
{name:'testOptionalThisNone',kind:'clause'},
100+
{name:'testOptionalThisFormat',kind:'contract'},
100101
{name:'testUnderscore',kind:'clause'},
101102
{name:'testIfEnd',kind:'clause'},
102103
{name:'alltypes',kind:'clause'},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
concerto version ">= 1.0.0"
16+
17+
namespace org.accordproject.contract
18+
19+
/**
20+
* Contract Data
21+
* -- Describes the structure of contracts and clauses
22+
*/
23+
24+
/* A contract is a asset -- This contains the contract data */
25+
abstract asset Contract identified by contractId {
26+
o String contractId
27+
}
28+
29+
/* A clause is an asset -- This contains the clause data */
30+
abstract asset Clause identified by clauseId {
31+
o String clauseId
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$class":"org.test.EmptyContract","name":"Fred","dueDate":"2020-12-17T00:00:00.000Z","contractId":"fc0d87a2-33f7-4858-9d4a-941b89c7aed0","$identifier":"fc0d87a2-33f7-4858-9d4a-941b89c7aed0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$class":"org.accordproject.commonmark.Document","xmlns":"http://commonmark.org/xml/1.0","nodes":[{"$class":"org.accordproject.templatemark.ContractDefinition","name":"top","elementType":"org.test.EmptyContract","nodes":[{"$class":"org.accordproject.commonmark.Paragraph","nodes":[{"$class":"org.accordproject.commonmark.Text","text":"Name: "},{"$class":"org.accordproject.templatemark.VariableDefinition","name":"name","elementType":"String"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"Payment due by "},{"$class":"org.accordproject.templatemark.FormattedVariableDefinition","format":"DD MMMM YYYY","name":"dueDate","elementType":"DateTime"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.templatemark.OptionalDefinition","whenSome":[{"$class":"org.accordproject.commonmark.Text","text":"Payment due by "},{"$class":"org.accordproject.templatemark.FormattedVariableDefinition","format":"DD MMMM YYYY","name":"this","elementType":"DateTime"}],"whenNone":[],"name":"dueDate","elementType":"DateTime"}]}]}]}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name: {{name}}
2+
Payment due by {{dueDate as "DD MMMM YYYY"}}
3+
{{#optional dueDate}}Payment due by {{this as "DD MMMM YYYY"}}{{/optional}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace org.test
2+
3+
import org.accordproject.contract.* from https://models.accordproject.org/accordproject/contract.cto
4+
5+
asset EmptyContract extends Contract {
6+
o String name
7+
o DateTime dueDate optional
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name: "Fred"
2+
Payment due by 17 December 2020
3+
Payment due by 17 December 2020

0 commit comments

Comments
 (0)