/// <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); }
/// <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; }
private void PushTag(string rawName) { string tagName; string prefix = JbstWriter.SplitPrefix(rawName, out tagName); JbstContainerControl control; if (JbstCommandBase.JbstPrefix.Equals(prefix, StringComparison.OrdinalIgnoreCase)) { if (StringComparer.OrdinalIgnoreCase.Equals(JbstControlReference.ControlCommand, tagName)) { control = new JbstControlReference(); } else if (StringComparer.OrdinalIgnoreCase.Equals(JbstPlaceholder.PlaceholderCommand, tagName)) { control = new JbstPlaceholder(); } else if (StringComparer.OrdinalIgnoreCase.Equals(JbstInline.InlineCommand, tagName)) { control = new JbstInline(); } else { throw new InvalidOperationException("Unknown JBST command ('" + rawName + "')"); } } else { control = new JbstContainerControl(prefix, tagName); } if (this.current == null) { this.current = this.document; } this.current.ChildControls.Add(control); this.current = control; }
public static List<ParseException> Compile( string inputFile, string inputSource, TextWriter output, string copyright, string timeStamp, bool prettyPrint) { if (output == null) { throw new NullReferenceException("Output TextWriter was null."); } if (String.IsNullOrEmpty(inputSource)) { if (String.IsNullOrEmpty(inputFile)) { throw new NullReferenceException("Input file path was empty."); } inputSource = File.ReadAllText(inputFile); } // write out header with copyright and timestamp WriteHeader(output, copyright, timeStamp); // verify, compact and write out results // parse JBST markup JbstWriter writer = new JbstWriter(inputFile); List<ParseException> errors = new List<ParseException>(); try { HtmlDistiller parser = new HtmlDistiller(); parser.EncodeNonAscii = false; parser.BalanceTags = false; parser.NormalizeWhitespace = false; parser.HtmlWriter = writer; parser.HtmlFilter = new NullHtmlFilter(); parser.Parse(inputSource); } catch (ParseException ex) { errors.Add(ex); } catch (Exception ex) { errors.Add(new ParseError(ex.Message, inputFile, 0, 0, ex)); } // render the pretty-printed version writer.Render(output); // return any errors return errors; }
protected override void ResetCodeProvider() { this.jbstWriter = null; base.ResetCodeProvider(); }
protected override void ProcessResource( IResourceBuildHelper helper, string virtualPath, string sourceText, out string resource, out string compacted, List<ParseException> errors) { // parse JBST markup this.jbstWriter = new JbstWriter(virtualPath); try { HtmlDistiller parser = new HtmlDistiller(); parser.EncodeNonAscii = false; parser.BalanceTags = false; parser.NormalizeWhitespace = false; parser.HtmlWriter = this.jbstWriter; parser.HtmlFilter = new NullHtmlFilter(); parser.Parse(sourceText); // determine which globalization keys were used JbstCodeProvider.ExtractGlobalizationKeys(this.jbstWriter.JbstParseTree, this.GlobalizationKeys); } catch (ParseException ex) { errors.Add(ex); } catch (Exception ex) { errors.Add(new ParseError(ex.Message, virtualPath, 0, 0, ex)); } string renderedTemplate; using (StringWriter sw = new StringWriter()) { // render the pretty-printed version this.jbstWriter.Render(sw); sw.Flush(); renderedTemplate = sw.ToString(); resource = ScriptResourceCodeProvider.FirewallScript(virtualPath, renderedTemplate, false); } // min the output for better compaction compacted = ScriptCompactionAdapter.Compact(virtualPath, renderedTemplate, errors); compacted = ScriptResourceCodeProvider.FirewallScript(virtualPath, compacted, true); }