Beispiel #1
0
        /// <summary>
        /// Produces a code minifiction of CSS assets by using Sergey Kryzhanovsky's CSSO (CSS Optimizer)
        /// </summary>
        /// <param name="assets">Set of CSS assets</param>
        /// <returns>Set of CSS assets with minified text content</returns>
        public IList <IAsset> Minify(IList <IAsset> assets)
        {
            if (assets == null)
            {
                throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "assets");
            }

            if (assets.Count == 0)
            {
                return(assets);
            }

            var assetsToProcessing = assets.Where(a => a.IsStylesheet && !a.Minified).ToList();

            if (assetsToProcessing.Count == 0)
            {
                return(assets);
            }

            OptimizationOptions options = CreateOptimizationOptions();

            using (var cssOptimizer = new CssOptimizer(_createJsEngineInstance, options))
            {
                foreach (var asset in assetsToProcessing)
                {
                    InnerMinify(asset, cssOptimizer);
                }
            }

            return(assets);
        }
Beispiel #2
0
        private void InnerMinify(IAsset asset, CssOptimizer cssOptimizer)
        {
            string newContent;
            string assetUrl = asset.Url;

            try
            {
                newContent = cssOptimizer.Optimize(asset.Content, assetUrl);
            }
            catch (CssOptimizationException e)
            {
                throw new AssetMinificationException(
                          string.Format(CoreStrings.Minifiers_MinificationSyntaxError,
                                        CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
            }
            catch (Exception e)
            {
                throw new AssetMinificationException(
                          string.Format(CoreStrings.Minifiers_MinificationFailed,
                                        CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message), e);
            }

            asset.Content  = newContent;
            asset.Minified = true;
        }
Beispiel #3
0
        /// <summary>
        /// Produces a code minifiction of CSS asset by using Sergey Kryzhanovsky's CSSO (CSS Optimizer)
        /// </summary>
        /// <param name="asset">CSS asset</param>
        /// <returns>CSS asset with minified text content</returns>
        public IAsset Minify(IAsset asset)
        {
            if (asset == null)
            {
                throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "asset");
            }

            if (asset.Minified)
            {
                return(asset);
            }

            OptimizationOptions options = CreateOptimizationOptions();

            using (var cssOptimizer = new CssOptimizer(_createJsEngineInstance, options))
            {
                InnerMinify(asset, cssOptimizer);
            }

            return(asset);
        }
        /// <summary>
        /// Produces a code minifiction of CSS asset by using Sergey Kryzhanovsky's CSSO (CSS Optimizer)
        /// </summary>
        /// <param name="asset">CSS asset</param>
        /// <returns>CSS asset with minified text content</returns>
        public IAsset Minify(IAsset asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(
                          nameof(asset),
                          string.Format(CoreStrings.Common_ArgumentIsNull, nameof(asset))
                          );
            }

            if (asset.Minified)
            {
                return(asset);
            }

            OptimizationOptions options = CreateOptimizationOptions();

            using (var cssOptimizer = new CssOptimizer(_createJsEngineInstance, options))
            {
                InnerMinify(asset, cssOptimizer);
            }

            return(asset);
        }
		/// <summary>
		/// Produces a code minifiction of CSS-asset by using Sergey Kryzhanovsky's CSSO (CSS Optimizer)
		/// </summary>
		/// <param name="asset">CSS-asset</param>
		/// <returns>CSS-asset with minified text content</returns>
		public IAsset Minify(IAsset asset)
		{
			if (asset == null)
			{
				throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "asset");
			}

			if (asset.Minified)
			{
				return asset;
			}

			using (var cssOptimizer = new CssOptimizer(_createJsEngineInstance))
			{
				InnerMinify(asset, cssOptimizer, DisableRestructuring);
			}

			return asset;
		}
		private void InnerMinify(IAsset asset, CssOptimizer cssOptimizer, bool disableRestructuring)
		{
			string newContent;
			string assetUrl = asset.Url;

			try
			{
				newContent = cssOptimizer.Optimize(asset.Content, assetUrl, disableRestructuring);
			}
			catch (CssOptimizingException e)
			{
				throw new AssetMinificationException(
					string.Format(CoreStrings.Minifiers_MinificationSyntaxError,
						CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message));
			}
			catch (Exception e)
			{
				throw new AssetMinificationException(
					string.Format(CoreStrings.Minifiers_MinificationFailed,
						CODE_TYPE, assetUrl, MINIFIER_NAME, e.Message), e);
			}

			asset.Content = newContent;
			asset.Minified = true;
		}
		/// <summary>
		/// Produces a code minifiction of CSS-assets by using Sergey Kryzhanovsky's CSSO (CSS Optimizer)
		/// </summary>
		/// <param name="assets">Set of CSS-assets</param>
		/// <returns>Set of CSS-assets with minified text content</returns>
		public IList<IAsset> Minify(IList<IAsset> assets)
		{
			if (assets == null)
			{
				throw new ArgumentException(CoreStrings.Common_ValueIsEmpty, "assets");
			}

			if (assets.Count == 0)
			{
				return assets;
			}

			var assetsToProcessing = assets.Where(a => a.IsStylesheet && !a.Minified).ToList();
			if (assetsToProcessing.Count == 0)
			{
				return assets;
			}

			bool disableRestructuring = DisableRestructuring;

			using (var cssOptimizer = new CssOptimizer(_createJsEngineInstance))
			{
				foreach (var asset in assetsToProcessing)
				{
					InnerMinify(asset, cssOptimizer, disableRestructuring);
				}
			}

			return assets;
		}