public CssManager(SettingManager sm) { _sm = sm; _cim = new CssImageManager(sm); }
public CssImageManager(SettingManager sm) { _sm = sm; }
public JavaScriptManager(SettingManager sm) { _sm = sm; }
public void Release(SettingManager sm) { // to xhtml System.IO.StreamReader sr = new System.IO.StreamReader(sm.PageName); string xhtml = Html2XHtml(sr.ReadToEnd()); sr.Close(); // parse xhtml XmlReaderSettings xrs = new XmlReaderSettings(); xrs.XmlResolver = new XHTMLResolver(); xrs.ProhibitDtd = false; if (sm.IsHtmlCompress) { xrs.IgnoreComments = true; xrs.IgnoreProcessingInstructions = true; xrs.IgnoreWhitespace = true; } XDocument doc = XDocument.Load(XmlReader.Create(new System.IO.StringReader(xhtml), xrs), LoadOptions.None ); // UriResolver SourceUriResolver = new UriResolver( sm.PageName, false ); UriResolver TargetUriResolver = new UriResolver(sm.OutputPath, true); // init js manager JavaScriptManager jsm = new JavaScriptManager( sm ); var js = from s in doc.Descendants() where string.Compare( s.Name.LocalName, "script", true ) == 0 && string.Compare( s.Attribute("type").Value, "text/javascript", true ) == 0 && s.Attribute("src") != null select s; foreach ( XElement xe in js ) jsm.Add(xe, SourceUriResolver, TargetUriResolver); jsm.JSMin(); // init css manager CssManager cm = new CssManager(sm); var css = from s in doc.Descendants() where string.Compare( s.Name.LocalName, "link", true ) == 0 && string.Compare( s.Attribute("type").Value, "text/css", true ) == 0 && string.Compare( s.Attribute("rel").Value, "stylesheet", true ) == 0 && s.Attribute("href") != null select s; foreach (XElement xe in css) cm.Add(xe, SourceUriResolver, TargetUriResolver); cm.CssMin(); // init image manager // save html if ( !sm.IsHtmlCompress ) doc.Save(TargetUriResolver.ToAbsolute( "index.html" ) ); else { var nodes = from s in doc.DescendantNodes() where s.NodeType == XmlNodeType.Comment && string.Compare( s.Parent.Name.LocalName, "script", true ) != 0 select s; nodes.Remove(); doc.Save( TargetUriResolver.ToAbsolute("index.html"), SaveOptions.DisableFormatting ); } }