Skip to content

Commit dda3f9d

Browse files
authored
[soy mode] Natively support Soy Element Composition
* Add support for Soy Element Composition. Add support for Soy Element Composition. It has the syntax in the form of <{foo()}></> This adds support to pass through allowEmptyTag and to support this mode in closetag. * Disable allowMissingTagName and handle Soy Element Composition directly. Disable allowMissingTagName and handle Soy Element Composition directly. This also adds a case in closetag.js to handle autocompletes for soy element composition. Right now, if you were to do something like <{foo()}> it would autocomplet with </undefined>. This change makes it autocomplete with </>
1 parent eb345ef commit dda3f9d

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

addon/edit/closetag.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@
128128
replacement = head + "style";
129129
} else {
130130
var context = inner.mode.xmlCurrentContext && inner.mode.xmlCurrentContext(state)
131-
if (!context || (context.length && closingTagExists(cm, context, context[context.length - 1], pos)))
131+
var top = context.length ? context[context.length - 1] : ""
132+
if (!context || (context.length && closingTagExists(cm, context, top, pos)))
132133
return CodeMirror.Pass;
133-
replacement = head + context[context.length - 1]
134+
replacement = head + top
134135
}
135136
if (cm.getLine(pos.line).charAt(tok.end) != ">") replacement += ">";
136137
replacements[i] = replacement;

mode/soy/soy.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,17 @@
498498
}
499499
return expression(stream, state);
500500

501+
case "template-call-expression":
502+
if (stream.match(/^([\w-?]+)(?==)/)) {
503+
return "attribute";
504+
} else if (stream.eat('>')) {
505+
state.soyState.pop();
506+
return "keyword";
507+
} else if (stream.eat('/>')) {
508+
state.soyState.pop();
509+
return "keyword";
510+
}
511+
return expression(stream, state);
501512
case "literal":
502513
if (stream.match(/^(?=\{\/literal})/)) {
503514
state.soyState.pop();
@@ -563,6 +574,15 @@
563574
state.soyState.push("import");
564575
state.indent += 2 * config.indentUnit;
565576
return "keyword";
577+
} else if (match = stream.match(/^<\{/)) {
578+
state.soyState.push("template-call-expression");
579+
state.tag = "print";
580+
state.indent += 2 * config.indentUnit;
581+
state.soyState.push("tag");
582+
return "keyword";
583+
} else if (match = stream.match(/^<\/>/)) {
584+
state.indent -= 2 * config.indentUnit;
585+
return "keyword";
566586
}
567587

568588
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);

mode/soy/test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@
2727
'[string "][tag&bracket />]');
2828

2929
MT('soy-element-composition-test',
30-
'[tag&bracket <][keyword {][callee&variable foo]()[keyword }]',
31-
'[tag&bracket ></>]');
30+
'[keyword <{][callee&variable foo]()[keyword }]',
31+
'[keyword ></>]');
32+
33+
MT('soy-element-composition-attribute-test',
34+
'[keyword <{][callee&variable foo]()[keyword }]',
35+
'[attribute class]=[string "Foo"]',
36+
'[keyword ></>]');
3237

3338
MT('namespace-test',
3439
'[keyword {namespace] [variable namespace][keyword }]')

0 commit comments

Comments
 (0)