|
| 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 | +) |
0 commit comments