-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #525 from bradwyoung/post-tag-helpers
New and Enhanced Post Tag helpers
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Threading.Tasks; | ||
using DasBlog.Services; | ||
using DasBlog.Web.Models.BlogViewModels; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace DasBlog.Web.TagHelpers.Post | ||
{ | ||
public class PostImageTagHelper: TagHelper | ||
|
||
{ | ||
public PostViewModel Post { get; set; } | ||
|
||
public string Css { get; set; } | ||
|
||
private readonly IDasBlogSettings dasBlogSettings; | ||
|
||
public PostImageTagHelper(IDasBlogSettings dasBlogSettings) | ||
{ | ||
this.dasBlogSettings = dasBlogSettings; | ||
} | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
output.TagMode = TagMode.StartTagAndEndTag; | ||
output.TagName = "img"; | ||
|
||
if (!string.IsNullOrEmpty(Css)) | ||
{ | ||
output.Attributes.SetAttribute("class", Css); | ||
} | ||
|
||
output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(Post.ImageUrl)); | ||
output.Attributes.SetAttribute("alt", Post.Title); | ||
await Task.CompletedTask; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
source/DasBlog.Web.UI/TagHelpers/Post/PostLinkTagHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DasBlog.Services; | ||
using DasBlog.Web.Models.BlogViewModels; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace DasBlog.Web.TagHelpers.Post | ||
{ | ||
public class PostLinkTagHelper : TagHelper | ||
|
||
{ | ||
public PostViewModel Post { get; set; } | ||
|
||
public string Css { get; set; } | ||
|
||
private readonly IDasBlogSettings dasBlogSettings; | ||
|
||
public PostLinkTagHelper(IDasBlogSettings dasBlogSettings) | ||
{ | ||
this.dasBlogSettings = dasBlogSettings; | ||
} | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
output.TagMode = TagMode.StartTagAndEndTag; | ||
output.TagName = "a"; | ||
|
||
if (!string.IsNullOrEmpty(Css)) | ||
{ | ||
output.Attributes.SetAttribute("class", Css); | ||
} | ||
|
||
output.Attributes.SetAttribute("href", dasBlogSettings.RelativeToRoot(Post.PermaLink)); | ||
await Task.CompletedTask; | ||
} | ||
} | ||
} |