Permalink
Browse files

Use JavaScriptLoggingTagHelperComponent

  • Loading branch information...
hishamco committed Apr 4, 2017
1 parent 926fb2f commit 277a9ba46ddcef813b91036e616925c019171148
View
@@ -5,6 +5,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Routing;
using jsLogger.Extensions;
using Microsoft.AspNetCore.Razor.TagHelpers;
using jsLogger.TagHelpers;
namespace jsLogger
{
@@ -30,6 +32,8 @@ public void ConfigureServices(IServiceCollection services)
{
options.HandleGlobalExceptions = true;
});
services.AddSingleton<ITagHelperComponent, JavaScriptLoggingTagHelperComponent>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Threading.Tasks;
namespace jsLogger.TagHelpers
{
public class JavaScriptLoggingTagHelperComponent : TagHelperComponent
{
private readonly string _script;
public JavaScriptLoggingTagHelperComponent(JavaScriptLoggingSnippet jsLoggingSnippet)
{
_script = jsLoggingSnippet.Script;
}
public override int Order => 1;
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (string.Equals(context.TagName, "head", StringComparison.Ordinal))

This comment has been minimized.

Show comment
Hide comment
@DamianEdwards

DamianEdwards Apr 4, 2017

Do you intend for this to be a case-sensitive match? I'd expect not.

@DamianEdwards

DamianEdwards Apr 4, 2017

Do you intend for this to be a case-sensitive match? I'd expect not.

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Apr 4, 2017

Owner

May be .. may be not while everything is possible in HTML 😄 unless we use XHTML (strict HTML)

@hishamco

hishamco Apr 4, 2017

Owner

May be .. may be not while everything is possible in HTML 😄 unless we use XHTML (strict HTML)

{
output.PostContent.AppendHtml(_script);
}
return Task.CompletedTask;
}
}
}
@@ -1,6 +1,4 @@
@inject JavaScriptLoggingSnippet JavaScriptLoggingSnippet
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@@ -17,7 +15,6 @@
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
@Html.Raw(JavaScriptLoggingSnippet.Script)
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">

0 comments on commit 277a9ba

Please sign in to comment.