Skip to content

Commit

Permalink
Closes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
valdisiljuconoks committed Nov 23, 2020
1 parent 09ada28 commit 6ed55fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions samples/SampleAlloy/Views/StartPage/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
@model PageViewModel<SampleAlloy.Models.Pages.StartPage>


<div>
@Html.Raw(Html.ResizePicture(Model.CurrentPage.MainImage, PictureProfiles.SampleImage, cssClass: "sample-css-class").ToHtmlString())
@Html.ResizePicture(Model.CurrentPage.MainImage, PictureProfiles.SampleImage, cssClass: "sample-css-class")
</div>

<div>
@Html.ResizePictures(new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static MvcHtmlString ResizePictures(this HtmlHelper helper, UrlBuilder[]
source.Attributes.Add("srcset", url.ToString());
source.Attributes.Add("media", media);

sources.Append(source);
sources.Append(source.ToString(TagRenderMode.SelfClosing));
}

var img = new TagBuilder("img");
Expand All @@ -50,7 +50,7 @@ public static MvcHtmlString ResizePictures(this HtmlHelper helper, UrlBuilder[]
if (!string.IsNullOrEmpty(cssClass))
img.Attributes.Add("class", cssClass);

picture.InnerHtml = sources.ToString() + img;
picture.InnerHtml = sources + img.ToString(TagRenderMode.SelfClosing);

return new MvcHtmlString(picture.ToString());
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public static MvcHtmlString ResizePicture(this HtmlHelper helper, UrlBuilder url
public static MvcHtmlString ResizePicture(this HtmlHelper helper, ContentReference image, PictureProfile profile, string alternateText = "", string cssClass = "")
{
var imgUrl = helper.ResizeImage(image, profile.DefaultWidth);
var sourceSets = profile.SrcSetWidths.Select(w => $"{helper.ResizeImage(image, w).ToString()} {w}w").ToArray();
var sourceSets = profile.SrcSetWidths.Select(w => $"{helper.ResizeImage(image, w)} {w}w").ToArray();

return GeneratePictureElement(profile, imgUrl.ToString(), sourceSets, alternateText, cssClass);
}
Expand All @@ -109,7 +109,7 @@ private static MvcHtmlString GeneratePictureElement(PictureProfile profile, stri
if(!string.IsNullOrEmpty(cssClass))
img.Attributes.Add("class", cssClass);

picture.InnerHtml = source.ToString() + img;
picture.InnerHtml = source.ToString(TagRenderMode.SelfClosing) + img.ToString(TagRenderMode.SelfClosing);

return new MvcHtmlString(picture.ToString());
}
Expand Down

0 comments on commit 6ed55fb

Please sign in to comment.