Skip to content

Commit 696a68c

Browse files
authored
Add example of the official website of ElvisJS (#64)
* feat(example): add footer to todo-mvc * feat(website): complete the layout of the website * feat(widget): Add link widget * docs(help): add help wanted to readme * fix(readme): fix the typo of readme
1 parent 7c19741 commit 696a68c

File tree

36 files changed

+441
-154
lines changed

36 files changed

+441
-154
lines changed

Cargo.lock

Lines changed: 13 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ members = [
2424
"examples/click",
2525
"examples/router",
2626
"examples/todo-mvc",
27+
"examples/website",
2728
]
2829

2930
[dependencies]

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
Is anybody home? [The Evlis Book][1] mainly talks about the usage of [elvis][2], here is our [roadmap][roadmap], come and [join][community] us !~
1111

1212

13+
## Help Wanted
14+
15+
+ [ ] A static http/websocket development server [#16][#16]
16+
+ [ ] Documentation of ElvisJS [#65][#65]
17+
+ [ ] A Markdown parser using ElvisJS [#66][#66]
18+
+ [ ] Optimize the State machine [#67][#67]
19+
1320
## Getting Started
1421

1522
```
@@ -39,32 +46,35 @@ struct Index;
3946

4047
impl LifeCycle for Index {
4148
fn create(&self) -> Node {
42-
Center::new()
43-
.child(Text::new().text("Hello, World!"))
44-
.into()
49+
Center::with(Text::new().text("Hello, World!")).into()
4550
}
4651
}
4752
```
4853

49-
5054
## Examples
5155

5256
+ [hello-world][hello-world-example]
5357
+ [click][click-example]
5458
+ [router][router-example]
5559
+ [todo-mvc][todo-mvc]
60+
+ [website][website]
5661

5762

5863

5964
## LICENSE
6065

6166
Heartbreak Hotel.
6267

68+
[#16]: https://github.com/elvisjs/elvis/issues/16
69+
[#65]: https://github.com/elvisjs/elvis/issues/65
70+
[#66]: https://github.com/elvisjs/elvis/issues/66
71+
[#67]: https://github.com/elvisjs/elvis/issues/67
6372
[1]: https://elvisjs.github.io/book
6473
[2]: https://docs.rs/elvis
6574
[community]: https://elvisjs.github.io/book/community
6675
[hello-world-example]: https://github.com/elvisjs/elvis/tree/master/examples/hello-world
6776
[click-example]: https://github.com/elvisjs/elvis/tree/master/examples/click
6877
[router-example]: https://github.com/elvisjs/elvis/tree/master/examples/router
6978
[todo-mvc]: https://github.com/elvisjs/elvis/tree/master/examples/todo-mvc
79+
[website]: https://github.com/elvisjs/elvis/tree/master/examples/website
7080
[roadmap]: https://github.com/elvisjs/elvis/milestones

crates/core/src/attr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct Attribute {
99
pub tag: String,
1010
/// Source
1111
pub src: String,
12+
/// Href
13+
pub href: String,
1214
/// Text
1315
pub text: String,
1416
/// Type

crates/core/src/gesture.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ where
8383
fn into(self) -> Node {
8484
let mut n = self.child.into();
8585
n.gesture = Some(self.gesture);
86+
n.state = Some(HashMap::new());
8687
n
8788
}
8889
}

crates/core/src/node.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ impl Node {
142142
path
143143
}
144144

145-
// /// Generate a `Rc<RefCell<Node>>`
146-
// pub fn new() -> Rc<RefCell<Node>> {
147-
// Rc::new(RefCell::new(Node::default()))
148-
// }
149-
150145
/// Add second tree to the first one.
151146
pub fn push(r: Rc<RefCell<Node>>, c: Rc<RefCell<Node>>) {
152147
let pre = Rc::downgrade(&r);

crates/core/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub trait Router {
66
// /// Back to last page
77
// fn back() -> Result<(), Error>;
88
/// Push new path
9-
fn push(path: &str) -> Result<(), Error>;
9+
fn push(path: impl Into<String>) -> Result<(), Error>;
1010
}

crates/core/src/state.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ use std::collections::HashMap;
66
pub type StateKV = HashMap<Vec<u8>, Vec<u8>>;
77

88
/// state for tree
9-
pub struct State<W> {
9+
pub struct State {
1010
/// Elvis Node
11-
pub child: W,
11+
child: Node,
1212
/// State Machine
13-
pub state: StateKV,
13+
state: StateKV,
1414
}
1515

16-
impl<W> State<W>
17-
where
18-
W: Into<Node>,
19-
{
16+
impl State {
17+
/// New State
18+
pub fn new(node: impl Into<Node>) -> State {
19+
State {
20+
child: node.into(),
21+
state: HashMap::new(),
22+
}
23+
}
24+
}
25+
26+
impl State {
2027
/// Get state
2128
pub fn get(&self, k: &[u8]) -> Vec<u8> {
2229
self.state.get(k).unwrap_or(&vec![]).to_vec()
@@ -28,12 +35,9 @@ where
2835
}
2936
}
3037

31-
impl<W> Into<Node> for State<W>
32-
where
33-
W: Into<Node>,
34-
{
38+
impl Into<Node> for State {
3539
fn into(self) -> Node {
36-
let mut n = self.child.into();
40+
let mut n: Node = self.child.into();
3741
n.state = Some(self.state);
3842
n
3943
}

crates/core/src/style/init.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::value::{
33
FlexBasis, FlexDirection, FlexPosition, FlexWrap, GridAuto, GridFlow, GridTemplate,
44
MultiColumnLineStyle,
55
},
6-
BorderRadius, BorderStyle, BoxBorder, BoxShadow, Color, FontFamily, FontStyle, Position,
7-
TextAlign, Unit, VecUnit,
6+
BorderRadius, BorderStyle, BoxBorder, BoxShadow, Color, Display, FontFamily, FontStyle,
7+
Position, TextAlign, Unit, VecUnit,
88
};
99

1010
pub fn camel_snake(camel: &str) -> String {
@@ -91,6 +91,25 @@ macro_rules! construct_style {
9191
}
9292
}
9393
)*
94+
95+
$(
96+
#[doc=$sdoc]
97+
pub trait $ss {
98+
#[doc=$sdoc]
99+
fn $sf(self, value: super::$ss) -> Node;
100+
}
101+
102+
impl<T> $ss for T
103+
where
104+
T: Into<Node>,
105+
{
106+
fn $sf(self, value: super::$ss) -> Node {
107+
let mut node: Node = self.into();
108+
node.style.push(Style::$ss(value));
109+
node
110+
}
111+
}
112+
)*
94113
}
95114
};
96115
}
@@ -179,5 +198,6 @@ construct_style! {[
179198
(Position, position, "Box Position"),
180199

181200
// border radius
182-
(BorderRadius, box_radius, "Border Radius"),
201+
(BorderRadius, border_radius, "Border Radius"),
202+
(Display, display, "display"),
183203
]}

crates/core/src/value/border.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::value::{Color, Unit};
2-
use elvis_core_support::EnumStyle;
2+
use elvis_core_support::{EnumStyle, Setter};
33

44
/// Border Style
55
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, EnumStyle)]
@@ -33,7 +33,7 @@ impl Default for BorderStyle {
3333
}
3434

3535
/// Border Style
36-
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
36+
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Setter)]
3737
pub struct BoxBorder {
3838
/// border width
3939
pub width: Unit,
@@ -43,6 +43,13 @@ pub struct BoxBorder {
4343
pub color: Color,
4444
}
4545

46+
impl BoxBorder {
47+
/// The shortcut of `BoxBorder::new()`
48+
pub fn with(width: Unit) -> BoxBorder {
49+
BoxBorder::new().width(width)
50+
}
51+
}
52+
4653
impl Default for BoxBorder {
4754
fn default() -> BoxBorder {
4855
BoxBorder {
@@ -65,7 +72,7 @@ impl ToString for BoxBorder {
6572
}
6673

6774
/// Border Radius
68-
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
75+
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Setter)]
6976
pub struct BorderRadius {
7077
/// top left radius
7178
pub top_left: Unit,
@@ -85,6 +92,16 @@ pub struct BorderRadius {
8592
pub second_bottom_right: Unit,
8693
}
8794

95+
impl BorderRadius {
96+
/// Set all radius
97+
pub fn all(self, radius: Unit) -> BorderRadius {
98+
self.top_left(radius)
99+
.top_right(radius)
100+
.bottom_left(radius)
101+
.bottom_right(radius)
102+
}
103+
}
104+
88105
impl Default for BorderRadius {
89106
fn default() -> BorderRadius {
90107
BorderRadius {

0 commit comments

Comments
 (0)