Beispiel #1
0
        public BlockClosingAction RenderSilentEval(ViewSourceReader viewSourceReader, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText;

            var lambdaMatch = lambdaRegex.Match(code);

            if (!lambdaMatch.Success)
            {
                builder.AppendSilentCode(code, !viewSourceReader.IsBlock);

                if (viewSourceReader.IsBlock)
                {
                    builder.BeginCodeBlock();

                    return(builder.EndCodeBlock);
                }

                return(MarkupRule.EmptyClosingAction);
            }

            var depth = viewSourceReader.CurrentInputLine.IndentCount;

            code = TranslateLambda(code, lambdaMatch);

            builder.AppendChangeOutputDepth(depth);
            builder.AppendSilentCode(code, true);

            return(() =>
            {
                builder.AppendChangeOutputDepth(depth);
                builder.AppendSilentCode("})", true);
            });
        }
        public BlockClosingAction RenderSilentEval(ViewSourceReader viewSourceReader, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText;

            builder.AppendSilentCode(code, false);

            if( viewSourceReader.IsBlock )
            {
                builder.BeginCodeBlock();

                if( !viewSourceReader.CurrentInputLine.NormalizedText.Trim().Split( ' ' )[0].ToUpperInvariant().Equals( "CASE" ) )
                {
                    return () =>
                      {
                          if( (viewSourceReader.CurrentInputLine.Text.TrimStart().StartsWith(SilentEvalMarkupRule.SignifierChar)) &&
                            MidBlockKeywords.Contains( viewSourceReader.CurrentInputLine.NormalizedText.Trim().Split( ' ' )[0].ToUpperInvariant() ) )
                          {
                              builder.Unindent();
                          }
                          else
                          {
                              builder.EndCodeBlock();
                          }
                      };
                }
            }

            return MarkupRule.EmptyClosingAction;
        }
        public BlockClosingAction RenderSilentEval(ViewSourceReader viewSourceReader, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText;

            var lambdaMatch = LambdaRegex.Match( code );

            var templateClassBuilder = (BooTemplateClassBuilder)builder;
            if( !lambdaMatch.Success )
            {
                templateClassBuilder.AppendSilentCode(code, !viewSourceReader.IsBlock);

                if( viewSourceReader.IsBlock )
                {
                    templateClassBuilder.BeginCodeBlock();

                    return templateClassBuilder.EndCodeBlock;
                }

                return MarkupRule.EmptyClosingAction;
            }

            var depth = viewSourceReader.CurrentInputLine.IndentCount;

            templateClassBuilder.AppendChangeOutputDepth( depth, true );
            templateClassBuilder.AppendSilentCode( code, false );
            templateClassBuilder.BeginCodeBlock();

            return () =>
              {
                  templateClassBuilder.AppendChangeOutputDepth( depth, false );
                  templateClassBuilder.EndCodeBlock();
              };
        }
Beispiel #4
0
        public BlockClosingAction RenderSilentEval(ViewSourceReader viewSourceReader, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText;

            builder.AppendSilentCode(code, false);

            if (viewSourceReader.IsBlock)
            {
                builder.BeginCodeBlock();

                if (!viewSourceReader.CurrentInputLine.NormalizedText.Trim().Split(' ')[0].ToUpperInvariant().Equals("CASE"))
                {
                    return(() =>
                    {
                        if ((viewSourceReader.CurrentInputLine.Text.TrimStart().StartsWith(SilentEvalMarkupRule.SignifierChar)) &&
                            MidBlockKeywords.Contains(viewSourceReader.CurrentInputLine.NormalizedText.Trim().Split(' ')[0].ToUpperInvariant()))
                        {
                            builder.Unindent();
                        }
                        else
                        {
                            builder.EndCodeBlock();
                        }
                    });
                }
            }

            return(MarkupRule.EmptyClosingAction);
        }
Beispiel #5
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var content          = currentInputLine.NormalizedText.Trim().ToLowerInvariant();

            if (string.IsNullOrEmpty(content))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">");
            }
            else if (string.Equals(content, "1.1"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">");
            }
            else if (string.Equals(content, "strict"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">");
            }
            else if (string.Equals(content, "frameset"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Frameset//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"">");
            }
            else if (string.Equals(content, "html"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"" ""http://www.w3.org/TR/html4/loose.dtd"">");
            }
            else if (string.Equals(content, "html strict"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01//EN"" ""http://www.w3.org/TR/html4/strict.dtd"">");
            }
            else if (string.Equals(content, "html frameset"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Frameset//EN"" ""http://www.w3.org/TR/html4/frameset.dtd"">");
            }
            else
            {
                var parts = content.Split(' ');

                if (string.Equals(parts[0], "xml"))
                {
                    var encoding = "utf-8";

                    if (parts.Length == 2)
                    {
                        encoding = parts[1];
                    }

                    var invariant = Utility.FormatInvariant(@"<?xml version=""1.0"" encoding=""{0}"" ?>", encoding);
                    builder.AppendOutput(invariant);
                }
                else
                {
                    SyntaxException.Throw(currentInputLine, ErrorParsingTag, currentInputLine);
                }
            }

            builder.AppendOutputLine();

            return(EmptyClosingAction);
        }
Beispiel #6
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var content = currentInputLine.NormalizedText.Trim().ToLowerInvariant();

            if (string.IsNullOrEmpty(content))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">");
            }
            else if (string.Equals(content, "1.1"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">");
            }
            else if (string.Equals(content, "strict"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">");
            }
            else if (string.Equals(content, "frameset"))
            {
                builder.AppendOutput(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Frameset//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"">");
            }
            else if (string.Equals(content, "html"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"" ""http://www.w3.org/TR/html4/loose.dtd"">");
            }
            else if (string.Equals(content, "html strict"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01//EN"" ""http://www.w3.org/TR/html4/strict.dtd"">");
            }
            else if (string.Equals(content, "html frameset"))
            {
                builder.AppendOutput(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Frameset//EN"" ""http://www.w3.org/TR/html4/frameset.dtd"">");
            }
            else
            {
                var parts = content.Split(' ');

                if (string.Equals(parts[0], "xml"))
                {
                    var encoding = "utf-8";

                    if (parts.Length == 2)
                    {
                        encoding = parts[1];
                    }

                    var invariant = Utility.FormatInvariant(@"<?xml version=""1.0"" encoding=""{0}"" ?>", encoding);
                    builder.AppendOutput(invariant);
                }
                else
                {
                    SyntaxException.Throw(currentInputLine, ErrorParsingTag,currentInputLine);
                }
            }

            builder.AppendOutputLine();

            return EmptyClosingAction;
        }
Beispiel #7
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            builder.AppendOutput(viewSourceReader.CurrentInputLine.Indent);
            builder.AppendOutput(viewSourceReader.CurrentInputLine.NormalizedText);
            builder.AppendOutputLine();

            return(EmptyClosingAction);
        }
Beispiel #8
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            builder.AppendOutput(viewSourceReader.CurrentInputLine.Indent);
            builder.AppendOutput(viewSourceReader.CurrentInputLine.NormalizedText);
            builder.AppendOutputLine();

            return EmptyClosingAction;
        }
Beispiel #9
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var match            = _commentRegex.Match(currentInputLine.NormalizedText);

            if (!match.Success)
            {
                SyntaxException.Throw(currentInputLine, ErrorParsingTag, currentInputLine);
            }

            var ieBlock = match.Groups[1].Value;
            var content = match.Groups[2].Value;

            var openingTag = new StringBuilder(currentInputLine.Indent);

            openingTag.Append("<!--");
            var closingTag = new StringBuilder("-->");

            if (!string.IsNullOrEmpty(ieBlock))
            {
                openingTag.AppendFormat("{0}>", ieBlock);
                closingTag.Insert(0, "<![endif]");
            }

            if (string.IsNullOrEmpty(content))
            {
                builder.AppendOutput(openingTag.ToString());
                builder.AppendOutputLine();
                closingTag.Insert(0, currentInputLine.Indent);
            }
            else
            {
                if (content.Length > 50)
                {
                    builder.AppendOutput(openingTag.ToString());
                    builder.AppendOutputLine();

                    builder.AppendOutput(viewSourceReader.NextIndent);

                    builder.AppendOutput(content);

                    builder.AppendOutputLine();
                }
                else
                {
                    builder.AppendOutput(openingTag.ToString());
                    builder.AppendOutput(content);
                    closingTag.Insert(0, ' ');
                }
            }

            return(() =>
            {
                builder.AppendOutput(closingTag.ToString());
                builder.AppendOutputLine();
            });
        }
Beispiel #10
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var match = _commentRegex.Match( currentInputLine.NormalizedText );

            if( !match.Success )
            {
                SyntaxException.Throw( currentInputLine, ErrorParsingTag, currentInputLine);
            }

            var ieBlock = match.Groups[1].Value;
            var content = match.Groups[2].Value;

            var openingTag = new StringBuilder(currentInputLine.Indent);
            openingTag.Append("<!--");
            var closingTag = new StringBuilder("-->");

            if( !string.IsNullOrEmpty( ieBlock ) )
            {
                openingTag.AppendFormat("{0}>",ieBlock);
                closingTag.Insert(0,"<![endif]");
            }

            if( string.IsNullOrEmpty( content ) )
            {
                builder.AppendOutput(openingTag.ToString());
                builder.AppendOutputLine();
                closingTag.Insert(0, currentInputLine.Indent);
            }
            else
            {
                if( content.Length > 50 )
                {
                    builder.AppendOutput(openingTag.ToString());
                    builder.AppendOutputLine();

                    builder.AppendOutput( viewSourceReader.NextIndent );

                    builder.AppendOutput(content);

                    builder.AppendOutputLine();
                }
                else
                {
                    builder.AppendOutput( openingTag.ToString() );
                    builder.AppendOutput( content );
                    closingTag.Insert(0, ' ');
                }
            }

            return () =>
                   {
                       builder.AppendOutput(closingTag.ToString());
                       builder.AppendOutputLine();
                   };
        }
Beispiel #11
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var inputLine = viewSourceReader.CurrentInputLine;

            builder.AppendOutput(inputLine.Indent);
            builder.AppendCode(inputLine.NormalizedText.Trim(), options.EncodeHtml);

            builder.AppendOutputLine();
            return(EmptyClosingAction);
        }
Beispiel #12
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var inputLine = viewSourceReader.CurrentInputLine;

            builder.AppendOutput( inputLine.Indent );
            builder.AppendCode(inputLine.NormalizedText.Trim(), options.EncodeHtml);

            builder.AppendOutputLine();
            return EmptyClosingAction;
        }
Beispiel #13
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText.Trim();

            if( !string.IsNullOrEmpty( code ) )
            {
                builder.AppendPreambleCode( code );
            }

            return EmptyClosingAction;
        }
Beispiel #14
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var code = viewSourceReader.CurrentInputLine.NormalizedText.Trim();

            if (!string.IsNullOrEmpty(code))
            {
                builder.AppendPreambleCode(code);
            }

            return(EmptyClosingAction);
        }
Beispiel #15
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var content = viewSourceReader.CurrentInputLine.NormalizedText.Trim().Replace("\"", "\"\"");

            var indexOfEquals = content.IndexOf('=');
            var key           = content.Substring(0, indexOfEquals).Trim();
            var value         = content.Substring(indexOfEquals + 1, content.Length - indexOfEquals - 1).Trim();

            builder.Meta[key] = value;

            return(EmptyClosingAction);
        }
Beispiel #16
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var content = viewSourceReader.CurrentInputLine.NormalizedText.Trim().Replace( "\"", "\"\"" );

            var indexOfEquals = content.IndexOf('=');
            var key = content.Substring(0, indexOfEquals).Trim();
            var value = content.Substring(indexOfEquals+1, content.Length - indexOfEquals - 1).Trim();

            builder.Meta[key] = value;

            return EmptyClosingAction;
        }
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var ruby = new StringBuilder();

            foreach (var reference in options.References)
            {
                ruby.AppendLine( string.Format("require '{0}'", reference) );
            }

            ruby.Append(builder.Build(options.Usings));

            var templateSource = ruby.ToString();
            _scriptEngine.Execute( templateSource );

            return CreateTemplateFactory( _scriptEngine, builder.ClassName );
        }
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var text = viewSourceReader.CurrentInputLine.NormalizedText.TrimStart();
		    var indexOfSpace = text.IndexOf(' ');
            var sectionName = text.Substring(indexOfSpace + 1, text.Length - indexOfSpace - 1);
            var code = string.Format("{0}).AddSection(\"{1}\", x =>", viewSourceReader.CurrentInputLine.Indent, sectionName);

            builder.EndCodeBlock();
            builder.Indent();

            builder.AppendSilentCode(code, false);
            builder.BeginCodeBlock();


            return builder.Unindent;
        }
Beispiel #19
0
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var templateSource = builder.Build(options.Usings);

            var typeBuilder = new BooTemplateTypeBuilder(options);

            var templateType = typeBuilder.Build(templateSource, builder.ClassName);

            if( templateType == null )
            {
                var path = ListExtensions.Last(viewSourceReader.ViewSources).Path;
                TemplateCompilationException.Throw( typeBuilder.CompilerResults,typeBuilder.Source, path );
            }

            return new TemplateFactory( templateType );
        }
Beispiel #20
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var text         = viewSourceReader.CurrentInputLine.NormalizedText.TrimStart();
            var indexOfSpace = text.IndexOf(' ');
            var sectionName  = text.Substring(indexOfSpace + 1, text.Length - indexOfSpace - 1);
            var code         = string.Format("{0}).AddSection(\"{1}\", x =>", viewSourceReader.CurrentInputLine.Indent, sectionName);

            builder.EndCodeBlock();
            builder.Indent();

            builder.AppendSilentCode(code, false);
            builder.BeginCodeBlock();


            return(builder.Unindent);
        }
Beispiel #21
0
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var templateSource = builder.Build(options.Usings);

            var typeBuilder = new BooTemplateTypeBuilder(options);

            var templateType = typeBuilder.Build(templateSource, builder.ClassName);

            if (templateType == null)
            {
                var path = ListExtensions.Last(viewSourceReader.ViewSources).Path;
                TemplateCompilationException.Throw(typeBuilder.CompilerResults, typeBuilder.Source, path);
            }

            return(new TemplateFactory(templateType));
        }
Beispiel #22
0
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var ruby = new StringBuilder();

            foreach (var reference in options.References)
            {
                ruby.AppendLine(string.Format("require '{0}'", reference));
            }

            ruby.Append(builder.Build(options.Usings));

            var templateSource = ruby.ToString();

            _scriptEngine.Execute(templateSource);

            return(CreateTemplateFactory(_scriptEngine, builder.ClassName));
        }
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var typeBuilder = CreateTemplateTypeBuilder(options);
            //TODO: leaky abstraction
            var classBuilder = (CodeDomClassBuilder) builder;
            var provider = GetCodeDomProvider(typeBuilder.ProviderOptions);
            classBuilder.CodeDomProvider = provider;
            typeBuilder.CodeDomProvider = provider;
            var templateSource = classBuilder.Build(options.Usings);

            var templateType = typeBuilder.Build( templateSource, classBuilder.ClassName );

            if( templateType == null )
            {
                var viewSources = viewSourceReader.ViewSources;
                TemplateCompilationException.Throw(typeBuilder.CompilerResults, typeBuilder.Source, ListExtensions.Last(viewSources).Path);
            }

            return new TemplateFactory( templateType );
        }
Beispiel #24
0
        public TemplateFactory Compile(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var typeBuilder = CreateTemplateTypeBuilder(options);
            //TODO: leaky abstraction
            var classBuilder = (CodeDomClassBuilder)builder;
            var provider     = GetCodeDomProvider(typeBuilder.ProviderOptions);

            classBuilder.CodeDomProvider = provider;
            typeBuilder.CodeDomProvider  = provider;
            var templateSource = classBuilder.Build(options.Usings);

            var templateType = typeBuilder.Build(templateSource, classBuilder.ClassName);

            if (templateType == null)
            {
                var viewSources = viewSourceReader.ViewSources;
                TemplateCompilationException.Throw(typeBuilder.CompilerResults, typeBuilder.Source, ListExtensions.Last(viewSources).Path);
            }

            return(new TemplateFactory(templateType));
        }
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {

            var dictionary = string.Empty;

            var text = viewSourceReader.CurrentInputLine.NormalizedText.Trim();
            var indexOfSpace = text.IndexOf(' ');
            string componentName ;
            if (indexOfSpace == -1)
            {
                componentName = text.Trim();
            }
            else
            {
                dictionary = text.Substring(indexOfSpace, text.Length - indexOfSpace);
                dictionary = dictionary.Trim();
                Debug.Assert(dictionary.StartsWith("{"), "dictionary must start with '{'");
                Debug.Assert(dictionary.EndsWith("}"), "dictionary must start with '}'");
                dictionary = dictionary.Substring(1, dictionary.Length - 2);
                componentName = text.Substring(0, indexOfSpace);
            }


            var codeDomClassBuilder = (CodeDomClassBuilder)builder;

            var dictionaryLocalVariable = AppendCreateDictionaryLocalVariable(dictionary, codeDomClassBuilder);

        	codeDomClassBuilder.CurrentTextWriterVariableName = "x";
            var code = string.Format("{0}Component(\"{1}\", {2}, (x) =>",
                                     viewSourceReader.CurrentInputLine.Indent, componentName, dictionaryLocalVariable);

            codeDomClassBuilder.AppendSilentCode(code, false);
            codeDomClassBuilder.BeginCodeBlock();
			return () =>
			       	{
			       		codeDomClassBuilder.EndCodeBlock();
			       		codeDomClassBuilder.AppendSilentCode(").Render();", false);
			       		codeDomClassBuilder.CurrentTextWriterVariableName = TemplateClassBuilder.DefaultTextWriterVariableName;
			       	};
        }
Beispiel #26
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var dictionary = string.Empty;

            var    text         = viewSourceReader.CurrentInputLine.NormalizedText.Trim();
            var    indexOfSpace = text.IndexOf(' ');
            string componentName;

            if (indexOfSpace == -1)
            {
                componentName = text.Trim();
            }
            else
            {
                dictionary = text.Substring(indexOfSpace, text.Length - indexOfSpace);
                dictionary = dictionary.Trim();
                Debug.Assert(dictionary.StartsWith("{"), "dictionary must start with '{'");
                Debug.Assert(dictionary.EndsWith("}"), "dictionary must start with '}'");
                dictionary    = dictionary.Substring(1, dictionary.Length - 2);
                componentName = text.Substring(0, indexOfSpace);
            }


            var codeDomClassBuilder = (CodeDomClassBuilder)builder;

            var dictionaryLocalVariable = AppendCreateDictionaryLocalVariable(dictionary, codeDomClassBuilder);

            codeDomClassBuilder.CurrentTextWriterVariableName = "x";
            var code = string.Format("{0}Component(\"{1}\", {2}, (x) =>",
                                     viewSourceReader.CurrentInputLine.Indent, componentName, dictionaryLocalVariable);

            codeDomClassBuilder.AppendSilentCode(code, false);
            codeDomClassBuilder.BeginCodeBlock();
            return(() =>
            {
                codeDomClassBuilder.EndCodeBlock();
                codeDomClassBuilder.AppendSilentCode(").Render();", false);
                codeDomClassBuilder.CurrentTextWriterVariableName = TemplateClassBuilder.DefaultTextWriterVariableName;
            });
        }
Beispiel #27
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var partialName = viewSourceReader.CurrentInputLine.NormalizedText.Trim();

            if (string.IsNullOrEmpty(partialName))
            {
                if (viewSourceReader.ViewSourceQueue.Count == 0)
                {
                    throw new InvalidOperationException(NoPartialName);
                }
                var templatePath = viewSourceReader.ViewSourceQueue.Dequeue();
                viewSourceReader.MergeTemplate(templatePath, true);
            }
            else
            {
                partialName = partialName.Insert(partialName.LastIndexOf(@"\", StringComparison.OrdinalIgnoreCase) + 1, "_");
                var viewSource = options.TemplateContentProvider.GetViewSource(partialName, viewSourceReader.ViewSources);
                viewSourceReader.ViewSourceModifiedChecks.Add(() => viewSource.IsModified);
                viewSourceReader.MergeTemplate(viewSource, true);
            }

            return EmptyClosingAction;
        }
Beispiel #28
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var partialName = viewSourceReader.CurrentInputLine.NormalizedText.Trim();

            if (string.IsNullOrEmpty(partialName))
            {
                if (viewSourceReader.ViewSourceQueue.Count == 0)
                {
                    throw new InvalidOperationException(NoPartialName);
                }
                var templatePath = viewSourceReader.ViewSourceQueue.Dequeue();
                viewSourceReader.MergeTemplate(templatePath, true);
            }
            else
            {
                partialName = partialName.Insert(partialName.LastIndexOf(@"\", StringComparison.OrdinalIgnoreCase) + 1, "_");
                var viewSource = options.TemplateContentProvider.GetViewSource(partialName, viewSourceReader.ViewSources);
                viewSourceReader.ViewSourceModifiedChecks.Add(() => viewSource.IsModified);
                viewSourceReader.MergeTemplate(viewSource, true);
            }

            return(EmptyClosingAction);
        }
Beispiel #29
0
 public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
 {
     return(options.TemplateCompiler.RenderSilentEval(viewSourceReader, builder));
 }
Beispiel #30
0
 public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
 {
     return options.TemplateCompiler.RenderSilentEval(viewSourceReader, builder);
 }
Beispiel #31
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var input = PreprocessLine(currentInputLine);
            var match = _tagRegex.Match(input);

            if (!match.Success)
            {
                SyntaxException.Throw(currentInputLine, ErrorParsingTag, currentInputLine);
            }

            var groups = match.Groups;
            var tagName = groups[1].Value.Replace("\\", string.Empty);

            var isWhitespaceSensitive = _whitespaceSensitiveTags.Contains(tagName);
            var openingTag = string.Format("{0}<{1}", currentInputLine.Indent, tagName);
            var closingTag = string.Format("</{0}>", tagName);

            builder.AppendOutput(openingTag);

            ParseAndRenderAttributes(builder, match);

            var action = groups[6].Value.Trim();

            if (string.Equals("/", action) || options.IsAutoClosingTag(tagName))
            {
                builder.AppendOutput(" />");
                builder.AppendOutputLine();
                return EmptyClosingAction;
            }

            var content = groups[7].Value.Trim();

            if (string.IsNullOrEmpty(content))
            {
                builder.AppendOutput(">");
                builder.AppendOutputLine();
                closingTag = currentInputLine.Indent + closingTag;
            }
            else
            {
                if ((content.Length > 50) || ("=" == action) || ("&=" == action) || ("!=" == action))
                {
                    builder.AppendOutput(">");

                    if (!isWhitespaceSensitive)
                    {
                        builder.AppendOutputLine();
                        builder.AppendOutput(viewSourceReader.NextIndent);
                    }

                    if (string.Equals("=", action))
                    {
                        builder.AppendCode(content, options.EncodeHtml);
                    }
                    else if (string.Equals("&=", action))
                    {
                        builder.AppendCode(content, true);
                    }
                    else if (string.Equals("!=", action))
                    {
                        builder.AppendCode(content, false);
                    }
                    else
                    {
                        AppendText(content, builder, options);
                    }

                    if (!isWhitespaceSensitive)
                    {
                        builder.AppendOutputLine();
                        closingTag = currentInputLine.Indent + closingTag;
                    }
                }
                else
                {
                    builder.AppendOutput(">");
                    AppendText(content, builder, options);
                    if ((currentInputLine.IndentCount + 1) == viewSourceReader.NextInputLine.IndentCount)
                    {
                        builder.AppendOutputLine();
                        closingTag = currentInputLine.Indent + closingTag;
                    }
                }
            }

            return () =>
            {
                builder.AppendOutput(closingTag);
                builder.AppendOutputLine();
            };
        }
Beispiel #32
0
 public abstract BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder);
Beispiel #33
0
 public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
 {
     return EmptyClosingAction;
 }
Beispiel #34
0
 public abstract BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder);
Beispiel #35
0
 public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
 {
     return(EmptyClosingAction);
 }
Beispiel #36
0
        public override BlockClosingAction Render(ViewSourceReader viewSourceReader, TemplateOptions options, TemplateClassBuilder builder)
        {
            var currentInputLine = viewSourceReader.CurrentInputLine;
            var input            = PreprocessLine(currentInputLine);
            var match            = _tagRegex.Match(input);

            if (!match.Success)
            {
                SyntaxException.Throw(currentInputLine, ErrorParsingTag, currentInputLine);
            }

            var groups  = match.Groups;
            var tagName = groups[1].Value.Replace("\\", string.Empty);

            var isWhitespaceSensitive = _whitespaceSensitiveTags.Contains(tagName);
            var openingTag            = string.Format("{0}<{1}", currentInputLine.Indent, tagName);
            var closingTag            = string.Format("</{0}>", tagName);

            builder.AppendOutput(openingTag);

            ParseAndRenderAttributes(builder, match);

            var action = groups[6].Value.Trim();

            if (string.Equals("/", action) || options.IsAutoClosingTag(tagName))
            {
                builder.AppendOutput(" />");
                builder.AppendOutputLine();
                return(EmptyClosingAction);
            }

            var content = groups[7].Value.Trim();

            if (string.IsNullOrEmpty(content))
            {
                builder.AppendOutput(">");
                builder.AppendOutputLine();
                closingTag = currentInputLine.Indent + closingTag;
            }
            else
            {
                if ((content.Length > 50) || ("=" == action) || ("&=" == action) || ("!=" == action))
                {
                    builder.AppendOutput(">");

                    if (!isWhitespaceSensitive)
                    {
                        builder.AppendOutputLine();
                        builder.AppendOutput(viewSourceReader.NextIndent);
                    }

                    if (string.Equals("=", action))
                    {
                        builder.AppendCode(content, options.EncodeHtml);
                    }
                    else if (string.Equals("&=", action))
                    {
                        builder.AppendCode(content, true);
                    }
                    else if (string.Equals("!=", action))
                    {
                        builder.AppendCode(content, false);
                    }
                    else
                    {
                        AppendText(content, builder, options);
                    }

                    if (!isWhitespaceSensitive)
                    {
                        builder.AppendOutputLine();
                        closingTag = currentInputLine.Indent + closingTag;
                    }
                }
                else
                {
                    builder.AppendOutput(">");
                    AppendText(content, builder, options);
                    if ((currentInputLine.IndentCount + 1) == viewSourceReader.NextInputLine.IndentCount)
                    {
                        builder.AppendOutputLine();
                        closingTag = currentInputLine.Indent + closingTag;
                    }
                }
            }

            return(() =>
            {
                builder.AppendOutput(closingTag);
                builder.AppendOutputLine();
            });
        }