|
@@ -116,20 +116,56 @@ pub fn new(name: &str) {
|
116
|
116
|
.expect("Couldn't create css/style.css");
|
117
|
117
|
fs::write(project_path.join("js").join("index.js"), "").expect("Couldn't create js/index.js");
|
118
|
118
|
|
119
|
|
- for file in &[
|
120
|
|
- "layout",
|
121
|
|
- "post_listing",
|
122
|
|
- "post",
|
123
|
|
- "page",
|
124
|
|
- "post_listing_item",
|
|
119
|
+ let default_layout_template = format!(
|
|
120
|
+ "<html>
|
|
121
|
+ <head>
|
|
122
|
+ <title>{}</title>
|
|
123
|
+ </head>
|
|
124
|
+ <body>
|
|
125
|
+ <h1>{}</h1>
|
|
126
|
+ {{{{ contents }}}}
|
|
127
|
+ </body>
|
|
128
|
+</html>\n",
|
|
129
|
+ name, name
|
|
130
|
+ );
|
|
131
|
+ let default_post_listing_template = format!(
|
|
132
|
+ "<div>
|
|
133
|
+ <h3>Posts</h3>
|
|
134
|
+ <ul>{{{{ post_listing }}}}</ul>
|
|
135
|
+</div>\n"
|
|
136
|
+ );
|
|
137
|
+ let default_post_template = format!(
|
|
138
|
+ "<article>
|
|
139
|
+ <h1>{{{{ title }}}}</h1>
|
|
140
|
+ <div>{{{{ body }}}}</div>
|
|
141
|
+</article>\n"
|
|
142
|
+ );
|
|
143
|
+ let default_page_template = format!(
|
|
144
|
+ "<article>
|
|
145
|
+ <h1>{{{{ title }}}}</h1>
|
|
146
|
+ <div>{{{{ body }}}}</div>
|
|
147
|
+</article>\n"
|
|
148
|
+ );
|
|
149
|
+ let default_post_listing_item_template = format!(
|
|
150
|
+ "<li>
|
|
151
|
+ <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
|
|
152
|
+</li>\n"
|
|
153
|
+ );
|
|
154
|
+
|
|
155
|
+ for (filename, contents) in &[
|
|
156
|
+ ("layout", &default_layout_template),
|
|
157
|
+ ("post_listing", &default_post_listing_template),
|
|
158
|
+ ("post", &default_post_template),
|
|
159
|
+ ("page", &default_page_template),
|
|
160
|
+ ("post_listing_item", &default_post_listing_item_template),
|
125
|
161
|
] {
|
126
|
162
|
fs::write(
|
127
|
163
|
&project_path
|
128
|
164
|
.join("templates")
|
129
|
|
- .join(format!("{}.html", file)),
|
130
|
|
- "",
|
|
165
|
+ .join(format!("{}.html", filename)),
|
|
166
|
+ &contents,
|
131
|
167
|
)
|
132
|
|
- .expect(&format!("Couldn't write templates/{}.html", file));
|
|
168
|
+ .expect(&format!("Couldn't write templates/{}.html", filename));
|
133
|
169
|
}
|
134
|
170
|
}
|
135
|
171
|
|
|
@@ -192,25 +228,42 @@ mod tests {
|
192
|
228
|
}
|
193
|
229
|
|
194
|
230
|
assert_eq!(
|
195
|
|
- "",
|
196
|
|
- fs::read_to_string(&project_dir.join("templates").join("post_listing.html")).unwrap()
|
|
231
|
+ format!(
|
|
232
|
+ "<html><head><title>{}</title></head><body><h1>{}</h1>{{{{ contents }}}}</body></html>",
|
|
233
|
+ uuid, uuid
|
|
234
|
+ ),
|
|
235
|
+ fs::read_to_string(&project_dir.join("templates").join("layout.html"))
|
|
236
|
+ .unwrap()
|
|
237
|
+ .replace("\n", "")
|
|
238
|
+ .replace(" ", "")
|
197
|
239
|
);
|
198
|
240
|
assert_eq!(
|
199
|
|
- "",
|
200
|
|
- fs::read_to_string(&project_dir.join("templates").join("layout.html")).unwrap()
|
|
241
|
+ format!("<div><h3>Posts</h3><ul>{{{{ post_listing }}}}</ul></div>"),
|
|
242
|
+ fs::read_to_string(&project_dir.join("templates").join("post_listing.html"))
|
|
243
|
+ .unwrap()
|
|
244
|
+ .replace("\n", "")
|
|
245
|
+ .replace(" ", "")
|
201
|
246
|
);
|
202
|
247
|
assert_eq!(
|
203
|
|
- "",
|
|
248
|
+ format!("<li><a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a></li>"),
|
204
|
249
|
fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
|
205
|
250
|
.unwrap()
|
|
251
|
+ .replace("\n", "")
|
|
252
|
+ .replace(" ", "")
|
206
|
253
|
);
|
207
|
254
|
assert_eq!(
|
208
|
|
- "",
|
209
|
|
- fs::read_to_string(&project_dir.join("templates").join("post.html")).unwrap()
|
|
255
|
+ format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
|
|
256
|
+ fs::read_to_string(&project_dir.join("templates").join("post.html"))
|
|
257
|
+ .unwrap()
|
|
258
|
+ .replace("\n", "")
|
|
259
|
+ .replace(" ", "")
|
210
|
260
|
);
|
211
|
261
|
assert_eq!(
|
212
|
|
- "",
|
213
|
|
- fs::read_to_string(&project_dir.join("templates").join("page.html")).unwrap()
|
|
262
|
+ format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
|
|
263
|
+ fs::read_to_string(&project_dir.join("templates").join("page.html"))
|
|
264
|
+ .unwrap()
|
|
265
|
+ .replace("\n", "")
|
|
266
|
+ .replace(" ", "")
|
214
|
267
|
);
|
215
|
268
|
assert_eq!(
|
216
|
269
|
"",
|