Exemple #1
0
        public PathBasedPresetTreeExclusion(string excludedPath, TemplateTreeRoot root)
        {
            _excludedPath = excludedPath;

            // path that does not start with / is relative to the parent include root path
            if (!_excludedPath.StartsWith("/"))
            {
                _excludedPath = $"{root.Path.TrimEnd('/')}/{_excludedPath}";
            }

            // for legacy compatibility you can exclude children by having a path exclusion end with a trailing slash
            // but since we add a trailing slash internally to all paths (so that we match by path e.g. /foo != /foot)
            // we need to know if the original string had a trailing slash and handle it as a child exclusion
            _implicitChildrenExclusion = _excludedPath.EndsWith("/");

            // we internally add a trailing slash to the excluded path, and add a trailing slash to the incoming evaluate path
            // why? because otherwise using StartsWith would mean that /foo would also exclude /foot. But /foo/ and /foot/ do not match like that.
            _excludedPath = PathTool.EnsureTrailingSlash(_excludedPath);
        }
        public ChildrenOfPathBasedPresetTreeExclusion(string excludeChildrenOfPath, string[] exceptions, TemplateTreeRoot root)
        {
            _excludeChildrenOfPath = excludeChildrenOfPath;

            // path that does not start with / is relative to the parent include root path
            // eg include /foo, path 'bar' => /foo/bar
            if (!_excludeChildrenOfPath.StartsWith("/"))
            {
                _excludeChildrenOfPath = $"{root.Path.TrimEnd('/')}/{_excludeChildrenOfPath}";
            }

            // normalize the root path to have a trailing slash which will make the path match only children
            // (like implicit matching)
            _excludeChildrenOfPath = PathTool.EnsureTrailingSlash(_excludeChildrenOfPath);

            // convert all exceptions to full paths with a trailing slash (so we can match on path segments)
            _exceptions = exceptions.Select(exception => $"{PathTool.EnsureTrailingSlash(_excludeChildrenOfPath)}{exception}/").ToArray();
        }