Exemplo n.º 1
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     switch (patternIndex)
     {
         case 0:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 1:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 2:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 3:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 4:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters, true);
         case 5:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters, true);
         case 6:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 7:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters);
         case 8:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters, true);
         case 9:
             return render(line, reader, RegularExpressionPatterns[patternIndex], parameters, true);
     }
     throw new TemplateException("Can't parse html tag.");
 }
Exemplo n.º 2
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match m = Regex.Match(line.Trim(),RegularExpressionPatterns[patternIndex]);
     String type = m.Groups["statment"].Value;
     type = type.Trim();
     string realType;
     switch (type)
     {
         case "xml":
             realType = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
             break;
         case "transitional":
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
             break;
         case "strict":
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
             break;
         case "frameset":
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
             break;
         case "1.1":
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">";
             break;
         case "basic":
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.1//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd\">";
             break;
         case "mobile":
             realType = "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.2//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd\">";
             break;
         default:
             realType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.1//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd\">";
             break;
     }
     return realType + "\n";
 }
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     String condition = lineMatch.Groups["condition"].Value;
     var interpreter = new Interpreter();
     foreach (var element in parameters)
     {
         interpreter.SetVariable(element.Key, element.Value, element.Value.GetType());
     }
     var result = interpreter.Eval<bool>(condition);
     if (result)
         return renderer.RenderBlock(reader.ReadBlock());
     reader.ReadBlock();
     return "";
 }
Exemplo n.º 4
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     String statment = lineMatch.Groups["statment"].Value;
     if (statment.Contains(" "))
         throw new TemplateException("Name of template can't contains space");
     Parent = statment;
     IsInParrent = false;
     String childSource = reader.ReadToEnd();
     renderer.RenderBlock(childSource);
     TextReader fileReader = File.OpenText(statment+".fte");
     String parrentSource = fileReader.ReadToEnd();
     fileReader.Close();
     IsInParrent = true;
     return renderer.RenderBlock(parrentSource);
 }
Exemplo n.º 5
0
 /// <summary>
 /// If in child template collect blocks
 /// If in parrent render blocks using child blocks
 /// </summary>
 /// <param name="line"></param>
 /// <param name="reader"></param>
 /// <param name="parameters"></param>
 /// <param name="patternIndex"></param>
 /// <returns></returns>
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     String statment = lineMatch.Groups["statment"].Value;
     if (!renderer.GetPlugin<ExtendsPlugin>().IsInParrent)
     {
         blocks.Add(statment, reader.ReadBlock());
         return "";
     }
     StringBuilder renderedSource = new StringBuilder();
     renderedSource.Append(renderer.RenderBlock(reader.ReadBlock()));
     if (blocks.ContainsKey(statment))
     {
         renderedSource.Append(renderer.RenderBlock(blocks[statment]));
     }
     return renderedSource.ToString();
 }
Exemplo n.º 6
0
 private string eachParser(string statment, TemplateReader reader, Dictionary<string, object> parameters)
 {
     string variable = @"([a-zA-Z_][a-zA-Z0-9_]*)([\.]([a-zA-Z_][a-zA-Z0-9_]*))*";
     string indexPattern = "(,[ ]*(?<index>" + variable + "))";
     string iteratorPattern = "(?<iterator>" + variable + ")";
     string collectionPattern="(?<collection>" + variable + ")";
     string optional = "?";
     string regex = iteratorPattern + "[ ]*" + indexPattern + optional + "[ ]+in[ ]+" + collectionPattern;
     Match m = Regex.Match(statment, regex);
     StringBuilder builder = new StringBuilder();
     if (m.Success)
     {
         String indexName = null;
         bool isWithIndex = m.Groups["index"].Success;
         if (isWithIndex)
             indexName = m.Groups["index"].Value;
         var iteratorName = m.Groups["iterator"].Value;
         var collectionName = m.Groups["collection"].Value;
         string codeBlock = reader.ReadBlock();
         if (codeBlock.Length == 0)
         {
             return "";
         }
         int index = 0;
         dynamic collection = parameters[collectionName];
         if (isWithIndex)
             parameters.Add(indexName, 0);
         foreach (var it in collection)
         {
             parameters.Add(iteratorName, it);
             if (isWithIndex)
                 parameters[indexName] = index;
             index++;
             builder.Append(renderer.RenderBlock(codeBlock));
             parameters.Remove(iteratorName);
         }
         if (isWithIndex)
             parameters.Remove(indexName);
     }
     else
     {
         throw new TemplateException("Can't parse each statment.");
     }
     return builder.ToString();
 }
Exemplo n.º 7
0
 public string callMixin(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match m = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     List<object> mixinParams = new List<object>();
     String mixinName = m.Groups["name"].Value;
     Mixin mixin = mixins[mixinName];
     var interpreter = new Interpreter();
     Dictionary<string, object> outerParameters = new Dictionary<string, object>();
     foreach (var element in parameters)
     {
         interpreter.SetVariable(element.Key, element.Value, element.Value.GetType());
     }
     foreach (Capture cap in m.Groups["param"].Captures)
     {
         var result = interpreter.Eval(cap.Value);
         mixinParams.Add(result);
     }
     if (mixinParams.Count != mixin.parameters.Count)
         throw new TemplateException("Missmatch number of mixin arguments");
     for (int i = 0; i < mixinParams.Count; i++)
     {
         if (parameters.ContainsKey(mixin.parameters[i]))
         {
             outerParameters.Add(mixin.parameters[i], parameters[mixin.parameters[i]]);
             parameters[mixin.parameters[i]] = mixinParams[i];
         }
         else
         {
             parameters.Add(mixin.parameters[i], mixinParams[i]);
         }
     }
     String blockRendered = renderer.RenderBlock(mixin.block);
     foreach(var n in mixin.parameters)
     {
         parameters.Remove(n);
     }
     foreach(var p in outerParameters)
     {
         parameters.Add(p.Key, p.Value);
     }
     return blockRendered;
 }
Exemplo n.º 8
0
 public abstract String RenderTag(String line, TemplateReader reader, Dictionary<string, object> parameters,int patternIndex);
Exemplo n.º 9
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     String text = lineMatch.Groups["text"].Value;
     return TemplateRendererUtils.CreateIndent(renderer.LineIndent) + text + "\n";
 }
Exemplo n.º 10
0
 public abstract String RenderTag(String line, TemplateReader reader, Dictionary <string, object> parameters, int patternIndex);
Exemplo n.º 11
0
 private string render(String line, TemplateReader reader, String pattern, Dictionary<string, object> parameters, bool renderWithTextBlock = false)
 {
     Match lineMatch = Regex.Match(line.Trim(), pattern);
     String tag = "div";
     String text = "";
     List<string> attributes = new List<string>();
     int level = reader.Level;
     if (lineMatch.Groups["tag"].Success)
     {
         tag = lineMatch.Groups["tag"].Value;
     }
     if (lineMatch.Groups["text"].Success)
     {
         text = lineMatch.Groups["text"].Value;
     }
     StringBuilder textBuilder = new StringBuilder();
     if (text.Length > 0)
     {
         textBuilder.Append(TemplateRendererUtils.CreateIndent(renderer.LineIndent + 1));
         textBuilder.Append(text);
         textBuilder.Append("\n");
     }
     renderer.LineIndent++;
     String sourceBlock;
     if (renderWithTextBlock||textBlockTags.Contains(tag))
     {
         sourceBlock = reader.ReadBlockWithIndent(renderer.LineIndent);
         sourceBlock = sourceBlock.TrimEnd('\n');
         if (sourceBlock.Length > 0)
         {
             textBuilder.Append(sourceBlock);
             textBuilder.Append("\n");
         }
     }
     else
     {
         sourceBlock=reader.ReadBlock();
         textBuilder.Append(renderer.RenderBlock(sourceBlock));
     }
     renderer.LineIndent--;
     if (lineMatch.Groups["id"].Success)
     {
         attributes.Add("id=\"" + lineMatch.Groups["id"].Value + "\"");
     }
     if (lineMatch.Groups["class"].Success)
     {
         attributes.Add("class=\"" + lineMatch.Groups["class"].Value + "\"");
     }
     foreach (Capture cap in lineMatch.Groups["attr"].Captures)
     {
         attributes.Add(cap.Value.Trim());
     }
     return generateTag(tag, attributes, textBuilder.ToString());
 }
Exemplo n.º 12
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     String statment = lineMatch.Groups["statment"].Value;
     return eachParser(statment, reader, parameters);
 }
Exemplo n.º 13
0
 public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex)
 {
     if (patternIndex < 3)
     {
         return declareMixin(line, reader, patternIndex);
     }
     else
     {
         return callMixin(line, reader, parameters, patternIndex);
     }
 }
Exemplo n.º 14
0
 public string declareMixin(string line, TemplateReader reader, int patternIndex)
 {
     Match m = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]);
     Mixin mixin = new Mixin();
     String mixinName = m.Groups["name"].Value;
     foreach (Capture cap in m.Groups["attr_name"].Captures)
     {
         mixin.parameters.Add(cap.Value);
     }
     String block = reader.ReadBlockWithIndent(0);
     mixin.block = block;
     mixins.Add(mixinName, mixin);
     return "";
 }