Skip to content

Commit 58cf91b

Browse files
committed
page initilization
1 parent e130471 commit 58cf91b

File tree

6 files changed

+203
-121
lines changed

6 files changed

+203
-121
lines changed

index.html

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Respo Moonbit</title>
5-
<style>
6-
body {
7-
margin: 0;
8-
}
9-
10-
body * {
11-
box-sizing: border-box;
12-
}
13-
</style>
4+
<title>MoonBit is like Rust</title>
145
</head>
156
<body>
167
<!-- <script src="./main.mjs" type="module"></script> -->

src/main/container.mbt

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
fn comp_container() -> @respo_node.RespoNode[ActionOp] {
2+
div(
3+
class_name=str_spaced(
4+
[@respo.preset, @respo.ui_global, @respo.ui_fullscreen, @respo.ui_column],
5+
),
6+
style=respo_style(font_family="Helvetica Neue, sans-serif"),
7+
[
8+
div(
9+
class_name=@respo.ui_center,
10+
style=respo_style(
11+
background_color=RawString("rgb(221, 221, 221)"),
12+
font_weight="100",
13+
font_size=24,
14+
padding=Px(40),
15+
color=RawString("#888"),
16+
line_height=Em(2),
17+
),
18+
[
19+
text_node("MoonBit is like Rust (Except that it has GC)"),
20+
text_node("Fork repo if you want to contribute."),
21+
],
22+
),
23+
div(
24+
style=respo_style(background_color=RawString("#eee")),
25+
[
26+
div(
27+
style=respo_style(max_width=Px(1400), margin=Auto),
28+
[
29+
comp_section("BASICS"),
30+
comp_topic("Hello World"),
31+
comp_compare(
32+
"println(\"Hello, World!\")", "println!(\"Hello, World!\");",
33+
),
34+
comp_topic("Variables And Constants"),
35+
comp_compare(mbt_variable, rs_variable),
36+
comp_topic("Explicit Types"),
37+
comp_topic("Type Coercion"),
38+
comp_topic("String Interpolation"),
39+
comp_topic("Range Operator"),
40+
comp_topic("Inclusive Range Operator"),
41+
comp_section("COLLECTIONS"),
42+
comp_topic("Arrays"),
43+
comp_topic("Maps"),
44+
comp_topic("Empty Collections"),
45+
comp_section("FUNCTIONS"),
46+
comp_topic("Functions"),
47+
comp_topic("Tuple Return"),
48+
comp_topic("Variable Number Of Arguments"),
49+
comp_topic("Function Type"),
50+
comp_topic("Map"),
51+
comp_topic("Sort"),
52+
comp_topic("Named Arguments"),
53+
comp_section("TRAITS"),
54+
comp_topic("Declaration"),
55+
comp_topic("Usage"),
56+
comp_topic("Default Implementation"),
57+
comp_topic("Downcasting"),
58+
comp_topic("Protocol"),
59+
comp_topic("Extensions"),
60+
@respo_node.space(height=200),
61+
],
62+
),
63+
],
64+
),
65+
],
66+
)
67+
}
68+
69+
fn comp_section(title : String) -> @respo_node.RespoNode[ActionOp] {
70+
div(
71+
class_name=str_spaced([]),
72+
style=respo_style(
73+
padding=Px(12),
74+
font_size=48,
75+
font_weight="100",
76+
text_align=Center,
77+
margin=Px(60),
78+
color=RawString("#888"),
79+
),
80+
[text_node(title)],
81+
)
82+
}
83+
84+
fn comp_topic(title : String) -> @respo_node.RespoNode[ActionOp] {
85+
div(
86+
class_name=str_spaced([@respo.ui_center]),
87+
style=respo_style(
88+
padding=Px(12),
89+
font_size=32,
90+
font_weight="200",
91+
margin=Px(60),
92+
color=RawString("#444"),
93+
),
94+
[div([text_node(title)])],
95+
)
96+
}
97+
98+
fn comp_compare(
99+
mbt_code : String,
100+
rs_code : String
101+
) -> @respo_node.RespoNode[ActionOp] {
102+
div(
103+
class_name=str_spaced([@respo.ui_row]),
104+
style=respo_style(padding=Px(12)),
105+
[
106+
div(
107+
class_name=str_spaced([@respo.ui_expand, @respo.ui_column]),
108+
[
109+
div([text_node("MoonBit", class_name=style_lang_name)]),
110+
div([code_block(mbt_code)]),
111+
],
112+
),
113+
@respo_node.space(width=16),
114+
div(
115+
class_name=str_spaced([@respo.ui_expand, @respo.ui_column]),
116+
[
117+
div([text_node("Rust", class_name=style_lang_name)]),
118+
div([code_block(rs_code)]),
119+
],
120+
),
121+
],
122+
)
123+
}
124+
125+
/// a custom style for code block
126+
fn code_block[T](
127+
class_name? : String,
128+
style? : @respo_node.RespoStyle,
129+
code : String
130+
) -> @respo_node.RespoNode[T] {
131+
pre(
132+
class_name=str_some_spaced(
133+
[
134+
Some(@respo.ui_font_code),
135+
Some(@respo.ui_expand),
136+
class_name,
137+
Some(style_code_block),
138+
],
139+
),
140+
style=style.or_default(),
141+
inner_text=code,
142+
)
143+
}
144+
145+
fn str_some_spaced(arr : Array[String?]) -> String {
146+
arr.filter(fn(x) { not(x.is_empty()) }).map(fn(x) { x.unwrap() })
147+
|> String::concat(separator=" ")
148+
}
149+
150+
let style_code_block : String = declare_static_style(
151+
[
152+
(
153+
"&",
154+
respo_style(
155+
padding=Px(8),
156+
background_color=Hsl(0, 0, 100),
157+
border=(1.0, Solid, Hsl(0, 0, 90)),
158+
border_radius=4,
159+
line_height=Em(1.6),
160+
font_size=13,
161+
),
162+
),
163+
("pre&", respo_style(margin=Px(0))),
164+
],
165+
)
166+
167+
let style_lang_name : String = declare_static_style(
168+
[
169+
(
170+
"&",
171+
respo_style(
172+
font_weight="100",
173+
line_height=Em(1.6),
174+
font_size=18,
175+
margin_bottom=Px(8),
176+
),
177+
),
178+
],
179+
)

src/main/counter.mbt

-103
This file was deleted.

src/main/main.mbt

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
let app_store_key : String = "mbt-workflow"
22

33
fn view(
4-
store : Store
4+
_store : Store
55
) -> @respo_node.RespoNode[ActionOp]!@respo_node.RespoCommonError {
66
if false {
77
raise @respo_node.RespoCommonError("TODO")
88
}
99
// @dom_ffi.log("Store to render: " + store.to_json().stringify(indent=2))
10-
let states = store.get_states()
11-
div(
12-
class_name=@respo.ui_global,
13-
style=respo_style(padding=Px(12)),
14-
[comp_counter(states.pick("counter"), store.counted)],
15-
)
10+
// let states = store.get_states()
11+
comp_container()
1612
}
1713

1814
fn main {

src/main/moon.pkg.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"span",
1616
"respo_attrs",
1717
"respo_style",
18-
"declare_static_style"
18+
"str_spaced",
19+
"pre",
20+
"declare_static_style",
21+
"text_node"
1922
]
2023
},
2124
{ "path": "tiye/dom-ffi/lib", "alias": "dom_ffi" }

src/main/snippets.mbt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let mbt_variable : String =
2+
#| let mut my_variable: Int = 42
3+
#| my_variable = 50
4+
#|
5+
#| let my_constant = 42
6+
7+
let rs_variable : String =
8+
#| let mut my_variable: usize = 42;
9+
#| my_variable = 50;
10+
#|
11+
#| let my_constant: usize = 42:
12+
13+
// fn demo() {
14+
// let mut my_variable : Int = 42
15+
16+
// }

0 commit comments

Comments
 (0)