Guest User

Untitled

a guest
Mar 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. public IActionResult Test() => View();
  2.  
  3. @{
  4. Layout = null;
  5. }
  6.  
  7. <stars-block title-id="56" score="6" default="true"></stars-block>
  8.  
  9. public class StarsBlockTagHelper : TagHelper
  10. {
  11. public int TitleId { get; set; }
  12. public int Score { get; set; }
  13. public bool Default { get; set; }
  14.  
  15. public override void Process(TagHelperContext context, TagHelperOutput output)
  16. {
  17. output.TagName = "div";
  18. output.Attributes.Add("class", "block-stars");
  19. output.Attributes.Add("data-title_id", TitleId);
  20. output.Attributes.Add("data-score", Score);
  21. output.Attributes.Add("data-default", Default);
  22.  
  23. TagBuilder ul = new TagBuilder("ul");
  24. ul.AddCssClass("w3l-ratings");
  25.  
  26. TagBuilder li;
  27. for (int i = 1; i <= 10; i =+ 2)
  28. {
  29. li = new TagBuilder("li");
  30. li.InnerHtml.AppendHtml(getStarHalf("left", i));
  31. li.InnerHtml.AppendHtml(getStarHalf("right", i + 1));
  32.  
  33. ul.InnerHtml.AppendHtml(li);
  34. }
  35.  
  36. output.Content.AppendHtml(ul);
  37. }
  38.  
  39. private TagBuilder getStarHalf(string direction, int id)
  40. {
  41. TagBuilder div = new TagBuilder("div");
  42. div.AddCssClass("star-half");
  43. div.Attributes.Add("data-star_half_id", id.ToString());
  44.  
  45. TagBuilder svg = new TagBuilder("svg");
  46. svg.Attributes.Add("version", "1.1");
  47. svg.Attributes.Add("id", "Layer_1");
  48. svg.Attributes.Add("xmlns", "http://www.w3.org/2000/svg");
  49. svg.Attributes.Add("xmlns:xlink", "http://www.w3.org/1999/xlink");
  50. svg.Attributes.Add("x", "0px");
  51. svg.Attributes.Add("y", "0px");
  52. svg.Attributes.Add("viewBox", "0 0 8.7 16.7");
  53. svg.Attributes.Add("xml:space", "preserve");
  54.  
  55. TagBuilder path = new TagBuilder("path");
  56. path.TagRenderMode = TagRenderMode.SelfClosing;
  57. path.AddCssClass("star-half-" + direction);
  58. 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");
  59.  
  60. svg.InnerHtml.AppendHtml(path);
  61. div.InnerHtml.AppendHtml(svg);
  62.  
  63. return div;
  64. }
  65.  
  66. <div class="block-stars" data-title_id="56" data-score="6" default="true">
  67. <ul class="w3l-ratings" >
  68. <li>
  69. <div class="star-half" data-star_half_id="1">
  70. <svg
  71. version="1.1"
  72. id="Layer_1"
  73. xmlns="http://www.w3.org/2000/svg"
  74. xmlns:xlink="http://www.w3.org/1999/xlink"
  75. x="0px"
  76. y="0px"
  77. viewBox="0 0 8.7 16.7"
  78. xml:space="preserve">
  79.  
  80. <path class="star-half-left"
  81. 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"/>
  82. </svg>
  83. </div>
  84. <div class="star-half" data-star_half_id="2">
  85. <svg
  86. version="1.1"
  87. id="Layer_1"
  88. xmlns="http://www.w3.org/2000/svg"
  89. xmlns:xlink="http://www.w3.org/1999/xlink"
  90. x="0px"
  91. y="0px"
  92. viewBox="0 0 8.7 16.7"
  93. xml:space="preserve">
  94. <path class="star-half-right"
  95. 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"/>
  96. </svg>
  97. </div>
  98. </li>
  99. <!-- and so on 10 times -->
  100. </ul>
  101. </div>
Add Comment
Please, Sign In to add comment