Skip to content

Commit 5acd5f8

Browse files
author
Ajay kumar
committed
[Blog] [Ajay]: Add gist component
1 parent b5d1ddd commit 5acd5f8

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@inherits GithubGistSnippetBase
2+
3+
<section class="[ flex flex-col ]">
4+
<h4 class="[ bg-gray-200 ] [ p-2 ] [ font-semibold ] [ text-black ] [ flex items-center ]">
5+
<svg xmlns="http://www.w3.org/2000/svg" class="[ icon icon-tabler icon-tabler-code ] [ text-purple-700 ] [ fill-purple-500 ]" width="20" height="20" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
6+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
7+
<polyline points="7 8 3 12 7 16"></polyline>
8+
<polyline points="17 8 21 12 17 16"></polyline>
9+
<line x1="14" y1="4" x2="10" y2="20"></line>
10+
</svg> Code Sample - @Title
11+
</h4>
12+
<article id="@Id" class="[ bg-gray-300 ]">
13+
</article>
14+
</section>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.JSInterop;
3+
4+
namespace TestArena.Blog.Common;
5+
6+
public class GithubGistSnippetBase : ComponentBase, IAsyncDisposable
7+
{
8+
private IJSObjectReference? module;
9+
10+
protected string Id = Guid.NewGuid().ToString();
11+
12+
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;
13+
14+
[Parameter, EditorRequired] public string Title { get; set; } = default!;
15+
[Parameter, EditorRequired] public string UserId { get; set; } = default!;
16+
[Parameter, EditorRequired] public string FileName { get; set; } = default!;
17+
18+
protected override async Task OnInitializedAsync()
19+
{
20+
module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/githubgist.js");
21+
22+
await module.InvokeVoidAsync("printSnippetFrom", Id, UserId, FileName);
23+
}
24+
25+
async ValueTask IAsyncDisposable.DisposeAsync()
26+
{
27+
if (module is not null)
28+
{
29+
await module.DisposeAsync();
30+
}
31+
}
32+
}

TestArena/Blog/PactNet/Intro/Index.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@
77
<Summary/>
88
<BuildStepDetection />
99
<HowToSteps />
10+
11+
<Section Heading="Consumer side tests:">
12+
<ChildContent>
13+
<p>The very first step is to create a unit test file and initialize pact builder as shown below</p>
14+
<GithubGistSnippet Title="Pact Builder Setup" UserId="ajaysskumar" FileName="c45d40c48ea2a3e2c81719e41df6f882"/>
15+
</ChildContent>
16+
</Section>
17+
1018
</BlogContainer>

TestArena/wwwroot/js/githubgist.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export function printSnippetFrom(id, userId, filename) {
2+
const target = document.getElementById(id);
3+
const iframe = document.createElement('iframe');
4+
const iframeId = `${userId}-${filename}`;
5+
iframe.setAttribute("id", iframeId);
6+
iframe.setAttribute("width", "100%");
7+
target.appendChild(iframe);
8+
9+
let doc = iframe.document;
10+
if (iframe.contentDocument) doc = iframe.contentDocument;
11+
else if (iframe.contentWindow) doc = iframe.contentWindow.document;
12+
13+
const gistScript = `<script src="https://gist.github.com/${userId}/${filename}.js"></script>`;
14+
const resizeScript = `onload="parent.document.getElementById('${iframeId}').style.height=document.body.scrollHeight + 'px'"`;
15+
const iframeHtml = `<html><body ${resizeScript}>${gistScript}</body></html>`;
16+
17+
doc.open();
18+
doc.writeln(iframeHtml);
19+
doc.close();
20+
}

0 commit comments

Comments
 (0)