Exemplo n.º 1
0
        public JsMinifyTransform(IJsMinifier minifier)
        {
            if (minifier == null)
            {
                throw new ArgumentNullException(nameof(minifier));
            }

            _minifier = minifier;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a instance of HTML minifier
        /// </summary>
        /// <returns>Instance of HTML minifier</returns>
        public override IMarkupMinifier CreateMinifier()
        {
            HtmlMinificationSettings settings    = MinificationSettings;
            ICssMinifier             cssMinifier = CssMinifierFactory.CreateMinifier();
            IJsMinifier jsMinifier = JsMinifierFactory.CreateMinifier();

            var minifier = new HtmlMinifier(settings, cssMinifier, jsMinifier, _logger);

            return(minifier);
        }
 public ResourceProcessor(IResourceCacher resourceCacher, IResourceReaderManager resourceReader, ICompressionFactory compressionFactory, IResourceHasher resourceHasher, IJsMinifier jsMinifier, ICssMinifier cssMinifier, IVirtualPathProvider virtualPathProvider)
 {
     m_ResourceCacher = resourceCacher;
     m_ResourceReader = resourceReader;
     m_CompressionFactory = compressionFactory;
     m_ResourceHasher = resourceHasher;
     m_JsMinifier = jsMinifier;
     m_CssMinifier = cssMinifier;
     m_VirtualPathProvider = virtualPathProvider;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a instance of XHTML minifier based on the settings
        /// that specified in configuration files (App.config or Web.config)
        /// </summary>
        /// <param name="settings">XHTML minification settings</param>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="logger">logger</param>
        /// <returns>XHTML minifier</returns>
        public XhtmlMinifier CreateXhtmlMinifierInstance(XhtmlMinificationSettings settings = null,
                                                         ICssMinifier cssMinifier           = null, IJsMinifier jsMinifier = null, ILogger logger = null)
        {
            XhtmlMinificationSettings innerSettings = settings ?? GetXhtmlMinificationSettings();
            ICssMinifier innerCssMinifier           = cssMinifier ?? _wmmContext.Code.CreateDefaultCssMinifierInstance();
            IJsMinifier  innerJsMinifier            = jsMinifier ?? _wmmContext.Code.CreateDefaultJsMinifierInstance();
            ILogger      innerLogger = logger ?? _wmmContext.GetDefaultLoggerInstance();

            var xhtmlMinifier = new XhtmlMinifier(innerSettings, innerCssMinifier, innerJsMinifier, innerLogger);

            return(xhtmlMinifier);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a instance of default JS minifier based on the settings
        /// that specified in configuration files (App.config or Web.config)
        /// </summary>
        /// <param name="loadSettingsFromConfigurationFile">Flag for whether to allow
        /// loading minifier settings from configuration file</param>
        /// <returns>JS minifier</returns>
        public IJsMinifier CreateDefaultJsMinifierInstance(bool loadSettingsFromConfigurationFile = true)
        {
            string defaultJsMinifierName = _wmmContext.GetCoreConfiguration().Js.DefaultMinifier;

            if (string.IsNullOrWhiteSpace(defaultJsMinifierName))
            {
                throw new ConfigurationErrorsException(
                          string.Format(Strings.Configuration_DefaultCodeMinifierNotSpecified, "JS"));
            }

            IJsMinifier jsMinifier = CreateJsMinifierInstance(defaultJsMinifierName,
                                                              loadSettingsFromConfigurationFile);

            return(jsMinifier);
        }
        public XhtmlMinificationViewModel Minify(XhtmlMinificationViewModel model)
        {
            string cssMinifierName = model.Settings.CssMinifierName;
            string jsMinifierName  = model.Settings.JsMinifierName;

            var          settings    = Mapper.Map <XhtmlMinificationSettings>(model.Settings);
            ICssMinifier cssMinifier = _cssMinifierFactory.CreateMinifier(cssMinifierName);
            IJsMinifier  jsMinifier  = _jsMinifierFactory.CreateMinifier(jsMinifierName);

            var xhtmlMinifier = new XhtmlMinifier(settings, cssMinifier, jsMinifier);
            var result        = xhtmlMinifier.Minify(model.SourceCode, true);

            model.Result = Mapper.Map <MarkupMinificationResultViewModel>(result);

            return(model);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructs instance of HTML minifier
        /// </summary>
        /// <param name="settings">HTML minification settings</param>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="logger">Logger</param>
        public HtmlMinifier(HtmlMinificationSettings settings = null, ICssMinifier cssMinifier = null,
                            IJsMinifier jsMinifier            = null, ILogger logger = null)
        {
            settings = settings ?? new HtmlMinificationSettings();

            _genericHtmlMinifier = new GenericHtmlMinifier(
                new GenericHtmlMinificationSettings
            {
                WhitespaceMinificationMode              = settings.WhitespaceMinificationMode,
                RemoveHtmlComments                      = settings.RemoveHtmlComments,
                RemoveHtmlCommentsFromScriptsAndStyles  = settings.RemoveHtmlCommentsFromScriptsAndStyles,
                RemoveCdataSectionsFromScriptsAndStyles = settings.RemoveCdataSectionsFromScriptsAndStyles,
                UseShortDoctype                   = settings.UseShortDoctype,
                CustomShortDoctype                = settings.CustomShortDoctype,
                PreserveCase                      = settings.PreserveCase,
                UseMetaCharsetTag                 = settings.UseMetaCharsetTag,
                EmptyTagRenderMode                = settings.EmptyTagRenderMode,
                RemoveOptionalEndTags             = settings.RemoveOptionalEndTags,
                PreservableOptionalTagList        = settings.PreservableOptionalTagList,
                RemoveTagsWithoutContent          = settings.RemoveTagsWithoutContent,
                CollapseBooleanAttributes         = settings.CollapseBooleanAttributes,
                AttributeQuotesRemovalMode        = settings.AttributeQuotesRemovalMode,
                RemoveEmptyAttributes             = settings.RemoveEmptyAttributes,
                RemoveRedundantAttributes         = settings.RemoveRedundantAttributes,
                RemoveJsTypeAttributes            = settings.RemoveJsTypeAttributes,
                RemoveCssTypeAttributes           = settings.RemoveCssTypeAttributes,
                PreservableAttributeList          = settings.PreservableAttributeList,
                RemoveHttpProtocolFromAttributes  = settings.RemoveHttpProtocolFromAttributes,
                RemoveHttpsProtocolFromAttributes = settings.RemoveHttpsProtocolFromAttributes,
                RemoveJsProtocolFromAttributes    = settings.RemoveJsProtocolFromAttributes,
                MinifyEmbeddedCssCode             = settings.MinifyEmbeddedCssCode,
                MinifyInlineCssCode               = settings.MinifyInlineCssCode,
                MinifyEmbeddedJsCode              = settings.MinifyEmbeddedJsCode,
                MinifyInlineJsCode                = settings.MinifyInlineJsCode,
                MinifyEmbeddedJsonData            = settings.MinifyEmbeddedJsonData,
                ProcessableScriptTypeList         = settings.ProcessableScriptTypeList,
                MinifyKnockoutBindingExpressions  = settings.MinifyKnockoutBindingExpressions,
                MinifyAngularBindingExpressions   = settings.MinifyAngularBindingExpressions,
                CustomAngularDirectiveList        = settings.CustomAngularDirectiveList,
                UseXhtmlSyntax                    = false
            },
                cssMinifier,
                jsMinifier,
                logger
                );
        }
        static ResourceManagerRuntime()
        {
            s_VirtualPathResolverManager = new VirtualPathResolverManager(() => new HttpContextVirtualPathResolver(), () => new WindowsVirtualPathResolver());
            s_CacheProvider = new SystemRuntimeCacheProvider();
            s_CompressionFactory = new CompressionFactory();
            s_ResourceHasher = new Md5ResourceHasher();
            s_CssMinifier = new YahooCssMinifier();
            s_JsMinifier = new YahooJsMinifier();
            s_DebugStatusReader = new HttpContextDebugStatusReader();
            s_DateTimeProvider = new DefaultDateTimeProvider();
            s_HttpResponseCacher = new HttpResponseCacher(s_DateTimeProvider);
            s_HttpResponseCompressor = new HttpResponseCompressor();
            s_RemoteFileTempFolderProvider = new WindowsTempPathRemoteFileTempFolderProvider();
            s_VirtualPathProvider = new VirtualPathProvider();
            s_HtmlMinifier = new SimpleHtmlMinifier();

            UpdateDependentObjects();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructs instance of HTML minifier
        /// </summary>
        /// <param name="settings">HTML minification settings</param>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="logger">Logger</param>
        public HtmlMinifier(HtmlMinificationSettings settings = null, ICssMinifier cssMinifier = null,
			IJsMinifier jsMinifier = null, ILogger logger = null)
        {
            settings = settings ?? new HtmlMinificationSettings();

            _genericHtmlMinifier = new GenericHtmlMinifier(
                new GenericHtmlMinificationSettings
                    {
                        WhitespaceMinificationMode = settings.WhitespaceMinificationMode,
                        RemoveHtmlComments = settings.RemoveHtmlComments,
                        RemoveHtmlCommentsFromScriptsAndStyles = settings.RemoveHtmlCommentsFromScriptsAndStyles,
                        RemoveCdataSectionsFromScriptsAndStyles = settings.RemoveCdataSectionsFromScriptsAndStyles,
                        UseShortDoctype = settings.UseShortDoctype,
                        PreserveCase = settings.PreserveCase,
                        UseMetaCharsetTag = settings.UseMetaCharsetTag,
                        EmptyTagRenderMode = settings.EmptyTagRenderMode,
                        RemoveOptionalEndTags = settings.RemoveOptionalEndTags,
                        PreservableOptionalTagList = settings.PreservableOptionalTagList,
                        RemoveTagsWithoutContent = settings.RemoveTagsWithoutContent,
                        CollapseBooleanAttributes = settings.CollapseBooleanAttributes,
                        AttributeQuotesRemovalMode = settings.AttributeQuotesRemovalMode,
                        RemoveEmptyAttributes = settings.RemoveEmptyAttributes,
                        RemoveRedundantAttributes = settings.RemoveRedundantAttributes,
                        RemoveJsTypeAttributes = settings.RemoveJsTypeAttributes,
                        RemoveCssTypeAttributes = settings.RemoveCssTypeAttributes,
                        PreservableAttributeList = settings.PreservableAttributeList,
                        RemoveHttpProtocolFromAttributes = settings.RemoveHttpProtocolFromAttributes,
                        RemoveHttpsProtocolFromAttributes = settings.RemoveHttpsProtocolFromAttributes,
                        RemoveJsProtocolFromAttributes = settings.RemoveJsProtocolFromAttributes,
                        MinifyEmbeddedCssCode = settings.MinifyEmbeddedCssCode,
                        MinifyInlineCssCode = settings.MinifyInlineCssCode,
                        MinifyEmbeddedJsCode = settings.MinifyEmbeddedJsCode,
                        MinifyInlineJsCode = settings.MinifyInlineJsCode,
                        ProcessableScriptTypeList = settings.ProcessableScriptTypeList,
                        MinifyKnockoutBindingExpressions = settings.MinifyKnockoutBindingExpressions,
                        MinifyAngularBindingExpressions = settings.MinifyAngularBindingExpressions,
                        CustomAngularDirectiveList = settings.CustomAngularDirectiveList,
                        UseXhtmlSyntax = false
                    },
                cssMinifier,
                jsMinifier,
                logger
            );
        }
Exemplo n.º 10
0
 public Helper(IOptions <BundleGlobalOptions> globalOptions, IJsMinifier minifier)
 {
     _globalOptions   = globalOptions.Value;
     _minifyTransform = new JsMinifyTransform(minifier);
 }
 public DefaultInlineJavascriptMinifier(IJsMinifier jsMinifier)
 {
     m_JsMinifier = jsMinifier;
 }
        /// <summary>
        /// Constructs instance of generic HTML minifier
        /// </summary>
        /// <param name="settings">Generic HTML minification settings</param>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="logger">Logger</param>
        public GenericHtmlMinifier(GenericHtmlMinificationSettings settings = null,
			ICssMinifier cssMinifier = null, IJsMinifier jsMinifier = null, ILogger logger = null)
        {
            _settings = settings ?? new GenericHtmlMinificationSettings();
            _logger = logger ?? new NullLogger();
            _cssMinifier = cssMinifier ?? new KristensenCssMinifier();
            _jsMinifier = jsMinifier ?? new CrockfordJsMinifier();
            _htmlParser = new HtmlParser(new HtmlParsingHandlers
            {
                XmlDeclaration = XmlDeclarationHandler,
                Doctype = DoctypeHandler,
                Comment = CommentHandler,
                IfConditionalComment = IfConditionalCommentHandler,
                EndIfConditionalComment = EndIfConditionalCommentHandler,
                StartTag = StartTagHandler,
                EndTag = EndTagHandler,
                Text = TextHandler,
                TemplateTag = TemplateTagHandler
            });

            _processableScriptTypes = new HashSet<string>(_settings.ProcessableScriptTypeCollection);

            IList<string> customAngularDirectivesWithExpressions = _settings.CustomAngularDirectiveCollection.ToList();
            _angularDirectivesWithExpressions = (customAngularDirectivesWithExpressions.Count > 0) ?
                Utils.UnionHashSets(_builtinAngularDirectivesWithExpressions, customAngularDirectivesWithExpressions)
                :
                _builtinAngularDirectivesWithExpressions
                ;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Constructs instance of generic HTML minifier
        /// </summary>
        /// <param name="settings">Generic HTML minification settings</param>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="logger">Logger</param>
        public GenericHtmlMinifier(GenericHtmlMinificationSettings settings = null,
			ICssMinifier cssMinifier = null, IJsMinifier jsMinifier = null, ILogger logger = null)
        {
            _settings = settings ?? new GenericHtmlMinificationSettings();
            _logger = logger ?? new NullLogger();
            _cssMinifier = cssMinifier ?? new KristensenCssMinifier();
            _jsMinifier = jsMinifier ?? new CrockfordJsMinifier();
            _htmlParser = new HtmlParser(new HtmlParsingHandlers
            {
                XmlDeclaration = XmlDeclarationHandler,
                Doctype = DoctypeHandler,
                Comment = CommentHandler,
                IfConditionalComment = IfConditionalCommentHandler,
                EndIfConditionalComment = EndIfConditionalCommentHandler,
                StartTag = StartTagHandler,
                EndTag = EndTagHandler,
                Text = TextHandler,
                EmbeddedCode = EmbeddedCodeHandler,
                TemplateTag = TemplateTagHandler,
                IgnoredFragment = IgnoredFragmentHandler
            });

            _buffer = new List<string>();
            _errors = new List<MinificationErrorInfo>();
            _warnings = new List<MinificationErrorInfo>();
            _tagsWithNotRemovableWhitespaceQueue = new Queue<string>();
            _currentNodeType = HtmlNodeType.Unknown;
            _currentTag = null;
            _currentText = string.Empty;

            ISet<string> customAngularDirectivesWithExpressions = _settings.CustomAngularDirectiveCollection;
            _angularDirectivesWithExpressions = customAngularDirectivesWithExpressions.Count > 0 ?
                Utils.UnionHashSets(_builtinAngularDirectivesWithExpressions, customAngularDirectivesWithExpressions)
                :
                _builtinAngularDirectivesWithExpressions
                ;
        }