Dylan Baker 5 gadus atpakaļ
vecāks
revīzija
8783ea2e2a
5 mainītis faili ar 64 papildinājumiem un 32 dzēšanām
  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 Parādīt failu

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

+ 4
- 2
src/main.rs Parādīt failu

28
                 .required(true)
28
                 .required(true)
29
                 .possible_values(&["build", "new", "watch"])
29
                 .possible_values(&["build", "new", "watch"])
30
                 .index(1),
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
         .arg(
33
         .arg(
33
             Arg::with_name("name")
34
             Arg::with_name("name")
34
                 .required_if("command", "new")
35
                 .required_if("command", "new")
35
                 .index(2),
36
                 .index(2),
36
-        ).get_matches();
37
+        )
38
+        .get_matches();
37
 
39
 
38
     let include_drafts = match matches.occurrences_of("drafts") {
40
     let include_drafts = match matches.occurrences_of("drafts") {
39
         0 => false,
41
         0 => false,

+ 8
- 4
src/post.rs Parādīt failu

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

+ 8
- 4
src/render.rs Parādīt failu

8
         .replace(
8
         .replace(
9
             "{{ page_title }}",
9
             "{{ page_title }}",
10
             &format!("{} | {}", post.title, config.site_name),
10
             &format!("{} | {}", post.title, config.site_name),
11
-        ).replace(
11
+        )
12
+        .replace(
12
             "{{ contents }}",
13
             "{{ contents }}",
13
             &post_template.replace("{{ title }}", &post.title).replace(
14
             &post_template.replace("{{ title }}", &post.title).replace(
14
                 "{{ body }}",
15
                 "{{ body }}",
36
                         post_item_template
37
                         post_item_template
37
                             .replace("{{ slug }}", &post.slug)
38
                             .replace("{{ slug }}", &post.slug)
38
                             .replace("{{ title }}", &post.title)
39
                             .replace("{{ title }}", &post.title)
39
-                    }).collect::<Vec<String>>()
40
+                    })
41
+                    .collect::<Vec<String>>()
40
                     .join("\n"),
42
                     .join("\n"),
41
             ),
43
             ),
42
         )
44
         )
60
             &Config {
62
             &Config {
61
                 site_name: "Test Site".to_string(),
63
                 site_name: "Test Site".to_string(),
62
             },
64
             },
63
-        ).replace("\n", "");
65
+        )
66
+        .replace("\n", "");
64
 
67
 
65
         assert_eq!(
68
         assert_eq!(
66
             "<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>",
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
             &Config {
98
             &Config {
96
                 site_name: "Test Site".to_string(),
99
                 site_name: "Test Site".to_string(),
97
             },
100
             },
98
-        ).replace("\n", "");
101
+        )
102
+        .replace("\n", "");
99
 
103
 
100
         assert_eq!(
104
         assert_eq!(
101
             "<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>",
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 Parādīt failu

21
     fs::write(
21
     fs::write(
22
         cwd.join("public").join(&post.slug).join("index.html"),
22
         cwd.join("public").join(&post.slug).join("index.html"),
23
         render_post(layout, post_template, post, config),
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
 pub fn write_post_listing(
28
 pub fn write_post_listing(
41
             posts,
42
             posts,
42
             config,
43
             config,
43
         ),
44
         ),
44
-    ).expect("Unable to write file");
45
+    )
46
+    .expect("Unable to write file");
45
 }
47
 }
46
 
48
 
47
 #[cfg(test)]
49
 #[cfg(test)]

Notiek ielāde…
Atcelt
Saglabāt