Browse Source

fmt

master
Dylan Baker 5 years ago
parent
commit
8783ea2e2a
5 changed files with 64 additions and 32 deletions
  1. 40
    20
      src/commands.rs
  2. 4
    2
      src/main.rs
  3. 8
    4
      src/post.rs
  4. 8
    4
      src/render.rs
  5. 4
    2
      src/write.rs

+ 40
- 20
src/commands.rs View File

@@ -58,7 +58,8 @@ pub fn build(include_drafts: bool) {
58 58
             let post = parse_post(entry.path());
59 59
             write_post(&cwd, &layout_template, &post_template, &post, &config);
60 60
             post
61
-        }).collect();
61
+        })
62
+        .collect();
62 63
 
63 64
     write_post_listing(
64 65
         &cwd,
@@ -73,7 +74,8 @@ pub fn build(include_drafts: bool) {
73 74
         &vec![cwd.join("css"), cwd.join("js")],
74 75
         cwd.join("public"),
75 76
         &dir::CopyOptions::new(),
76
-    ).expect("Couldn't copy css/js directories");
77
+    )
78
+    .expect("Couldn't copy css/js directories");
77 79
 }
78 80
 
79 81
 pub fn new(name: &str) {
@@ -84,7 +86,8 @@ pub fn new(name: &str) {
84 86
     fs::write(
85 87
         project_path.join("tlon.toml"),
86 88
         format!("site_name = \"{}\"", &name),
87
-    ).expect("Could not create tlon.toml");
89
+    )
90
+    .expect("Could not create tlon.toml");
88 91
 
89 92
     for dir in &["drafts", "posts", "public", "templates", "css", "js"] {
90 93
         fs::create_dir(&project_path.join(&dir))
@@ -101,7 +104,8 @@ pub fn new(name: &str) {
101 104
                 .join("templates")
102 105
                 .join(format!("{}.html", file)),
103 106
             "",
104
-        ).expect(&format!("Couldn't write templates/{}.html", file));
107
+        )
108
+        .expect(&format!("Couldn't write templates/{}.html", file));
105 109
     }
106 110
 }
107 111
 
@@ -213,31 +217,38 @@ mod tests {
213 217
         fs::write(
214 218
             project_dir.join("css").join("style.css"),
215 219
             "body { background: blue; }",
216
-        ).unwrap();
220
+        )
221
+        .unwrap();
217 222
         fs::write(
218 223
             project_dir.join("js").join("index.js"),
219 224
             "window.onload = function () { alert() }",
220
-        ).unwrap();
225
+        )
226
+        .unwrap();
221 227
         fs::write(
222 228
             project_dir.join("templates").join("layout.html"),
223 229
             "<html><head><title>{{ page_title }}</title></head><body>{{ contents }}</body></html>",
224
-        ).unwrap();
230
+        )
231
+        .unwrap();
225 232
         fs::write(
226 233
             project_dir.join("templates").join("post.html"),
227 234
             "<article><h1>{{ title }}</h1><div>{{ body }}</div></article>",
228
-        ).unwrap();
235
+        )
236
+        .unwrap();
229 237
         fs::write(
230 238
             project_dir.join("templates").join("post_listing.html"),
231 239
             "<ul>{{ post_listing }}</ul>",
232
-        ).unwrap();
240
+        )
241
+        .unwrap();
233 242
         fs::write(
234 243
             project_dir.join("templates").join("post_listing_item.html"),
235 244
             "<li><a href=\"/{{ slug }}\">{{ title }}</a></li>",
236
-        ).unwrap();
245
+        )
246
+        .unwrap();
237 247
         fs::write(
238 248
             project_dir.join("posts").join("first-post.md"),
239 249
             "# First post\n\nThis is the first post\n\nIt has multiple paragraphs",
240
-        ).unwrap();
250
+        )
251
+        .unwrap();
241 252
         fs::write(project_dir.join("tlon.toml"), "site_name = \"Test Site\"").unwrap();
242 253
 
243 254
         build(false);
@@ -257,7 +268,8 @@ mod tests {
257 268
                     .join("public")
258 269
                     .join("first-post")
259 270
                     .join("index.html")
260
-            ).unwrap()
271
+            )
272
+            .unwrap()
261 273
             .replace("\n", ""),
262 274
         );
263 275
 
@@ -292,35 +304,43 @@ mod tests {
292 304
         fs::write(
293 305
             project_dir.join("css").join("style.css"),
294 306
             "body { background: blue; }",
295
-        ).unwrap();
307
+        )
308
+        .unwrap();
296 309
         fs::write(
297 310
             project_dir.join("js").join("index.js"),
298 311
             "window.onload = function () { alert() }",
299
-        ).unwrap();
312
+        )
313
+        .unwrap();
300 314
         fs::write(
301 315
             project_dir.join("templates").join("layout.html"),
302 316
             "<html><head><title>{{ page_title }}</title></head><body>{{ contents }}</body></html>",
303
-        ).unwrap();
317
+        )
318
+        .unwrap();
304 319
         fs::write(
305 320
             project_dir.join("templates").join("post.html"),
306 321
             "<article><h1>{{ title }}</h1><div>{{ body }}</div></article>",
307
-        ).unwrap();
322
+        )
323
+        .unwrap();
308 324
         fs::write(
309 325
             project_dir.join("templates").join("post_listing.html"),
310 326
             "<ul>{{ post_listing }}</ul>",
311
-        ).unwrap();
327
+        )
328
+        .unwrap();
312 329
         fs::write(
313 330
             project_dir.join("templates").join("post_listing_item.html"),
314 331
             "<li><a href=\"/{{ slug }}\">{{ title }}</a></li>",
315
-        ).unwrap();
332
+        )
333
+        .unwrap();
316 334
         fs::write(
317 335
             project_dir.join("posts").join("first-post.md"),
318 336
             "# First post\n\nThis is the first post",
319
-        ).unwrap();
337
+        )
338
+        .unwrap();
320 339
         fs::write(
321 340
             project_dir.join("drafts").join("first-draft.md"),
322 341
             "# First draft\n\nThis is the first draft",
323
-        ).unwrap();
342
+        )
343
+        .unwrap();
324 344
         fs::write(project_dir.join("tlon.toml"), "site_name = \"Test Site\"").unwrap();
325 345
 
326 346
         build(true);

+ 4
- 2
src/main.rs View File

@@ -28,12 +28,14 @@ fn main() {
28 28
                 .required(true)
29 29
                 .possible_values(&["build", "new", "watch"])
30 30
                 .index(1),
31
-        ).arg(Arg::with_name("drafts").short("d").long("drafts"))
31
+        )
32
+        .arg(Arg::with_name("drafts").short("d").long("drafts"))
32 33
         .arg(
33 34
             Arg::with_name("name")
34 35
                 .required_if("command", "new")
35 36
                 .index(2),
36
-        ).get_matches();
37
+        )
38
+        .get_matches();
37 39
 
38 40
     let include_drafts = match matches.occurrences_of("drafts") {
39 41
         0 => false,

+ 8
- 4
src/post.rs View File

@@ -67,7 +67,8 @@ mod tests {
67 67
             fs::write(
68 68
                 cwd.join("posts").join(format!("{}.md", &uuid)),
69 69
                 &String::from(post_body),
70
-            ).unwrap();
70
+            )
71
+            .unwrap();
71 72
         }
72 73
 
73 74
         let mut expected_paths: Vec<String> = uuids
@@ -79,7 +80,8 @@ mod tests {
79 80
                         .to_str()
80 81
                         .unwrap(),
81 82
                 )
82
-            }).collect();
83
+            })
84
+            .collect();
83 85
         expected_paths.sort();
84 86
         let mut actual_paths: Vec<String> = read_posts_dir(&cwd.join("posts"))
85 87
             .into_iter()
@@ -107,7 +109,8 @@ mod tests {
107 109
         fs::write(
108 110
             cwd.join("posts").join(&filename),
109 111
             "# This is a post\n\nHere is some content that goes in the post",
110
-        ).unwrap();
112
+        )
113
+        .unwrap();
111 114
 
112 115
         let post = parse_post(cwd.join("posts").join(&filename));
113 116
         assert_eq!("This is a post", post.title);
@@ -132,7 +135,8 @@ mod tests {
132 135
         fs::write(
133 136
             cwd.join("posts").join(&filename),
134 137
             "# This is a post\n\nHere is a line\n\nHere is another line\n\nAnd a third",
135
-        ).unwrap();
138
+        )
139
+        .unwrap();
136 140
 
137 141
         let post = parse_post(cwd.join("posts").join(&filename));
138 142
         assert_eq!("This is a post", post.title);

+ 8
- 4
src/render.rs View File

@@ -8,7 +8,8 @@ pub fn render_post(layout: &str, post_template: &str, post: &Post, config: &Conf
8 8
         .replace(
9 9
             "{{ page_title }}",
10 10
             &format!("{} | {}", post.title, config.site_name),
11
-        ).replace(
11
+        )
12
+        .replace(
12 13
             "{{ contents }}",
13 14
             &post_template.replace("{{ title }}", &post.title).replace(
14 15
                 "{{ body }}",
@@ -36,7 +37,8 @@ pub fn render_post_listing(
36 37
                         post_item_template
37 38
                             .replace("{{ slug }}", &post.slug)
38 39
                             .replace("{{ title }}", &post.title)
39
-                    }).collect::<Vec<String>>()
40
+                    })
41
+                    .collect::<Vec<String>>()
40 42
                     .join("\n"),
41 43
             ),
42 44
         )
@@ -60,7 +62,8 @@ mod tests {
60 62
             &Config {
61 63
                 site_name: "Test Site".to_string(),
62 64
             },
63
-        ).replace("\n", "");
65
+        )
66
+        .replace("\n", "");
64 67
 
65 68
         assert_eq!(
66 69
             "<html><head><title>hello world | Test Site</title></head><body><article><h1>hello world</h1><div><p>lorem ipsum dolor sit amet</p></div></article></body></html>",
@@ -95,7 +98,8 @@ mod tests {
95 98
             &Config {
96 99
                 site_name: "Test Site".to_string(),
97 100
             },
98
-        ).replace("\n", "");
101
+        )
102
+        .replace("\n", "");
99 103
 
100 104
         assert_eq!(
101 105
             "<html><head><title>Test Site</title></head><body><ul><li><a href=\"/first-post\">First post</a></li><li><a href=\"/second-post\">Second post</a></li><li><a href=\"/third-post\">Third post</a></li></ul></body></html>",

+ 4
- 2
src/write.rs View File

@@ -21,7 +21,8 @@ pub fn write_post(
21 21
     fs::write(
22 22
         cwd.join("public").join(&post.slug).join("index.html"),
23 23
         render_post(layout, post_template, post, config),
24
-    ).expect("Unable to write file");
24
+    )
25
+    .expect("Unable to write file");
25 26
 }
26 27
 
27 28
 pub fn write_post_listing(
@@ -41,7 +42,8 @@ pub fn write_post_listing(
41 42
             posts,
42 43
             config,
43 44
         ),
44
-    ).expect("Unable to write file");
45
+    )
46
+    .expect("Unable to write file");
45 47
 }
46 48
 
47 49
 #[cfg(test)]

Loading…
Cancel
Save