A simple adapter for connecting ResourceBuildProvider to YuiCompressor.NET/EcmaScript.NET.
Example #1
0
        // TODO: clean up all the various styles of input/output

        #region Public Methods

        public static List <ParseException> Compact(
            string virtualPath,
            string inputSource,
            TextWriter output)
        {
            if (output == null)
            {
                throw new NullReferenceException("Output TextWriter was null.");
            }

            List <ParseException> errors = new List <ParseException>();

            // compact and write out results
            try
            {
                if (String.IsNullOrEmpty(inputSource))
                {
                    inputSource = File.ReadAllText(virtualPath);
                }

                string compacted = ScriptCompactionAdapter.Compact(virtualPath, inputSource, errors);

                output.Write(compacted);
            }
            catch (ParseError ex)
            {
                errors.Add(ex);
            }

            // return any errors
            return(errors);
        }
Example #2
0
        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);
        }
Example #3
0
        protected internal override void ProcessResource(
            IResourceBuildHelper helper,
            string virtualPath,
            string sourceText,
            out string resource,
            out string compacted,
            List <ParseException> errors)
        {
            using (StringWriter writer = new StringWriter())
            {
                IList <ParseException> parseErrors;
                try
                {
                    parseErrors = ScriptCompactionAdapter.Compact(
                        virtualPath,
                        sourceText,
                        writer);
                }
                catch (ParseException ex)
                {
                    errors.Add(ex);
                    parseErrors = null;
                }
                catch (Exception ex)
                {
                    errors.Add(new ParseError(ex.Message, virtualPath, 0, 0, ex));
                    parseErrors = null;
                }

                if (parseErrors != null && parseErrors.Count > 0)
                {
                    errors.AddRange(parseErrors);
                }

                writer.Flush();

                resource  = ScriptResourceCodeProvider.FirewallScript(virtualPath, sourceText, false);
                compacted = ScriptResourceCodeProvider.FirewallScript(virtualPath, writer.ToString(), true);

                this.ExtractGlobalizationKeys(compacted);
            }
        }