public int ReplaceToken(int currentOffset, TemplateList list, Variables variables, ref string text) { int prevLength = text.Length; text = text.Remove(index + currentOffset, length).Insert(index + currentOffset, GetTokenContents(list, variables)); return(currentOffset + text.Length - prevLength); }
private void ReadFileToList(string file, TemplateList list) { string contents; try{ contents = File.ReadAllText(file, Encoding.UTF8); }catch(Exception e){ throw new TemplateException(Lang.Get["TemplateErrorFileRead", file], e); } string[] contentLines = contents.Split('\n', '\r'); if (contentLines.Length == 0){ throw new TemplateException(Lang.Get["TemplateErrorFileEmpty", file]); } for(int lineIndex = 0; lineIndex < contentLines.Length; lineIndex++){ string line = contentLines[lineIndex]; TemplateDeclaration declaration; if (TemplateDeclaration.TryReadLine(line, out declaration)){ if (declaration.DefinesTemplate){ StringBuilder build = new StringBuilder(); while(++lineIndex < contentLines.Length){ string templateLine = contentLines[lineIndex]; if (TemplateDeclaration.IsValidDeclaration(templateLine)){ --lineIndex; break; } build.Append(templateLine).Append("\r\n"); } list.AddTemplate(declaration, build.ToString()); } else if (declaration.Type == TemplateDeclaration.TemplateDeclarationType.Include){ string includedFile = Path.Combine(sourcePath, declaration.Name); if (!IsFilePathValid(includedFile)){ throw new TemplateException(Lang.Get["TemplateErrorIncludedFileWrongPath", declaration.Name]); } else if (!File.Exists(includedFile)){ throw new TemplateException(Lang.Get["TemplateErrorIncludedFileMissing", includedFile]); } else{ ReadFileToList(includedFile, list); } } } else if (line.Trim().Length > 0){ throw new TemplateException(Lang.Get["TemplateErrorFileMissingDeclaration", file, lineIndex]); } } }
public override string Process(TemplateList list, Variables variables) { string processedText = text; int offset = 0; foreach(TemplateToken token in tokens){ offset = token.ReplaceToken(offset, list, variables, ref processedText); } return processedText; }
public TemplateList ReadTemplates() { TemplateList templates = new TemplateList(); if (!File.Exists(mainFile)){ throw new TemplateException(Lang.Get["TemplateErrorMainFileMissing", mainFile]); } ReadFileToList(mainFile, templates); return templates; }
protected override string GetTokenContents(TemplateList list, Variables variables) { StringBuilder build = new StringBuilder(); foreach (Variables entry in variables.GetArray(cycleVariable)) { build.Append(list.ProcessTemplate(templateName, entry)); } return(build.ToString()); }
public TemplateList ReadTemplates() { TemplateList templates = new TemplateList(); if (!File.Exists(mainFile)) { throw new TemplateException(Lang.Get["TemplateErrorMainFileMissing", mainFile]); } ReadFileToList(mainFile, templates); return(templates); }
public override string Process(TemplateList list, Variables variables) { string processedText = text; int offset = 0; foreach (TemplateToken token in tokens) { offset = token.ReplaceToken(offset, list, variables, ref processedText); } return(processedText); }
protected abstract string GetTokenContents(TemplateList list, Variables variables);
public abstract string Process(TemplateList list, Variables variables);
protected override string GetTokenContents(TemplateList list, Variables variables) { return(list.ProcessTemplate(templateName, variables)); }
protected override string GetTokenContents(TemplateList list, Variables variables) { return(variables.CheckFlag(conditionFlag) ? list.ProcessTemplate(templateName, variables) : ""); }
public override string Process(TemplateList list, Variables variables) { return(text); }
public override string Process(TemplateList list, Variables variables) { return text; }
public int ReplaceToken(int currentOffset, TemplateList list, Variables variables, ref string text) { int prevLength = text.Length; text = text.Remove(index+currentOffset, length).Insert(index+currentOffset, GetTokenContents(list, variables)); return currentOffset+text.Length-prevLength; }
protected override string GetTokenContents(TemplateList list, Variables variables) { return variables.GetVariable(variableName, defaultValue); }
protected override string GetTokenContents(TemplateList list, Variables variables) { return list.ProcessTemplate(templateName, variables); }
protected override string GetTokenContents(TemplateList list, Variables variables) { StringBuilder build = new StringBuilder(); foreach(Variables entry in variables.GetArray(cycleVariable)){ build.Append(list.ProcessTemplate(templateName, entry)); } return build.ToString(); }
protected override string GetTokenContents(TemplateList list, Variables variables) { return variables.CheckFlag(conditionFlag) ? list.ProcessTemplate(templateName, variables) : ""; }
public GenerateHtml(TemplateList templateList, Variables variables) { this.templates = templateList; this.variables = variables; this.LastError = string.Empty; }
private void ReadFileToList(string file, TemplateList list) { string contents; try{ contents = File.ReadAllText(file, Encoding.UTF8); }catch (Exception e) { throw new TemplateException(Lang.Get["TemplateErrorFileRead", file], e); } string[] contentLines = contents.Split('\n', '\r'); if (contentLines.Length == 0) { throw new TemplateException(Lang.Get["TemplateErrorFileEmpty", file]); } for (int lineIndex = 0; lineIndex < contentLines.Length; lineIndex++) { string line = contentLines[lineIndex]; TemplateDeclaration declaration; if (TemplateDeclaration.TryReadLine(line, out declaration)) { if (declaration.DefinesTemplate) { StringBuilder build = new StringBuilder(); while (++lineIndex < contentLines.Length) { string templateLine = contentLines[lineIndex]; if (TemplateDeclaration.IsValidDeclaration(templateLine)) { --lineIndex; break; } build.Append(templateLine).Append("\r\n"); } list.AddTemplate(declaration, build.ToString()); } else if (declaration.Type == TemplateDeclaration.TemplateDeclarationType.Include) { string includedFile = Path.Combine(sourcePath, declaration.Name); if (!IsFilePathValid(includedFile)) { throw new TemplateException(Lang.Get["TemplateErrorIncludedFileWrongPath", declaration.Name]); } else if (!File.Exists(includedFile)) { throw new TemplateException(Lang.Get["TemplateErrorIncludedFileMissing", includedFile]); } else { ReadFileToList(includedFile, list); } } } else if (line.Trim().Length > 0) { throw new TemplateException(Lang.Get["TemplateErrorFileMissingDeclaration", file, lineIndex]); } } }
protected override string GetTokenContents(TemplateList list, Variables variables) { return(variables.GetVariable(variableName, defaultValue)); }