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
impl Page
Sourcepub fn new(content: &[El]) -> Self
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
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}
Sourcepub fn id_find(&mut self, id: &str) -> Option<&mut El>
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}
Sourcepub fn format(&self, make_pretty: bool) -> String
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?
More 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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more