Browse Source

Show link to raw view/refactor show

master
Dylan Baker 5 years ago
parent
commit
3da854df9f
2 changed files with 35 additions and 14 deletions
  1. 11
    3
      src/routes.rs
  2. 24
    11
      templates/snippets/show.tera

+ 11
- 3
src/routes.rs View File

@@ -30,15 +30,23 @@ pub fn show_snippet(id: i32, connection: DbConn) -> Template {
30 30
         Err(_) => None,
31 31
     };
32 32
 
33
-    let (title, body) = result.map_or(
33
+    let (id, title, body) = result.map_or(
34 34
         (
35
+            String::from(""),
35 36
             String::from("404 - Snippet not found"),
36
-            format!("<h3'>{}</h3>", "Snippet not found"),
37
+            String::from(""),
37 38
         ),
38
-        |snippet| (snippet.title, snippet.formatted_body),
39
+        |snippet| {
40
+            (
41
+                format!("{}", snippet.id),
42
+                snippet.title,
43
+                snippet.formatted_body,
44
+            )
45
+        },
39 46
     );
40 47
 
41 48
     let mut context: HashMap<&str, String> = HashMap::new();
49
+    context.insert("id", id);
42 50
     context.insert("title", title);
43 51
     context.insert("body", body);
44 52
 

+ 24
- 11
templates/snippets/show.tera View File

@@ -2,28 +2,41 @@
2 2
   <head>
3 3
     <title>{{ title }}</title>
4 4
     <style>
5
-      pre {
5
+      .container {
6
+        margin: auto;
7
+        max-width: 800px;
8
+      }
9
+
10
+      .header__raw-link {
6 11
         font-size: 16px;
7
-        padding: 15px;
12
+        font-weight: normal;
8 13
       }
9 14
 
10
-      pre.plaintext {
11
-        padding: 0;
15
+      .body > pre {
16
+        font-size: 16px;
17
+        padding: 15px;
12 18
       }
13 19
 
14
-      .container {
15
-        margin: auto;
16
-        max-width: 800px;
20
+      .body > pre.plaintext {
21
+        padding: 0;
17 22
       }
18 23
     </style>
19 24
     <meta name="viewport" content="width=device-width">
20 25
   </head>
21 26
   <body>
22 27
     <div class="container">
23
-      <h1>{{ title }}</h3>
24
-      <div>
25
-        {{ body | safe }}
26
-      </div>
28
+      <h1 class="header">
29
+        {{ title }}
30
+
31
+        {% if id %}
32
+          <a class="header__raw-link" href="/snippets/{{ id }}/raw">raw</a>
33
+        {% endif %}
34
+      </h1>
35
+      {% if body %}
36
+        <div class="body">
37
+          {{ body | safe }}
38
+        </div>
39
+      {% endif %}
27 40
     </div>
28 41
   </body>
29 42
 </html>

Loading…
Cancel
Save