public override string MinifyFile(Stream fileStream, ClientDependencyType type) { Func <Stream, string> streamToString = stream => { if (!stream.CanRead) { throw new InvalidOperationException("Cannot read input stream"); } if (stream.CanSeek) { stream.Position = 0; } var reader = new StreamReader(stream); return(reader.ReadToEnd()); }; switch (type) { case ClientDependencyType.Css: return(this.MinifyCss ? CssHelper.MinifyCss(fileStream) : streamToString(fileStream)); case ClientDependencyType.Javascript: return(this.MinifyJs ? JSMin.CompressJS(fileStream) : streamToString(fileStream)); default: return(streamToString(fileStream)); } }
public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request) { if (request.Url.LastPathSegment != null) { if (request.Url.LastPathSegment.EndsWith("s")) { if (request.Url.LastPathSegment.EndsWith("common.css")) { return(CssHelper.GetCssResponse(CssHelper.CommonCssSettings)); } } if (request.Url.LastPathSegment.EndsWith(@"t/")) { if (request.Url.ToString() == @"https://www.bitchute.com/accounts/logout/") { if (request.Method == "GET") { if (OnLogout == null) { OnLogout += RunOnLogout; OnLogout += RunPostAuthEvent.OnPostLogout; } OnLogout.Invoke(new LogoutEventArgs()); AppState.UserIsLoggedIn = false; } } } } return(base.ShouldInterceptRequest(view, request)); }
public override string MinifyFile(string fileContents, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(this.MinifyCss ? CssHelper.MinifyCss(fileContents) : fileContents); case ClientDependencyType.Javascript: { if (!this.MinifyJs) { return(fileContents); } using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) { writer.Write(fileContents); writer.Flush(); return(JSMin.CompressJS(ms)); } } default: return(fileContents); } }
public BvgGridTransferableState(BvgGrid <TItem> bvgGrid, bool SaveColumns = true) { ContaintState = true; HasMeasuredRect = bvgGrid.HasMeasuredRect; if (bvgGrid.HasMeasuredRect) { bvgSize = bvgGrid.bvgSize; } if (SaveColumns) { ColumnsOrderedList = bvgGrid.ColumnsOrderedList; ColumnsOrderedListFrozen = bvgGrid.ColumnsOrderedListFrozen; ColumnsOrderedListNonFrozen = bvgGrid.ColumnsOrderedListNonFrozen; } cssHelper = bvgGrid.cssHelper; if (bvgGrid.HorizontalScroll.compBlazorScrollbar != null) { compBlazorScrollbarHorizontal = bvgGrid.HorizontalScroll.compBlazorScrollbar; } if (bvgGrid.VerticalScroll.compBlazorScrollbar != null) { compBlazorScrollbarVerical = bvgGrid.VerticalScroll.compBlazorScrollbar; } }
public void Ensure_Non_Temp_Search_Strings_Are_Resolved_From_Stream() { var css = @"@font-face{ font-family:'Open Sans'; font-style:normal; font-weight:400; src:url('../fonts/opensans/OpenSans-Regular-webfont.eot'); src:local('Open Sans'), local('OpenSans'), url('../fonts/opensans/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/opensans/OpenSans-Regular-webfont.ttf') format('truetype'), url('../fonts/opensans/OpenSans-Regular-webfont.svg#open_sansregular') format('svg')}" ; using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) { writer.Write(css); writer.Flush(); string externalImports; IEnumerable <string> importPaths; CssHelper.ParseImportStatements(ms, out importPaths, out externalImports); Assert.AreEqual("", externalImports); } }
private static void WriteContentToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo inputFile, Stream stream, ClientDependencyType type, HttpContextBase context, string originalUrl) { if (type == ClientDependencyType.Css) { IEnumerable <string> importedPaths; string externalImports; CssHelper.ParseImportStatements(stream, out importedPaths, out externalImports); //we can write the external imports found at the top sw.WriteLine(externalImports); //need to write the imported sheets first since these theoretically should *always* be at the top for browser to support them foreach (var importPath in importedPaths) { var uri = new Uri(originalUrl, UriKind.RelativeOrAbsolute) .MakeAbsoluteUri(context); var absolute = uri.ToAbsolutePath(importPath); provider.WritePathToStream(ClientDependencyType.Css, absolute, context, sw); } var minified = GetMinifiedOutput(provider, type, inputFile, stream); //ensure the Urls in the css are changed to absolute var parsedUrls = CssHelper.ReplaceUrlsWithAbsolutePaths(minified, originalUrl, context); //then we write the css with the removed import statements sw.WriteLine(parsedUrls); } else { sw.WriteLine(GetMinifiedOutput(provider, type, inputFile, stream)); } }
public void Can_Parse_Import_Statements_From_Stream() { var css = @"@import url('/css/typography.css'); @import url('/css/layout.css'); @import url('http://mysite/css/color.css'); @import url(/css/blah.css); body { color: black; } div {display: block;}"; using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) { writer.Write(css); writer.Flush(); IEnumerable <string> importPaths; string externalImports; var position = CssHelper.ParseImportStatements(ms, out importPaths, out externalImports); Assert.AreEqual(@"@import url('http://mysite/css/color.css');", externalImports); Assert.AreEqual(3, importPaths.Count()); Assert.AreEqual("/css/typography.css", importPaths.ElementAt(0)); Assert.AreEqual("/css/layout.css", importPaths.ElementAt(1)); //Assert.AreEqual("http://mysite/css/color.css", importPaths.ElementAt(2)); Assert.AreEqual("/css/blah.css", importPaths.ElementAt(2)); } }
public string Styles(string styleLibraryName, bool outputDefaults = false) { // LR: Load the style library Dictionary <string, string> styleLibrary = this.StyleLibraries.GetStyleLibrary(styleLibraryName); if (!outputDefaults) { return(InlineCss(styleLibrary)); } // LR: Default CSS Component Properties Dictionary <string, string> defaultStyles = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> attribute in Attributes) { if (string.IsNullOrWhiteSpace(attribute.Value)) { continue; } if (!CssHelper.IsCssProperty(attribute.Key)) { // Console.WriteLine($"[IsCssProperty] => Omitted {attribute.Key} as it's not a CssProperty"); continue; } defaultStyles.Add(attribute.Key, attribute.Value); } // LR: Merge style library into default styles. // CAUTION: This will include unessary properties to be outputted to CSS. return(InlineCss(defaultStyles.MergeLeft(styleLibrary))); }
public void Can_Parse_Import_Statements() { var css = @"@import url('/css/typography.css'); @import url('/css/layout.css'); @import url('http://mysite/css/color.css'); @import url(/css/blah.css); body { color: black; } div {display: block;}"; IEnumerable <string> importPaths; var output = CssHelper.ParseImportStatements(css, out importPaths); Assert.AreEqual(@"@import url('http://mysite/css/color.css'); body { color: black; } div {display: block;}", output); Assert.AreEqual(3, importPaths.Count()); Assert.AreEqual("/css/typography.css", importPaths.ElementAt(0)); Assert.AreEqual("/css/layout.css", importPaths.ElementAt(1)); //Assert.AreEqual("http://mysite/css/color.css", importPaths.ElementAt(2)); Assert.AreEqual("/css/blah.css", importPaths.ElementAt(2)); }
protected override string Render() { var wrapper = new TagBuilder("div"); // Id wrapper.GenerateId(Id); // HTML Attributes wrapper.MergeAttributes(HtmlAttributes); // Class wrapper.AddCssClass("alert"); wrapper.MergeAttribute("role", "alert"); wrapper.AddCssClass(CssHelper <AlertControl> .ConvertToCss(BackgroundColor)); // Inner Html wrapper.InnerHtml = _textOrHtml; // Close button if (HasCloseBtn) { wrapper.InnerHtml += RenderCloseButton(); } return(wrapper.ToString()); }
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } // get rendered HTML from view string html = ViewRenderer.RenderViewToString(context, ViewName, Model); var cssFiles = CssHelper.GetAllCssPaths(html); //html = ClearHtmlStrategy.Clear(html); // generate the PDF content from HTML var pageConfig = PageConfig != null ? PageConfig : PageSize.A4; byte[] content = HtmlToPdfRenderer.Render(html, cssFiles, pageConfig); var contentDisposition = IsAttachment ? "attachement" : "inline"; HttpResponseBase response = context.HttpContext.Response; response.Clear(); response.ClearContent(); response.ClearHeaders(); response.ContentType = "application/pdf"; response.AppendHeader("Content-Disposition", $"{contentDisposition};filename={Filename}.pdf"); response.AddHeader("Content-Length", content.Length.ToString()); response.BinaryWrite(content); response.OutputStream.Flush(); response.OutputStream.Close(); response.End(); }
/// <summary> /// Writes the actual contents of a file or request result to the stream and ensures the contents are minified if necessary /// </summary> /// <param name="provider"></param> /// <param name="sw"></param> /// <param name="content"></param> /// <param name="type"></param> /// <param name="context"></param> /// <param name="originalUrl">The original Url that the content is related to</param> internal static void WriteContentToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, string content, ClientDependencyType type, HttpContextBase context, string originalUrl) { if (type == ClientDependencyType.Css) { IEnumerable <string> importedPaths; var removedImports = CssHelper.ParseImportStatements(content, out importedPaths); //need to write the imported sheets first since these theoretically should *always* be at the top for browser to support them foreach (var importPath in importedPaths) { var uri = new Uri(originalUrl, UriKind.RelativeOrAbsolute) .MakeAbsoluteUri(context); var absolute = uri.ToAbsolutePath(importPath); provider.WritePathToStream(ClientDependencyType.Css, absolute, context, sw); } //ensure the Urls in the css are changed to absolute var parsedUrls = CssHelper.ReplaceUrlsWithAbsolutePaths(removedImports, originalUrl, context); //then we write the css with the removed import statements sw.WriteLine(provider.MinifyFile(parsedUrls, ClientDependencyType.Css)); } else { sw.WriteLine(provider.MinifyFile(content, type)); } }
// https://github.com/mjmlio/mjml/blob/master/packages/mjml-section/src/index.js#L221 /// <summary> /// RenderWrappedChildren /// </summary> /// <returns></returns> public override string RenderChildren() { if (!this.Children.Any()) { return(string.Empty); } StringBuilder sb = new StringBuilder(); sb.Append(@" <!--[if mso | IE]> <tr> <![endif]-->"); foreach (var childComponent in Children) { string childContent = childComponent.RenderMjml(); if (string.IsNullOrWhiteSpace(childContent)) { continue; } if (childComponent.IsRawElement()) { sb.Append(childContent); } else { sb.Append($@" <!--[if mso | IE]> <td {HtmlAttributes(new Dictionary<string, string> { {"align", GetAttribute("align") }, {"class", CssHelper.SuffixCssClasses(GetAttribute("css-class"), "outlook") }, {"style", (childComponent as BodyComponent).Styles("tdOutlook") } })} > <![endif]--> "); sb.Append(childContent); sb.Append($@" <!--[if mso | IE]> </td> <![endif]--> "); } } sb.Append($@" <!--[if mso | IE]> </tr> <![endif]--> "); return(sb.ToString()); }
/// <summary> /// This ensures that all paths (i.e. images) in a CSS file have their paths change to absolute paths. /// </summary> /// <param name="fileContents"></param> /// <param name="type"></param> /// <param name="url"></param> /// <param name="http"></param> /// <returns></returns> protected virtual string ParseCssFilePaths(string fileContents, ClientDependencyType type, string url, HttpContextBase http) { //if it is a CSS file we need to parse the URLs if (type == ClientDependencyType.Css) { fileContents = CssHelper.ReplaceUrlsWithAbsolutePaths(fileContents, url, http); } return(fileContents); }
public void Retain_External_Imports() { var cssWithImport = @"@import url(""//fonts.googleapis.com/css?subset=latin,cyrillic-ext,latin-ext,cyrillic&family=Open+Sans+Condensed:300|Open+Sans:400,600,400italic,600italic|Merriweather:400,300,300italic,400italic,700,700italic|Roboto+Slab:400,300""); @import url(""//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"");"; IEnumerable <string> importPaths; var output = CssHelper.ParseImportStatements(cssWithImport, out importPaths); Assert.AreEqual(cssWithImport, output); }
protected override string Render() { // Create tag builder TagBuilder builder1 = new TagBuilder("div"); TagBuilder builder2 = new TagBuilder("div"); TagBuilder builder3 = new TagBuilder("div"); TagBuilder builder4 = new TagBuilder("div"); TagBuilder builder5 = new TagBuilder("div"); TagBuilder builder6 = new TagBuilder("div"); // HTML Attributes builder1.MergeAttributes(HtmlAttributes); builder1.GenerateId(Id); builder1.AddCssClass("modal"); builder1.AddCssClass("fade"); builder1.MergeAttribute("role", "dialog"); builder2.AddCssClass("modal-dialog"); builder2.AddCssClass(CssHelper <ModalControl> .ConvertToCss(Size)); builder3.AddCssClass("modal-content"); builder4.AddCssClass("modal-header"); TagBuilder buiderTitle = new TagBuilder("h4"); buiderTitle.AddCssClass("modal-title"); buiderTitle.SetInnerText(_title); TagBuilder buiderCloseBtn = new TagBuilder("button"); buiderCloseBtn.AddCssClass("close"); buiderCloseBtn.SetInnerText("×"); buiderCloseBtn.MergeAttribute("data-dismiss", "modal"); builder4.InnerHtml = buiderTitle.ToString() + buiderCloseBtn; builder5.AddCssClass("modal-body"); builder5.GenerateId(BodyId); builder5.InnerHtml = BodyInnerHtml; if (FooterInnerHtml != null) { builder6.AddCssClass("modal-footer"); builder6.InnerHtml = FooterInnerHtml; } // Wrap builder3.InnerHtml = builder4.ToString() + builder5 + builder6; builder2.InnerHtml = builder3.ToString(); builder1.InnerHtml = builder2.ToString(); return(builder1.ToString()); }
public override string[] GetCustomStyles(HtmlHelper html) { if (Content.UseCustomCss && !string.IsNullOrWhiteSpace(Content.CustomCss)) { var css = CssHelper.FixCss(Content.CustomCss); if (!string.IsNullOrWhiteSpace(css)) { return(new[] { css }); } } return(null); }
/// <summary> /// Minifies the file /// </summary> /// <param name="fileContents"></param> /// <param name="type"></param> /// <returns></returns> public virtual string MinifyFile(string fileContents, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(EnableCssMinify ? CssHelper.MinifyCss(fileContents) : fileContents); case ClientDependencyType.Javascript: return(EnableJsMinify ? JSMin.CompressJS(fileContents) : fileContents); default: return(fileContents); } }
public override string MinifyFile(string fileContents, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(MinifyCss ? CssHelper.MinifyCss(fileContents) : fileContents); case ClientDependencyType.Javascript: return(MinifyJs ? JSMin.CompressJS(fileContents) : fileContents); default: return(fileContents); } }
public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request) { if (request.Url.LastPathSegment != null) { if (request.Url.LastPathSegment.EndsWith("s")) { if (request.Url.LastPathSegment.EndsWith("common.css")) { return(CssHelper.GetCssResponse(CssHelper.CommonCssMyChannel)); } } } return(base.ShouldInterceptRequest(view, request)); }
/// <summary> /// Minifies the file /// </summary> /// <param name="fileStream"></param> /// <param name="type"></param> /// <returns></returns> public virtual string MinifyFile(Stream fileStream, ClientDependencyType type) { switch (type) { case ClientDependencyType.Css: return(EnableCssMinify ? CssHelper.MinifyCss(fileStream) : StreamToString(fileStream)); case ClientDependencyType.Javascript: return(EnableJsMinify ? JSMin.CompressJS(fileStream) : StreamToString(fileStream)); default: return(StreamToString(fileStream)); } }
protected void Page_Load(object sender, EventArgs e) { // Validate query string if (!QueryHelper.ValidateHash("hash", "containerid")) { fileUploaderElem.StopProcessing = true; } else { // Ensure additional styles CurrentMaster.HeadElements.Visible = true; CurrentMaster.HeadElements.Text += CssHelper.GetStyle("*{direction:ltr !important;}body{background:transparent !important;}input,input:focus,input:hover,input:active{border:none;border-color:transparent;outline:none;}"); // Initialize uploader control properties by query string values fileUploaderElem.ImageWidth = 16; fileUploaderElem.ImageHeight = 18; fileUploaderElem.ImageUrl = "~/CMSAdminControls/CKeditor/plugins/CMSPlugins/images/QuicklyInsertImage.gif"; fileUploaderElem.Text = HTMLHelper.EncodeForHtmlAttribute(QueryHelper.GetString("innerdivhtml", String.Empty)); fileUploaderElem.InnerElementClass = QueryHelper.GetText("innerdivclass", String.Empty); fileUploaderElem.AdditionalStyle = QueryHelper.GetText("additionalstyle", String.Empty); fileUploaderElem.LoadingImageUrl = GetImageUrl("Design/Preloaders/preload16.gif"); fileUploaderElem.FormGUID = QueryHelper.GetGuid("formguid", Guid.Empty); fileUploaderElem.NodeParentNodeID = QueryHelper.GetInteger("parentid", 0); fileUploaderElem.DocumentID = QueryHelper.GetInteger("documentid", 0); fileUploaderElem.SourceType = MediaSourceEnum.DocumentAttachments; string siteName = SiteContext.CurrentSiteName; string allowed = QueryHelper.GetString("allowedextensions", String.Empty); if (String.IsNullOrEmpty(allowed)) { allowed = SettingsKeyInfoProvider.GetValue(siteName + ".CMSUploadExtensions"); } fileUploaderElem.AllowedExtensions = allowed; fileUploaderElem.ResizeToWidth = QueryHelper.GetInteger("autoresize_width", 0); fileUploaderElem.ResizeToHeight = QueryHelper.GetInteger("autoresize_height", 0); fileUploaderElem.ResizeToMaxSideSize = QueryHelper.GetInteger("autoresize_maxsidesize", 0); fileUploaderElem.AfterSaveJavascript = "InsertImageOrMedia"; fileUploaderElem.InsertMode = true; fileUploaderElem.IsLiveSite = false; fileUploaderElem.FileUploadControl.Attributes["title"] = HTMLHelper.EncodeForHtmlAttribute(GetString("wysiwyg.ui.quicklyinsertimage")); ScriptHelper.RegisterStartupScript(this, typeof(String), "DirectFileUpload_" + ClientID, "window.uploaderFocused = false;", true); } }
protected void Page_Init(object sender, EventArgs e) { ScriptHelper.RegisterTooltip(this); RegisterAngularModule(); ScriptHelper.RegisterDialogScript(this); CssRegistration.RegisterCssLink(this, "~/CMSScripts/jquery/jqueryui/jquery-ui.css"); if (SiteContext.CurrentSite.SiteIsContentOnly && SitePresentationUri == null) { ShowError(GetString("campaign.incorrectPresentationUrl")); MessagesPlaceHolder.ContainerCssClass = CssHelper.EnsureClass(MessagesPlaceHolder.ContainerCssClass, "cms-campaigns-edit"); } }
protected override string Render() { // Label TagBuilder label = new TagBuilder("label"); label.MergeAttribute("for", Id); // HtmlAttributes label.MergeAttributes(HtmlAttributes); // Style: SetColor label.AddCssClass(CssHelper <LabelControl> .ConvertToCss(BackgroundColor)); return(label.ToString()); }
protected override string Render() { // CSS: SetColor & SetSize this.AddCssClass(CssHelper <ButtonControl> .ControlTypeAbbr); this.AddCssClass(CssHelper <ButtonControl> .ConvertToCss(BackgroundColor)); this.AddCssClass(CssHelper <ButtonControl> .ConvertToCss(Size)); this.AddCssClass(ConstantHelper.CssDropDownList); // Route values RouteValues = HtmlHelperExtension.AddRouteValue(RouteValues, new { area = _areaName }); String actionLinkStr = _htmlHelper.ActionLink(Text, _actionName, _controllerName, RouteValues, HtmlAttributes).ToString(); return(actionLinkStr); }
/// <summary> /// Whether the tree node matches the filter /// </summary> /// <param name="node">The tree node of type T</param> /// <returns> /// true, if the node matches, otherwise false /// </returns> protected override bool AcceptNode(HtmlElement element) { bool hidden = false; string displayValue = element.GetStyle(Css.Properties.DISPLAY); bool isDisplayNone = CssHelper.IsDisplayNone(displayValue); bool displayNoneIsDefaultValue = _defaultStyleLookup.IsDefaultValue(element.TagName, Css.Properties.DISPLAY, Css.Values.DISPLAY_NONE); if (isDisplayNone && !displayNoneIsDefaultValue) { hidden = true; } return(hidden); }
public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request) { if (request.Url.LastPathSegment != null) { if (request.Url.LastPathSegment.EndsWith("s")) //|| request.Url.Path.EndsWith(@"/bootstrap.min.css")) { if (request.Url.Path.EndsWith(@"/video.css")) { return(CssHelper.GetCssResponse(CssHelper.VideoCss)); } //else if (CssHelper.BootstrapCss != "") { return CssHelper.GetCssResponse(CssHelper.BootstrapCss); } } } return(base.ShouldInterceptRequest(view, request)); }
public override string RenderMjml() { return($@" {TagHelpers.ConditionalTag($@" <td {HtmlAttributes(new Dictionary<string, string> { { "style", "td" }, { "class", CssHelper.SuffixCssClasses(GetAttribute("css-class"), "outlook") } })}> ")} {RenderContent()} {TagHelpers.ConditionalTag($@" </td> ")} "); }
protected string GetStyleSheetLink(string url, bool prefixWithImagePath, string prefix, string cacheInvalidationSuffix) { string realUrl = url; if (!realUrl.IsEmpty()) { // i370377 - checks if the theme is external it don't need the local prefix if (realUrl.StartsWith("/") || realUrl.StartsWith("http://") || realUrl.StartsWith("https://")) { prefixWithImagePath = false; } if (prefixWithImagePath) { realUrl = prefix + realUrl; } return(" " + CssHelper.GetCssInclude(realUrl + cacheInvalidationSuffix)); } return(null); }
public void Retain_External_Imports_From_Stream() { var cssWithImport = @"@import url(""//fonts.googleapis.com/css?subset=latin,cyrillic-ext,latin-ext,cyrillic&family=Open+Sans+Condensed:300|Open+Sans:400,600,400italic,600italic|Merriweather:400,300,300italic,400italic,700,700italic|Roboto+Slab:400,300""); @import url(""//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"");"; using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) { writer.Write(cssWithImport); writer.Flush(); string externalImports; IEnumerable <string> importPaths; var position = CssHelper.ParseImportStatements(ms, out importPaths, out externalImports); Assert.AreEqual(ms.Length, position); Assert.AreEqual(cssWithImport, externalImports); } }