html.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. use bumpalo::Bump;
  2. fn main() {}
  3. fn build(factory: Factory) {
  4. factory.text();
  5. div::new(factory)
  6. .r#class()
  7. .r#tag()
  8. .r#type()
  9. .add_children()
  10. .iter_children()
  11. .finish();
  12. }
  13. /// # The `div` element
  14. ///
  15. ///
  16. /// The <div> HTML element is the generic container for flow content. It has no effect on the content or layout until
  17. /// styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like Flexbox is
  18. /// applied to its parent element).
  19. ///
  20. /// As a "pure" container, the <div> element does not inherently represent anything. Instead, it's used to group content
  21. /// so it can be easily styled using the class or id attributes, marking a section of a document as being written in a
  22. /// different language (using the lang attribute), and so on.
  23. ///
  24. /// ## Usage
  25. /// ```
  26. /// rsx!{
  27. /// div { class: "tall", id: "unique id"
  28. /// h1 {}
  29. /// p {}
  30. /// }
  31. /// }
  32. ///
  33. /// ```
  34. ///
  35. /// ## Specifications
  36. /// - Content categories: Flow content, palpable content.
  37. /// - Permitted content: Flow content.
  38. /// - Permitted parents: Any element that accepts flow content.
  39. #[allow(non_camel_case_types)]
  40. struct div {}
  41. struct h1 {}
  42. struct h2 {}
  43. trait BasicElement: Sized {
  44. const TagName: &'static str;
  45. fn get_bump(&self) -> &Bump;
  46. fn new(factory: Factory) -> Self;
  47. fn add_children(self) -> Self {
  48. self
  49. }
  50. fn iter_children(self) -> Self {
  51. self
  52. }
  53. fn finish(self) -> Self {
  54. self
  55. }
  56. }
  57. impl BasicElement for div {
  58. const TagName: &'static str = "div";
  59. fn get_bump(&self) -> &Bump {
  60. todo!()
  61. }
  62. fn new(factory: Factory) -> Self {
  63. todo!()
  64. }
  65. }
  66. impl div {
  67. fn class(self) -> Self {
  68. self
  69. }
  70. fn tag(self) -> Self {
  71. self
  72. }
  73. fn r#type(self) -> Self {
  74. self
  75. }
  76. }
  77. #[derive(Clone, Copy)]
  78. struct Factory<'a> {
  79. bump: &'a bumpalo::Bump,
  80. }
  81. impl<'a> Factory<'a> {
  82. fn text(&self) -> &str {
  83. todo!()
  84. }
  85. fn new_el(&'a self, tag: &'static str) -> ElementBuilder<'a> {
  86. ElementBuilder {
  87. bump: self.bump,
  88. tag,
  89. }
  90. }
  91. }
  92. struct ElementBuilder<'a> {
  93. tag: &'static str,
  94. bump: &'a bumpalo::Bump,
  95. }