Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative paths in automatic control registration #1817

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Routing;

namespace DotVVM.Framework.Configuration
{
public class DefaultControlRegistrationStrategy : IControlRegistrationStrategy
{
private DotvvmConfiguration configuration;
readonly DotvvmConfiguration configuration;
readonly string controlPrefix;
readonly string controlsDirectory;
readonly string filesFilter;
Expand All @@ -31,6 +32,10 @@ protected virtual IEnumerable<string> ListFiles()

public IEnumerable<DotvvmControlConfiguration> GetControls()
=> ListFiles()
.Select(f => new DotvvmControlConfiguration { Src = f, TagPrefix = GetControlPrefix(f), TagName = GetControlName(f) });
.Select(f => new DotvvmControlConfiguration {
Src = DefaultRouteStrategy.GetRelativePathBetween(configuration.ApplicationPhysicalPath, f),
TagPrefix = GetControlPrefix(f),
TagName = GetControlName(f)
});
}
}
2 changes: 1 addition & 1 deletion src/Framework/Framework/Routing/DefaultRouteStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected virtual IEnumerable<RouteStrategyMarkupFileInfo> DiscoverMarkupFiles()
});
}

private string GetRelativePathBetween(string from, string to)
internal static string GetRelativePathBetween(string from, string to)
{
var fromPath = from.Replace('\\', '/');
var toPath = to.Replace('\\', '/');
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/Common/DotvvmStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ private static void AddControls(DotvvmConfiguration config)

config.Markup.AutoDiscoverControls(new DefaultControlRegistrationStrategy(config, "sample", "Views/"));

if (config.Markup.Controls.FirstOrDefault(c => c.Src is not null && Path.IsPathRooted(c.Src)) is {} invalidControl)
throw new Exception($"Some controls have absolute paths! ({invalidControl.TagPrefix}:{invalidControl.TagName} - {invalidControl.Src})");
}

}
Expand Down
Loading