Example #1
0
        private void Import(ITextTemplatingEngineHost host, Directive includeDirective, string relativeToDirectory)
        {
            string fileName;

            if (includeDirective.Attributes.Count > 1 || !includeDirective.Attributes.TryGetValue("file", out fileName))
            {
                LogError("Unexpected attributes in include directive", includeDirective.StartLocation);
                return;
            }

            //try to resolve path relative to the file that included it
            if (relativeToDirectory != null && !Path.IsPathRooted(fileName))
            {
                var possible = Path.Combine(relativeToDirectory, fileName);
                if (File.Exists(possible))
                {
                    fileName = Path.GetFullPath(possible);
                }
            }

            string content, resolvedName;

            if (host.LoadIncludeText(fileName, out content, out resolvedName))
            {
                Parse(host, new Tokeniser(resolvedName, content), true, true);
            }
            else
            {
                LogError("Could not resolve include file '" + fileName + "'.", includeDirective.StartLocation);
            }
        }
Example #2
0
        void Import(ITextTemplatingEngineHost host, Directive includeDirective)
        {
            string fileName;

            if (includeDirective.Attributes.Count > 1 || !includeDirective.Attributes.TryGetValue("file", out fileName))
            {
                LogError("Unexpected attributes in include directive", includeDirective.StartLocation);
                return;
            }
            if (!File.Exists(fileName))
            {
                LogError("Included file '" + fileName + "' does not exist.", includeDirective.StartLocation);
                return;
            }

            string content, resolvedName;

            if (host.LoadIncludeText(fileName, out content, out resolvedName))
            {
                Parse(host, new Tokeniser(resolvedName, content), true);
            }
            else
            {
                LogError("Could not resolve include file '" + fileName + "'.", includeDirective.StartLocation);
            }
        }