protected override void Visit(MacroChunk chunk)
        {
            this._source.Write(string.Format("\r\n    object {0}(", chunk.Name));
            string str = "";

            foreach (MacroParameter parameter in chunk.Parameters)
            {
                this._source.Write(str).WriteCode(parameter.Type).Write(" ").Write(parameter.Name);
                str = ", ";
            }
            this._source.WriteLine(")");
            this.CodeIndent(chunk).WriteLine("{");
            this.CodeHidden();
            this._source.WriteLine("        using(OutputScope(new System.IO.StringWriter()))");
            this._source.WriteLine("        {");
            this.CodeDefault();
            Dictionary <string, object> globalSymbols = new Dictionary <string, object>();

            foreach (MacroParameter parameter2 in chunk.Parameters)
            {
                globalSymbols.Add(parameter2.Name, null);
            }
            new GeneratedCodeVisitor(this._source, globalSymbols, this._nullBehaviour).Accept(chunk.Body);
            this.CodeHidden();
            this._source.WriteLine("            return HTML(Output);");
            this._source.WriteLine("        }");
            this._source.WriteLine("    }");
            this.CodeDefault();
        }
Beispiel #2
0
        protected override void Visit(MacroChunk chunk)
        {
            _source.Write("def ").Write(chunk.Name).Write("(");
            string delimiter = "";

            foreach (var parameter in chunk.Parameters)
            {
                _source.Write(delimiter).Write(parameter.Name);
                delimiter = ",";
            }
            _source.WriteLine(")");
            _source.Indent++;

            var generator = new GeneratedCodeVisitor(_source, _globals);

            _source.WriteLine("__output__scope__=output_scope");

            _source.WriteLine("begin");
            _source.Indent++;
            generator.Accept(chunk.Body);
            _source.WriteLine("return output.to_string");
            _source.Indent--;
            _source.WriteLine("ensure");
            _source.Indent++;
            _source.WriteLine("__output__scope__.dispose");
            _source.Indent--;
            _source.WriteLine("end");

            _source.Indent--;
            _source.WriteLine("end");
        }
        protected override void Visit(MacroChunk chunk)
        {
            _source.Write("def ").Write(chunk.Name).Write("(");
            string delimiter = "";

            foreach (var parameter in chunk.Parameters)
            {
                _source.Write(delimiter).Write(parameter.Name);
                delimiter = ",";
            }
            _source.WriteLine("):");
            _source.Indent++;
            foreach (var global in _globals.Keys)
            {
                _source.Write("global ").WriteLine(global);
            }
            var generator = new GeneratedCodeVisitor(_source, _globals);

            _source.WriteLine("__output__scope__=OutputScopeAdapter(None)");

            _source.WriteLine("try:");
            _source.Indent++;
            generator.Accept(chunk.Body);
            _source.WriteLine("return Output.ToString()");
            _source.Indent--;

            _source.WriteLine("finally:");
            _source.Indent++;
            _source.WriteLine("__output__scope__.Dispose()");
            _source.Indent--;

            _source.Indent--;
        }
Beispiel #4
0
        protected override void Visit(MacroChunk chunk)
        {
            _source.Write(string.Format("\r\n    object {0}(", chunk.Name));
            string delimiter = "";

            foreach (var parameter in chunk.Parameters)
            {
                _source.Write(delimiter).WriteCode(parameter.Type).Write(" ").Write(parameter.Name);
                delimiter = ", ";
            }
            _source.WriteLine(")");
            CodeIndent(chunk).WriteLine("{");
            CodeHidden();
            _source.WriteLine("        using(OutputScope(new System.IO.StringWriter()))");
            _source.WriteLine("        {");
            CodeDefault();

            var variables = new Dictionary <string, object>();

            foreach (var param in chunk.Parameters)
            {
                variables.Add(param.Name, null);
            }
            var generator = new GeneratedCodeVisitor(_source, variables, _nullBehaviour);

            generator.Accept(chunk.Body);

            CodeHidden();
            _source.WriteLine("            return HTML(Output);");
            _source.WriteLine("        }");
            _source.WriteLine("    }");
            CodeDefault();
        }
        protected override void Visit(MacroChunk chunk)
        {
            this._source.Append("function ").Append(chunk.Name).Append("(");
            string str = "";

            foreach (MacroParameter parameter in chunk.Parameters)
            {
                this._source.Append(str).Append(parameter.Name);
                str = ", ";
            }
            this._source.AppendLine(") {var __output__ = new StringWriter(); OutputScope(__output__);");
            new JavascriptGeneratedCodeVisitor(this._source).Accept(chunk.Body);
            this._source.AppendLine("DisposeOutputScope(); return __output__.toString();}");
        }
 protected override void Visit(MacroChunk chunk)
 {
     _source.Append("function ").Append(chunk.Name).Append("(");
     string delimiter = "";
     foreach (var parameter in chunk.Parameters)
     {
         _source.Append(delimiter).Append(parameter.Name);
         delimiter = ", ";
     }
     _source.AppendLine(") {var __output__ = new StringWriter(); OutputScope(__output__);");
     var codeVisitor = new JavascriptGeneratedCodeVisitor(_source);
     codeVisitor.Accept(chunk.Body);
     _source.AppendLine("DisposeOutputScope(); return __output__.toString();}");
 }
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            var name  = inspector.TakeAttribute("name");
            var macro = new MacroChunk {
                Name = name.Value, Position = Locate(inspector.OriginalNode)
            };

            foreach (var attr in inspector.Attributes)
            {
                macro.Parameters.Add(new MacroParameter {
                    Name = attr.Name, Type = AsCode(attr)
                });
            }
            AddUnordered(macro);
            using (new Frame(this, macro.Body))
            {
                Accept(inspector.Body);
            }
        }
        protected override void Visit(MacroChunk chunk)
        {
            this._source.Write("Public Function ").Write(chunk.Name).Write("(");
            string str = "";

            foreach (MacroParameter parameter in chunk.Parameters)
            {
                this._source.Write(str).Write(parameter.Name).Write(" As ").WriteCode(parameter.Type);
                str = ", ";
            }
            this._source.WriteLine(") As String").AddIndent();
            this._source.WriteLine("Using OutputScope(new Global.System.IO.StringWriter())").AddIndent();
            Dictionary <string, object> globalSymbols = new Dictionary <string, object>();

            foreach (MacroParameter parameter2 in chunk.Parameters)
            {
                globalSymbols.Add(parameter2.Name, null);
            }
            new GeneratedCodeVisitor(this._source, globalSymbols, this._nullBehaviour).Accept(chunk.Body);
            this._source.WriteLine("Return Output.ToString()").RemoveIndent().WriteLine("End Using").RemoveIndent().WriteLine("End Function");
        }
Beispiel #9
0
        protected override void Visit(MacroChunk chunk)
        {
            _source
            .Write("Public Function ")
            .Write(chunk.Name)
            .Write("(");
            var delimiter = "";

            foreach (var parameter in chunk.Parameters)
            {
                _source
                .Write(delimiter)
                .Write(parameter.Name)
                .Write(" As ")
                .WriteCode(parameter.Type);
                delimiter = ", ";
            }
            _source
            .WriteLine(") As String")
            .AddIndent();
            _source
            .WriteLine("Using OutputScope(new Global.System.IO.StringWriter())")
            .AddIndent();

            var variables = new Dictionary <string, object>();

            foreach (var param in chunk.Parameters)
            {
                variables.Add(param.Name, null);
            }

            var generator = new GeneratedCodeVisitor(_source, variables, _nullBehaviour);

            generator.Accept(chunk.Body);

            _source
            .WriteLine("Return Output.ToString()")
            .RemoveIndent().WriteLine("End Using")
            .RemoveIndent().WriteLine("End Function");
        }
Beispiel #10
0
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            AttributeNode node  = inspector.TakeAttribute("name");
            MacroChunk    chunk = new MacroChunk {
                Name     = node.Value,
                Position = this.Locate(inspector.OriginalNode)
            };

            foreach (AttributeNode node2 in inspector.Attributes)
            {
                MacroParameter item = new MacroParameter {
                    Name = node2.Name,
                    Type = this.AsCode(node2)
                };
                chunk.Parameters.Add(item);
            }
            this.AddUnordered(chunk);
            using (new Frame(this, chunk.Body))
            {
                base.Accept(inspector.Body);
            }
        }
Beispiel #11
0
        public void MacroAddsFunction()
        {
            var macro = new MacroChunk
            {
                Name       = "foo",
                Parameters = new[] { new MacroParameter {
                                         Name = "x", Type = "string"
                                     } }
            };

            macro.Body.Add(new SendExpressionChunk {
                Code = "x"
            });
            var chunks = Chunks(
                new SendExpressionChunk {
                Code = "foo(\"hello\")"
            },
                macro);

            _compiler.CompileView(chunks, chunks);
            var contents = ExecuteView();

            Assert.AreEqual("hello", contents);
        }
 protected abstract void Visit(MacroChunk chunk);
Beispiel #13
0
 protected override void Visit(MacroChunk chunk)
 {
 }
Beispiel #14
0
 protected override void Visit(MacroChunk chunk)
 {
 }
        // just declare methods, leave implementation is left for GeneratedCodeVistor
        protected override void Visit(MacroChunk chunk)
        {
            _source.Write("\r\n");
            _source.Write(string.Format("method {0}.{1}(", this.ViewClassName, chunk.Name));
            string delimiter = "";
            foreach (var parameter in chunk.Parameters)
            {
                _source.Write(delimiter).Write(parameter.Name).Write(" : ").WriteCode(parameter.Type);
                delimiter = "; ";
            }
            _source.WriteLine(") : System.Object;");

            CodeIndent(chunk).WriteLine("begin");
            _source.WriteLine("        using(OutputScope(new System.IO.StringWriter())) do");
            _source.WriteLine("        begin");

            var variables = new Dictionary<string, object>();
            foreach (var param in chunk.Parameters)
            {
                variables.Add(param.Name, null);
            }
            var generator = new GeneratedCodeVisitor(_source, variables, _nullBehaviour);
            generator.Accept(chunk.Body);

            _source.WriteLine("            result := self.ToMvcHtmlString(Output);");
            _source.WriteLine("        end;");
            _source.WriteLine("    end;");
        }
Beispiel #16
0
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            var name = inspector.TakeAttribute("name");
            var macro = new MacroChunk { Name = name.Value, Position = Locate(inspector.OriginalNode) };
            foreach (var attr in inspector.Attributes)
            {
                macro.Parameters.Add(new MacroParameter { Name = attr.Name, Type = AsCode(attr) });
            }

            AddUnordered(macro);
            using (new Frame(this, macro.Body))
            {
                Accept(inspector.Body);
            }
        }
Beispiel #17
0
 protected override void Visit(MacroChunk chunk)
 {
     Accept(chunk.Body);
 }
Beispiel #18
0
        protected override void Visit(MacroChunk chunk)
        {
            _source.Write(string.Format("\r\n    object {0}(", chunk.Name));
            string delimiter = "";
            foreach (var parameter in chunk.Parameters)
            {
                _source.Write(delimiter).WriteCode(parameter.Type).Write(" ").Write(parameter.Name);
                delimiter = ", ";
            }
            _source.WriteLine(")");
            CodeIndent(chunk).WriteLine("{");
            CodeHidden();
            _source.WriteLine("        using(OutputScope(new System.IO.StringWriter()))");
            _source.WriteLine("        {");
            CodeDefault();

            var variables = new Dictionary<string, object>();
            foreach (var param in chunk.Parameters)
            {
                variables.Add(param.Name, null);
            }
            var generator = new GeneratedCodeVisitor(_source, variables, _nullBehaviour);
            generator.Accept(chunk.Body);

            CodeHidden();
            _source.WriteLine("            return HTML(Output);");
            _source.WriteLine("        }");
            _source.WriteLine("    }");
            CodeDefault();
        }
 protected override void Visit(MacroChunk chunk)
 {
     // Must not do anything here. Macro is written out in PreRender.
 }
 protected abstract void Visit(MacroChunk chunk);
 protected override void Visit(MacroChunk chunk)
 {
     // Must not do anything here. Macro is written out in PreRender.
 }
 protected override void Visit(MacroChunk chunk)
 {
     Accept(chunk.Body);
 }
        protected override void Visit(MacroChunk chunk)
        {
            _source
                .Write("Public Function ")
                .Write(chunk.Name)
                .Write("(");
            var delimiter = "";
            foreach (var parameter in chunk.Parameters)
            {
                _source
                    .Write(delimiter)
                    .Write(parameter.Name)
                    .Write(" As ")
                    .WriteCode(parameter.Type);
                delimiter = ", ";
            }
            _source
                .WriteLine(") As String")
                .AddIndent();
            _source
                .WriteLine("Using OutputScope(new Global.System.IO.StringWriter())")
                .AddIndent();

            var variables = new Dictionary<string, object>();
            foreach (var param in chunk.Parameters)
            {
                variables.Add(param.Name, null);
            }

            var generator = new GeneratedCodeVisitor(_source, variables, _nullBehaviour);
            generator.Accept(chunk.Body);

            _source
                .WriteLine("Return Output.ToString()")
                .RemoveIndent().WriteLine("End Using")
                .RemoveIndent().WriteLine("End Function");
        }