Struct Page

Source
pub struct Page {
    pub content: Vec<El>,
}
Expand description

The Page struct. Stores a list of nested HTML elements.

Fields§

§content: Vec<El>

Implementations§

Source§

impl Page

Source

pub fn new(content: &[El]) -> Self

Returns a new Page. Takes a slice of El as input.

Examples found in repository?
examples/hello_world.rs (lines 5-12)
3fn main() {
4   
5   let page = Page::new(&[
6      Tag::Html.content(&[
7         Tag::Head.content(&[
8            Tag::Meta.attributes(&[Attr::Charset("UTF-8".into())])
9         ]),
10         Tag::Body.style(&[Prop::Background("green".into())]).content(&[])
11      ])
12   ]);
13   
14   println!("{}", page.format(false));
15   println!("");
16   println!("{}", page.format(true));
17   
18}
More examples
Hide additional examples
examples/index_with_nav.rs (lines 77-99)
76fn base_page() -> Page {
77   Page::new(&[
78      Tag::Html
79      .content(&[
80         Tag::Head
81         .content(&[
82            Tag::Meta
83            .attributes(&[
84               Attr::Charset("UTF-8".into()),
85            ]),
86            Tag::Style.content(&[
87               css(),
88            ])
89         ]),
90         Tag::Body
91         .content(&[
92            nav(),
93            Tag::Div
94            .attributes(&[
95               Attr::Id("main".into()),
96            ]),
97         ])
98      ])
99   ])
100}
Source

pub fn add(self, child: El) -> Self

Pushes an El onto content field vec.

Source

pub fn id_find(&mut self, id: &str) -> Option<&mut El>

Allows for finding a child element by its id attribute.

Examples found in repository?
examples/index_with_nav.rs (line 109)
102fn index() -> Page {
103   let mut page = base_page();
104   
105   page.content[0].content[1].content[1].content.push(
106      El::text("Hello")
107   );
108   
109   if let Some(el) = page.id_find("main") {
110      el.content.push(
111         El::text("<br>Hello")
112      );
113   }
114   
115   page
116}
Source

pub fn format(&self, make_pretty: bool) -> String

Formats the Page for display or storage. Automatically prepends ’ to the beginning of the file.

Examples found in repository?
examples/index_with_nav.rs (line 119)
118fn main() {
119	println!("{}", index().format(false));
120}
More examples
Hide additional examples
examples/hello_world.rs (line 14)
3fn main() {
4   
5   let page = Page::new(&[
6      Tag::Html.content(&[
7         Tag::Head.content(&[
8            Tag::Meta.attributes(&[Attr::Charset("UTF-8".into())])
9         ]),
10         Tag::Body.style(&[Prop::Background("green".into())]).content(&[])
11      ])
12   ]);
13   
14   println!("{}", page.format(false));
15   println!("");
16   println!("{}", page.format(true));
17   
18}

Trait Implementations§

Source§

impl Display for Page

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Page

§

impl RefUnwindSafe for Page

§

impl Send for Page

§

impl Sync for Page

§

impl Unpin for Page

§

impl UnwindSafe for Page

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.