Skip to content

Commit

Permalink
added support for print type raw-html (#8)
Browse files Browse the repository at this point in the history
* added support for print type raw-html

* Added comments and changed visibility

* formatting

* Update Version to 6.1.0

Added HTMLRAW

---------

Co-authored-by: Benjamin Vertonghen <[email protected]>
  • Loading branch information
Jimmys20 and vertonghenb authored Jan 30, 2023
1 parent f3018f3 commit f599095
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
20 changes: 20 additions & 0 deletions samples/Append.Blazor.Printing.Wasm/Examples/RawHtml.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@inject IPrintingService PrintingService
<Example Name="@this.GetType().Name">
<Documentation>
<h3>Raw HTML</h3>
<p>Print raw HTML.</p>
</Documentation>
<Code>
@{
string rawHtml = String.Join(
Environment.NewLine,
"<h1>Print.js Raw HTML Print Test</h1>",
"<p style=\"color: blue;\">Lorem ipsum dolor sit amet, consectetur adipiscing elit,</p>",
"<p>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>");
}

<button @onclick="@(_ => PrintingService.Print(rawHtml, PrintType.RawHtml))">
Print Raw Html
</button>
</Code>
</Example>
4 changes: 3 additions & 1 deletion samples/Append.Blazor.Printing.Wasm/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
<hr />
<Append.Blazor.Printing.Documentation.Examples.Base64 />
<hr />
<Append.Blazor.Printing.Documentation.Examples.Html />
<Append.Blazor.Printing.Documentation.Examples.Html />
<hr />
<Append.Blazor.Printing.Documentation.Examples.RawHtml />
20 changes: 20 additions & 0 deletions samples/Append.Blazor.Printing.Wasm/wwwroot/examples/RawHtml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@inject IPrintingService PrintingService
<Example Name="@this.GetType().Name">
<Documentation>
<h3>Raw HTML</h3>
<p>Print raw HTML.</p>
</Documentation>
<Code>
@{
string rawHtml = String.Join(
Environment.NewLine,
"<h1>Print.js Raw HTML Print Test</h1>",
"<p style=\"color: blue;\">Lorem ipsum dolor sit amet, consectetur adipiscing elit,</p>",
"<p>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>");
}

<button @onclick="@(_ => PrintingService.Print(rawHtml, PrintType.RawHtml))">
Print Raw Html
</button>
</Code>
</Example>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>6.0.0</Version>
<Version>6.1.0</Version>
<Authors>Benjamin Vertonghen</Authors>
<Company>Append</Company>
<Description>Print and Save files in Blazor using the native dialog box using JavaScript Interop.</Description>
Expand Down
2 changes: 1 addition & 1 deletion source/Append.Blazor.Printing/PrintOptionsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal record PrintOptionsAdapter
public PrintOptionsAdapter(PrintOptions options)
{
Printable = options.Printable;
Type = Enum.GetName(typeof(PrintType), options.Type).ToLower();
Type = options.Type.ToPrintJsString();
ShowModal = options.ShowModal;
ModalMessage = options.ModalMessage;
Base64 = options.Base64 == true ? true : null;
Expand Down
3 changes: 2 additions & 1 deletion source/Append.Blazor.Printing/PrintType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum PrintType
Pdf,
Html,
Image,
Json
Json,
RawHtml
}
}
19 changes: 19 additions & 0 deletions source/Append.Blazor.Printing/PrintTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Append.Blazor.Printing
{
internal static class PrintTypeExtensions
{
/// <summary>
/// Adapts the <see cref="PrintType"/> to the JavaScript version.
/// </summary>
public static string ToPrintJsString(this PrintType printType)
{
return printType switch
{
PrintType.RawHtml => "raw-html",
_ => Enum.GetName(typeof(PrintType), printType).ToLower(),
};
}
}
}

0 comments on commit f599095

Please sign in to comment.