/// <summary>
        /// Gets a string containing the compiled CoffeeScript result.
        /// </summary>
        /// <param name="input">
        /// The input to process.
        /// </param>
        /// <param name="options">
        /// The AutoPrefixer options.
        /// </param>
        /// <returns>
        /// The <see cref="string"/> containing the compiled CoffeeScript result.
        /// </returns>
        public string Process(string input, AutoPrefixerOptions options)
        {
            string processedCode;

            lock (SyncRoot)
            {
                this.Initialize();

                try
                {
                    string result = this.javascriptEngine.Evaluate <string>(string.Format(CompilationFunctionCallTemplate, JsonConvert.SerializeObject(input), ConvertAutoPrefixerOptionsToJson(options)));

                    JObject json   = JObject.Parse(result);
                    JArray  errors = json["errors"] as JArray;

                    if (errors != null && errors.Count > 0)
                    {
                        throw new AutoPrefixerProcessingException(FormatErrorDetails(errors[0]));
                    }

                    processedCode = json.Value <string>("processedCode");
                }
                catch (JsRuntimeException ex)
                {
                    throw new AutoPrefixerProcessingException(JsErrorHelpers.Format(ex));
                }
            }

            return(processedCode);
        }
Beispiel #2
0
        /// <summary>
        /// Converts <see cref="AutoPrefixerOptions"/> to JSON
        /// </summary>
        /// <param name="options">AutoPrefixerOptions options</param>
        /// <returns>AutoPrefixerOptions options in JSON format</returns>
        private static JObject ConvertAutoPrefixerOptionsToJson(AutoPrefixerOptions options)
        {
            JObject optionsJson = new JObject(
                new JProperty("browsers", new JArray(options.Browsers)),
                new JProperty("cascade", options.Cascade),
                new JProperty("safe", options.Safe));

            return(optionsJson);
        }
        /// <summary>
        /// Transforms the content of the given string. 
        /// </summary>
        /// <param name="input">
        /// The input string to transform.
        /// </param>
        /// <param name="options">
        /// The <see cref="AutoPrefixerOptions"/>.
        /// </param>
        /// <returns>
        /// The transformed string.
        /// </returns>
        public string Transform(string input, AutoPrefixerOptions options)
        {
            if (!options.Enabled)
            {
                return input;
            }

            using (AutoPrefixerProcessor processor = new AutoPrefixerProcessor(CruncherConfiguration.Instance.JsEngineFunc))
            {
                input = processor.Process(input, options);
            }

            return input;
        }
        /// <summary>
        /// Converts <see cref="AutoPrefixerOptions"/> to JSON
        /// </summary>
        /// <param name="options">AutoPrefixerOptions options</param>
        /// <returns>AutoPrefixerOptions options in JSON format</returns>
        private static JObject ConvertAutoPrefixerOptionsToJson(AutoPrefixerOptions options)
        {
            JObject optionsJson = new JObject(
                new JProperty("browsers", new JArray(options.Browsers)),
                new JProperty("cascade", options.Cascade),
                new JProperty("add", options.Add),
                new JProperty("remove", options.Remove),
                new JProperty("supports", options.Supports),
                new JProperty("flexbox", options.Flexbox),
                new JProperty("grid", options.Grid)
                );

            return(optionsJson);
        }
Beispiel #5
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">
        /// The input string to transform.
        /// </param>
        /// <param name="options">
        /// The <see cref="AutoPrefixerOptions"/>.
        /// </param>
        /// <returns>
        /// The transformed string.
        /// </returns>
        public string Transform(string input, AutoPrefixerOptions options)
        {
            if (!options.Enabled)
            {
                return(input);
            }

            using (AutoPrefixerProcessor processor = new AutoPrefixerProcessor(CruncherConfiguration.Instance.JsEngineFunc))
            {
                input = processor.Process(input, options);
            }

            return(input);
        }
        /// <summary>
        /// Converts <see cref="AutoPrefixerOptions"/> to JSON
        /// </summary>
        /// <param name="options">AutoPrefixerOptions options</param>
        /// <returns>AutoPrefixerOptions options in JSON format</returns>
        private static JObject ConvertAutoPrefixerOptionsToJson(AutoPrefixerOptions options)
        {
            JObject optionsJson = new JObject(
                new JProperty("browsers", new JArray(options.Browsers)),
                new JProperty("cascade", options.Cascade),
                new JProperty("safe", options.Safe));

            return optionsJson;
        }
        /// <summary>
        /// Gets a string containing the compiled CoffeeScript result.
        /// </summary>
        /// <param name="input">
        /// The input to process.
        /// </param>
        /// <param name="options">
        /// The AutoPrefixer options.
        /// </param>
        /// <returns>
        /// The <see cref="string"/> containing the compiled CoffeeScript result.
        /// </returns>
        public string Process(string input, AutoPrefixerOptions options)
        {
            string processedCode;

            lock (SyncRoot)
            {
                this.Initialize();

                try
                {
                    string result = this.javascriptEngine.Evaluate<string>(string.Format(CompilationFunctionCallTemplate, JsonConvert.SerializeObject(input), ConvertAutoPrefixerOptionsToJson(options)));

                    JObject json = JObject.Parse(result);
                    JArray errors = json["errors"] as JArray;

                    if (errors != null && errors.Count > 0)
                    {
                        throw new AutoPrefixerProcessingException(FormatErrorDetails(errors[0]));
                    }

                    processedCode = json.Value<string>("processedCode");
                }
                catch (JsRuntimeException ex)
                {
                    throw new AutoPrefixerProcessingException(JsRuntimeErrorHelpers.Format(ex));
                }
            }

            return processedCode;
        }