Skip to content

Commit b1609de

Browse files
committed
detect markup controls based on presence in config.Markup.Controls
1 parent 8dfbe39 commit b1609de

4 files changed

Lines changed: 26 additions & 40 deletions

File tree

src/Framework/Framework/Compilation/Directives/MarkupDirectiveCompilerPipeline.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
using DotVVM.Framework.ResourceManagement;
55
using System.Collections.Immutable;
66
using DotVVM.Framework.Compilation.Parser.Dothtml.Parser;
7+
using DotVVM.Framework.Configuration;
78
using System;
9+
using System.Linq;
810

911
namespace DotVVM.Framework.Compilation.Directives
1012
{
@@ -14,18 +16,21 @@ public class MarkupDirectiveCompilerPipeline : MarkupDirectiveCompilerPipelineBa
1416
{
1517
private readonly IAbstractTreeBuilder treeBuilder;
1618
private readonly DotvvmResourceRepository resourceRepository;
19+
private readonly DotvvmConfiguration configuration;
1720

18-
public MarkupDirectiveCompilerPipeline(IAbstractTreeBuilder treeBuilder, DotvvmResourceRepository resourceRepository) : base()
21+
public MarkupDirectiveCompilerPipeline(IAbstractTreeBuilder treeBuilder, DotvvmConfiguration configuration) : base()
1922
{
2023
this.treeBuilder = treeBuilder;
21-
this.resourceRepository = resourceRepository;
24+
this.resourceRepository = configuration.Resources;
25+
this.configuration = configuration;
2226
}
2327

2428
protected override bool IsMarkupControl(string fileName)
2529
{
2630
if (fileName.EndsWith(".dotcontrol", StringComparison.OrdinalIgnoreCase))
2731
return true;
2832
return false;
33+
return configuration.Markup.Controls.Any(c => c.Src == fileName);
2934
}
3035

3136
protected override DefaultDirectiveResolver CreateDefaultResolver(DirectiveDictionary directivesByName)

src/Tests/Runtime/ControlTree/DefaultControlTreeResolver/CompilationWarningsTests.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,30 +188,6 @@ @viewModel System.DateTime
188188
Assert.AreEqual(1, literal.DothtmlNode.NodeWarnings.Count());
189189
Assert.AreEqual("Evaluation of method \"ToBrowserLocalTime\" on server-side may yield unexpected results.", literal.DothtmlNode.NodeWarnings.First());
190190
}
191-
192-
[TestMethod]
193-
public void DefaultViewCompiler_DotvvmView_Used_As_Control_Warning()
194-
{
195-
var files = new FakeMarkupFileLoader();
196-
files.MarkupFiles["TestControl.dothtml"] = """
197-
@viewModel object
198-
test
199-
""";
200-
var config = DotvvmTestHelper.CreateConfiguration(s => {
201-
s.AddSingleton<IMarkupFileLoader>(files);
202-
});
203-
config.Markup.AddMarkupControl("cc", "TestControl", "TestControl.dothtml");
204-
205-
var markup = DotvvmTestHelper.ParseResolvedTree("""
206-
@viewModel object
207-
<cc:TestControl Styles.Tag=this />
208-
""", configuration: config);
209-
var control = markup.Content.SelectRecursively(c => c.Content).Single(c => c.Properties.ContainsKey(Styles.TagProperty));
210-
Assert.AreEqual(typeof(DotvvmView), control.Metadata.Type);
211-
var element = (DothtmlElementNode)control.DothtmlNode;
212-
XAssert.Contains("The markup control <cc:TestControl> has a baseType DotvvmView", element.TagNameNode.NodeWarnings.First());
213-
Assert.AreEqual(1, element.TagNameNode.NodeWarnings.Count());
214-
}
215191
}
216192

217193
}

src/Tests/Runtime/ControlTree/DefaultControlTreeResolver/PropertyDirectiveTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public void ResolvedTree_PropertyDirectiveHalfWritten_AttributeResolved()
1212
{
1313
var root = ParseSource(@$"
1414
@viewModel object
15-
@property string MyProperty, , DotVVM., DotVVM.Fra = , DotVVM.Framework.Controls.MarkupOptionsAttribute.Required = t");
15+
@property string MyProperty, , DotVVM., DotVVM.Fra = , DotVVM.Framework.Controls.MarkupOptionsAttribute.Required = t",
16+
fileName: "x.dotcontrol");
1617

1718
var property = root.Directives["property"].SingleOrDefault() as IAbstractPropertyDeclarationDirective;
1819

@@ -32,7 +33,8 @@ public void ResolvedTree_PropertyDirectiveIncompatibleType_ErrorReported()
3233
{
3334
var root = ParseSource(@$"
3435
@viewModel object
35-
@property string MyProperty, DotVVM.Framework.Controls.MarkupOptionsAttribute.Required = 1");
36+
@property string MyProperty, DotVVM.Framework.Controls.MarkupOptionsAttribute.Required = 1",
37+
fileName: "x.dotcontrol");
3638

3739
var property = root.Directives["property"].SingleOrDefault() as IAbstractPropertyDeclarationDirective;
3840

@@ -52,7 +54,8 @@ public void ResolvedTree_PropertyDirectiveInvalidArrayInicializer_ResolvedCorrec
5254
{
5355
var root = ParseSource(@$"
5456
@viewModel object
55-
@property string a=[, MarkupOptionsAttribute.Required = true");
57+
@property string a=[, MarkupOptionsAttribute.Required = true",
58+
fileName: "x.dotcontrol");
5659

5760
var property = root.Directives["property"].SingleOrDefault() as IAbstractPropertyDeclarationDirective;
5861

@@ -69,7 +72,7 @@ public void ResolvedTree_PropertyDirectiveArrayInicializerAndAttributes_Resolved
6972
var root = ParseSource("""
7073
@viewModel object
7174
@property string[] MyProperty=["",""], MarkupOptionsAttribute.Required = true, MarkupOptionsAttribute.AllowBinding = false
72-
""");
75+
""", fileName: "x.dotcontrol");
7376

7477
var property = root.Directives["property"].SingleOrDefault() as IAbstractPropertyDeclarationDirective;
7578

@@ -114,7 +117,7 @@ public void ResolvedTree_PropertyDirective_InvalidType_DoesNotDuplicateError()
114117
{
115118
var root = ParseSource(@"@viewModel object
116119
@property invalidType MyProperty
117-
");
120+
", fileName: "x.dotcontrol");
118121

119122
var property = root.Directives["property"].Single() as IAbstractPropertyDeclarationDirective;
120123

@@ -127,7 +130,7 @@ public void ResolvedTree_PropertyDirective_InvalidAttributeType_ErrorReported()
127130
{
128131
var root = ParseSource(@"@viewModel object
129132
@property string MyProperty, DotVVM.Framework.Controls.NonExistingAttribute.Required = true
130-
");
133+
", fileName: "x.dotcontrol");
131134

132135
var property = root.Directives["property"].Single() as IAbstractPropertyDeclarationDirective;
133136

src/Tests/Runtime/DefaultViewCompilerTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ public void DefaultViewCompiler_CodeGeneration_MarkupControl()
196196
});
197197

198198
Assert.IsInstanceOfType(page, typeof(DotvvmView));
199-
Assert.IsInstanceOfType(page.Children[0], typeof(DotvvmView));
199+
Assert.IsInstanceOfType(page.Children[0], typeof(DotvvmMarkupControl));
200200

201-
var literal = page.Children[0].Children[0];
201+
var literal = page.Children[0].Children[0].Children[0];
202202
Assert.IsInstanceOfType(literal, typeof(Literal));
203203
Assert.AreEqual("aaa", ((Literal)literal).Text);
204204
}
@@ -267,9 +267,10 @@ public void DefaultViewCompiler_CodeGeneration_MarkupControl_InTemplate()
267267
Assert.IsTrue(string.IsNullOrWhiteSpace(((RawLiteral)literal1).EncodedText));
268268

269269
var markupControl = container.Children[1];
270-
Assert.IsInstanceOfType(markupControl, typeof(DotvvmView));
271-
Assert.IsInstanceOfType(markupControl.Children[0], typeof(Literal));
272-
Assert.AreEqual("aaa", ((Literal)markupControl.Children[0]).Text);
270+
Assert.IsInstanceOfType(markupControl, typeof(DotvvmMarkupControl));
271+
Assert.IsInstanceOfType(markupControl.Children[0], typeof(PlaceHolder));
272+
Assert.IsInstanceOfType(markupControl.Children[0].Children[0], typeof(Literal));
273+
Assert.AreEqual("aaa", ((Literal)markupControl.Children[0].Children[0]).Text);
273274

274275
var literal2 = container.Children[2];
275276
Assert.IsInstanceOfType(literal2, typeof(RawLiteral));
@@ -301,9 +302,10 @@ public void DefaultViewCompiler_CodeGeneration_MarkupControl_InTemplate_CacheTes
301302
Assert.IsTrue(string.IsNullOrWhiteSpace(((RawLiteral)literal1).EncodedText));
302303

303304
var markupControl = container.Children[1];
304-
Assert.IsInstanceOfType(markupControl, typeof(DotvvmView));
305-
Assert.IsInstanceOfType(markupControl.Children[0], typeof(Literal));
306-
Assert.AreEqual("aaa", ((Literal)markupControl.Children[0]).Text);
305+
Assert.IsInstanceOfType(markupControl, typeof(DotvvmMarkupControl));
306+
Assert.IsInstanceOfType(markupControl.Children[0], typeof(PlaceHolder));
307+
Assert.IsInstanceOfType(markupControl.Children[0].Children[0], typeof(Literal));
308+
Assert.AreEqual("aaa", ((Literal)markupControl.Children[0].Children[0]).Text);
307309

308310
var literal2 = container.Children[2];
309311
Assert.IsInstanceOfType(literal2, typeof(RawLiteral));

0 commit comments

Comments
 (0)