Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IActionResult Test() => View();
- @{
- Layout = null;
- }
- <stars-block title-id="56" score="6" default="true"></stars-block>
- public class StarsBlockTagHelper : TagHelper
- {
- public int TitleId { get; set; }
- public int Score { get; set; }
- public bool Default { get; set; }
- public override void Process(TagHelperContext context, TagHelperOutput output)
- {
- output.TagName = "div";
- output.Attributes.Add("class", "block-stars");
- output.Attributes.Add("data-title_id", TitleId);
- output.Attributes.Add("data-score", Score);
- output.Attributes.Add("data-default", Default);
- TagBuilder ul = new TagBuilder("ul");
- ul.AddCssClass("w3l-ratings");
- TagBuilder li;
- for (int i = 1; i <= 10; i =+ 2)
- {
- li = new TagBuilder("li");
- li.InnerHtml.AppendHtml(getStarHalf("left", i));
- li.InnerHtml.AppendHtml(getStarHalf("right", i + 1));
- ul.InnerHtml.AppendHtml(li);
- }
- output.Content.AppendHtml(ul);
- }
- private TagBuilder getStarHalf(string direction, int id)
- {
- TagBuilder div = new TagBuilder("div");
- div.AddCssClass("star-half");
- div.Attributes.Add("data-star_half_id", id.ToString());
- TagBuilder svg = new TagBuilder("svg");
- svg.Attributes.Add("version", "1.1");
- svg.Attributes.Add("id", "Layer_1");
- svg.Attributes.Add("xmlns", "http://www.w3.org/2000/svg");
- svg.Attributes.Add("xmlns:xlink", "http://www.w3.org/1999/xlink");
- svg.Attributes.Add("x", "0px");
- svg.Attributes.Add("y", "0px");
- svg.Attributes.Add("viewBox", "0 0 8.7 16.7");
- svg.Attributes.Add("xml:space", "preserve");
- TagBuilder path = new TagBuilder("path");
- path.TagRenderMode = TagRenderMode.SelfClosing;
- path.AddCssClass("star-half-" + direction);
- path.Attributes.Add("d", "M8.9,1.7L6,6.1L0.5,6.9l3.9,3.8l-0.9,5.5c1.8-1,3.6-1.9,5.4-2.9");
- svg.InnerHtml.AppendHtml(path);
- div.InnerHtml.AppendHtml(svg);
- return div;
- }
- <div class="block-stars" data-title_id="56" data-score="6" default="true">
- <ul class="w3l-ratings" >
- <li>
- <div class="star-half" data-star_half_id="1">
- <svg
- version="1.1"
- id="Layer_1"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- x="0px"
- y="0px"
- viewBox="0 0 8.7 16.7"
- xml:space="preserve">
- <path class="star-half-left"
- d="M8.9,1.7L6,6.1L0.5,6.9l3.9,3.8l-0.9,5.5c1.8-1,3.6-1.9,5.4-2.9"/>
- </svg>
- </div>
- <div class="star-half" data-star_half_id="2">
- <svg
- version="1.1"
- id="Layer_1"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- x="0px"
- y="0px"
- viewBox="0 0 8.7 16.7"
- xml:space="preserve">
- <path class="star-half-right"
- d="M8.9,1.7L6,6.1L0.5,6.9l3.9,3.8l-0.9,5.5c1.8-1,3.6-1.9,5.4-2.9"/>
- </svg>
- </div>
- </li>
- <!-- and so on 10 times -->
- </ul>
- </div>
Add Comment
Please, Sign In to add comment