public void GetVersions(FileVariable fv) { // {{entity_field_list[[{{tab}}{{tab}}{{tab}}<v-><data_type:int,is_dto_field:true|int code>,<data_type : DateTime|DateTime code>, <default|default code><-v>{{nl}}]]}} fv.Versions = new List <TemplateVersion>(); // see if there are multiple versions of the template // (old) var verMatch = Regex.Match(fv.InnerTemplate, "<v->.+<-v>"); var verMatch = Regex.Match(fv.InnerTemplate, "<v->(.|\n)+<-v>"); if (verMatch.Success) { var versions = Regex.Matches(fv.InnerTemplate, @"< *( *\w+ *: *\w+ *,?|default)* *\| *([^>])+ *>"); if (versions.Count > 0) { // parse each type foreach (var version in versions) { TemplateVersion ver = new TemplateVersion(); // get the parameters first var parameters = Regex.Matches(version.ToString(), @"(\w+ *: *\w+ *)"); if (parameters.Count > 0) { foreach (var p in parameters) { string[] parts = p.ToString().Split(':'); //ver.Parameters.Add(parts[0].Trim(), parts[1].Trim()); } } else { // this must be the default version ver.IsDefault = true; } // get the template ver.Template = getInBetween(version.ToString(), "|", ">"); fv.Versions.Add(ver); } } // replace the versions with a tag fv.InnerTemplate = fv.InnerTemplate.Replace(verMatch.ToString(), "{{template_versions}}"); } }
public List <FileVariable> GetVariables(string template) { // get a list of all the variables in the file List <FileVariable> variables = new List <FileVariable>(); var matches = Regex.Matches(template, @"(?!(\[\[.*)){{ *\w+ *}}(?!(.*\]\]))"); foreach (var match in matches) { var name = match.ToString().Replace("{{", "").Replace("}}", "").Trim(); // see if this variable is already in the list if (!variables.Any(v => v.Tag.Equals(match.ToString()))) { FileVariable fv = new FileVariable(); fv.Tag = match.ToString(); fv.Name = name; variables.Add(fv); } } return(variables); }