JsonFx.UI.Jbst.JbstWriter.Render C# (CSharp) Method

Render() public method

public Render ( TextWriter writer ) : void
writer System.IO.TextWriter
return void
        public void Render(TextWriter writer)
        {
            this.ProcessDirectives();

            // add JSLINT directives
            string globals = this.GetGlobals();
            if (!String.IsNullOrEmpty(globals))
            {
                writer.WriteLine("/*global {0} */", globals);
            }

            if (!EcmaScriptWriter.WriteNamespaceDeclaration(writer, this.JbstName, null, true))
            {
                writer.Write("var ");
            }

            // wrap with ctor and assign
            writer.Write(this.JbstName);
            writer.WriteLine(" = JsonML.BST(");

            // render root node of content (null is OK)
            EcmaScriptWriter jsWriter = new EcmaScriptWriter(writer);
            jsWriter.Settings.PrettyPrint = true;
            jsWriter.Write(this.JbstParseTree);

            writer.WriteLine(");");

            // render any declarations
            if (this.Declarations.HasCode)
            {
                this.Declarations.OwnerName = this.JbstName;
                jsWriter.Write(this.Declarations);
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Compiles the provided input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="filename"></param>
        /// <param name="compilationErrors"></param>
        /// <param name="compactionErrors"></param>
        /// <returns></returns>
        public IOptimizedResult Compile(TextReader input, string filename, List <ParseException> compilationErrors, List <ParseException> compactionErrors)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            // verify, compact and write out results
            // parse JBST markup
            JbstWriter writer = new JbstWriter(filename);

            StringWriter sw = new StringWriter();

            string source = input.ReadToEnd();

            try
            {
                HtmlDistiller parser = new HtmlDistiller();
                parser.EncodeNonAscii      = false;
                parser.BalanceTags         = false;
                parser.NormalizeWhitespace = false;
                parser.HtmlWriter          = writer;
                parser.HtmlFilter          = new NullHtmlFilter();
                parser.Parse(source);

                // render the pretty-printed version
                writer.Render(sw);
            }
            catch (ParseException ex)
            {
                compilationErrors.Add(ex);
            }
            catch (Exception ex)
            {
                compilationErrors.Add(new ParseError(ex.Message, filename, 0, 0, ex));
            }

            SimpleJbstBuildResult result = new SimpleJbstBuildResult(writer.JbstName, writer.AutoMarkup);

            result.Source        = source;
            result.PrettyPrinted = sw.GetStringBuilder().ToString();
            result.Compacted     = this.Compact(result.PrettyPrinted, filename, compactionErrors);
            result.ContentType   = "text/javascript";
            result.FileExtension = ".jbst.js";
            result.Hash          = this.ComputeHash(result.Source);

            // return any errors
            return(result);
        }
All Usage Examples Of JsonFx.UI.Jbst.JbstWriter::Render