Beispiel #1
0
        /// <summary>
        /// Actualizes a vendor prefixes in CSS code by using Andrey Sitnik's Autoprefixer
        /// </summary>
        /// <param name="content">Text content of CSS asset</param>
        /// <param name="path">Path to CSS asset</param>
        /// <returns>Autoprefixing result</returns>
        public AutoprefixingResult Process(string content, string path)
        {
            Initialize();

            AutoprefixingResult autoprefixingResult;

            try
            {
                var result = _jsEngine.Evaluate <string>(
                    string.Format(AUTOPREFIXING_FUNCTION_CALL_TEMPLATE,
                                  JsonConvert.SerializeObject(content), _optionsString));

                var json = JObject.Parse(result);

                var errors = json["errors"] != null ? json["errors"] as JArray : null;
                if (errors != null && errors.Count > 0)
                {
                    throw new CssAutoprefixingException(FormatErrorDetails(errors[0], content, path));
                }

                autoprefixingResult = new AutoprefixingResult
                {
                    ProcessedContent  = json.Value <string>("processedCode"),
                    IncludedFilePaths = GetIncludedFilePaths(_options.Stats)
                };
            }
            catch (JsRuntimeException e)
            {
                throw new CssAutoprefixingException(JsErrorHelpers.Format(e));
            }

            return(autoprefixingResult);
        }
Beispiel #2
0
        /// <summary>
        /// Actualizes a vendor prefixes in CSS code by using Andrey Sitnik's Autoprefixer
        /// </summary>
        /// <param name="content">Text content of CSS asset</param>
        /// <param name="path">Path to CSS asset</param>
        /// <returns>Autoprefixing result</returns>
        public AutoprefixingResult Process(string content, string path)
        {
            Initialize();

            AutoprefixingResult autoprefixingResult;

            try
            {
                var result = _jsEngine.Evaluate <string>(
                    string.Format(AUTOPREFIXING_FUNCTION_CALL_TEMPLATE,
                                  JsonConvert.SerializeObject(content), _optionsString));

                var json = JObject.Parse(result);

                var errors = json["errors"] != null ? json["errors"] as JArray : null;
                if (errors != null && errors.Count > 0)
                {
                    throw new CssAutoprefixingException(FormatErrorDetails(errors[0], content, path));
                }

                autoprefixingResult = new AutoprefixingResult
                {
                    ProcessedContent  = json.Value <string>("processedCode"),
                    IncludedFilePaths = GetIncludedFilePaths(_options.Stats)
                };
            }
            catch (JsScriptException e)
            {
                string errorDetails = JsErrorHelpers.GenerateErrorDetails(e, true);

                var           stringBuilderPool   = StringBuilderPool.Shared;
                StringBuilder errorMessageBuilder = stringBuilderPool.Rent();
                errorMessageBuilder.AppendLine(e.Message);
                errorMessageBuilder.AppendLine();
                errorMessageBuilder.Append(errorDetails);

                string errorMessage = errorMessageBuilder.ToString();
                stringBuilderPool.Return(errorMessageBuilder);

                throw new CssAutoprefixingException(errorMessage);
            }

            return(autoprefixingResult);
        }