/// <summary>
        /// Parses and includes the referenced template
        /// </summary>
        /// <param name="result"></param>
        void ParseIncludeStatement(ref ParseResult result)
        {
            // matches statements that begin with include
            if (result.TokenSplit.Length < 2 || result.TokenSplit[0] != "Include")
                return;

            string path = result.TokenSplit[1];
            //string path = System.IO.Path.Combine(_templateFolder, fileName);

            Template subTemplate = _parent.GetTemplateByFileName(path);

            // ensure the file exists
            if (subTemplate==null)
            {
                string message = "The Include template could not be found: '" + path + "'";
                throw new TemplateException(message, _lineNumber, result.Token, null);
            }

            // parse the include and set the result to the content created
            TemplateParser subParser = new TemplateParser(subTemplate, _data, _parent);
            foreach(CodeFile file in  subParser.ParseTemplate())
            {
                result.Value += file.FileContents;
                result.Value += Environment.NewLine + Environment.NewLine;
            }
        }
Example #2
0
        /// <summary>
        /// Generates code files for the data object using each template 
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public CodeFiles GenerateCode(TemplateData Data)
        {
            CodeFiles result = new CodeFiles();
            GenerationEventArgs e = new GenerationEventArgs() { DataObjectName = Data.DataContainerName };

            string type = Data.DataContainer.IsView ? "view" : "table";

            // generate code files for each template
            foreach (Template template in _templates.Where(t => t.IsInclude == false))
            {
                // only run templates for the right type of data object (ie. view or table)
                if (template.For.Contains(type))
                {
                    TemplateParser parser = new TemplateParser(template, Data, this);
                    CodeFile[] files = parser.ParseTemplate();
                    foreach (CodeFile file in files)
                        result.AddCodeFile(file);

                    e.TemplatesApplied.Add(template.FileName);
                    e.ParsingErrors.AddRange(parser.Exceptions);
                }

                // trigger the generated event
                OnCodeGenerated(e);
            }

            // merge in data common and safe reader
            result.Merge(GetDALCommonFiles(Data.RootNamespace));

            return result;
        }