Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ImageTagHelper #2516

Merged
merged 1 commit into from
May 11, 2015
Merged

ImageTagHelper #2516

merged 1 commit into from
May 11, 2015

Conversation

dpaquette
Copy link
Contributor

An ImageTagHelper that supports globbed src paths and cache busting file
version hash
[Resolves #2249]

@dnfclas
Copy link

dnfclas commented May 7, 2015

Hi @dpaquette, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dpaquette
Copy link
Contributor Author

What's the deal with @dnfclas ? I signed my cla before submitting this PR

@dougbu
Copy link
Member

dougbu commented May 8, 2015

@dpaquette We just changed the repos from MS Open Tech to .NET Foundation so there's a different CLA. The new CLA is simpler than the old one and so should only take a few moments to re-sign. Apologies for the extra bit of work!

@dnfclas
Copy link

dnfclas commented May 8, 2015

@dpaquette, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

/// If <c>true</c> then a query string "v" with the encoded content of the file is added.
/// </remarks>
[HtmlAttributeName(FileVersionAttributeName)]
public bool? FileVersion { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IncludeFileVersion? Or maybe AppendFileVersion? The current name makes it sound like it is a file version (e.g. you'd set asp-file-version="1.23.4" or something).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that AppendFileVersion or AddFileVersion would make more sense. This is modeled off the Link and Script tag helpers. If we change the name here then it would need to be changed on both those tag helpers too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why nullable? It's in the TargetElement so it'll always be provided.

@dpaquette
Copy link
Contributor Author

@Eilon I simplified the ImageTagHelper class by removing the Mode and Mode Detection code since this was no longer needed. Not sure what we should do about the naming of the asp-file-version attribute.

private FileVersionProvider _fileVersionProvider;

/// <summary>
/// Src of the image.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source

@dougbu
Copy link
Member

dougbu commented May 10, 2015

@dpaquette
Copy link
Contributor Author

@dougbu Simplified implementation and updated tests as per your comments

using Microsoft.Framework.Runtime;

using Moq;
using Xunit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove and sort usings. That should also clean up the extra blank line.

@NTaylorMullen
Copy link
Contributor

{ "data-extra", new HtmlString("something") },
{ "title", new HtmlString("Image title") },
{ "src", "testimage.png?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk" },
{ "asp-file-version", "true" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in realistic scenario asp-file-version would not appear in the Attributes collection after processing


private static TagHelperContext MakeTagHelperContext(
TagHelperAttributeList attributes = null,
string content = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify method signature: No need for attributes to be optional. No need for content at all.

@dougbu
Copy link
Member

dougbu commented May 10, 2015

⌚ very close

@dpaquette
Copy link
Contributor Author

@dougbu @NTaylorMullen Thanks for the review. I have updated based on your feedback. In retrospect, basing this implementation on the Link and Script Tag Helpers was probably a bad idea 😄

using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should have mentioned that we use the old VS default here: System namespaces first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@dougbu
Copy link
Member

dougbu commented May 10, 2015

@@ -47,6 +47,8 @@ public class MvcTagHelpersTest
[InlineData("Link", null)]
// Testing the ScriptTagHelper
[InlineData("Script", null)]
// Testing the ImageTagHelper
[InlineData("Image", null)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd that MvcTagHelpersWebSite.MvcTagHelper_Home.Image.html shows up here as a binary file. Anything unusual about it on your end? (Content looks fine when I click on View.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks line an encoding problem. I will try saving as UTF-8

@dougbu
Copy link
Member

dougbu commented May 11, 2015

:shipit:

Please rebase your branch to latest dev then squash your commits down to one (git rebase -i head~8 and change pick to s or squash for all commits except the first. We won't lose attribution when merging if you do that.

/// <inheritdoc />
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (FileVersion == true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (FileVersion)

@NTaylorMullen
Copy link
Contributor

:shipit:

An ImageTagHelper that supports cache busting by appending a file
version hash to the image src attribute
[Resolves #2249]

Code cleanup
@dpaquette
Copy link
Contributor Author

@dougbu @NTaylorMullen Thanks guys. I did a rebase to latest dev and squashed my commits.

@Eilon
Copy link
Member

Eilon commented May 11, 2015

BTW I logged #2540 to track changing the name of the FileVersion property.

@dougbu dougbu merged commit ab4d2ee into aspnet:dev May 11, 2015
@dougbu
Copy link
Member

dougbu commented May 11, 2015

ab4d2ee Thanks for your contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants