Explorar el Código

Show link to raw view/refactor show

master
Dylan Baker hace 5 años
padre
commit
3da854df9f
Se han modificado 2 ficheros con 35 adiciones y 14 borrados
  1. 11
    3
      src/routes.rs
  2. 24
    11
      templates/snippets/show.tera

+ 11
- 3
src/routes.rs Ver fichero

30
         Err(_) => None,
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
             String::from("404 - Snippet not found"),
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
     let mut context: HashMap<&str, String> = HashMap::new();
48
     let mut context: HashMap<&str, String> = HashMap::new();
49
+    context.insert("id", id);
42
     context.insert("title", title);
50
     context.insert("title", title);
43
     context.insert("body", body);
51
     context.insert("body", body);
44
 
52
 

+ 24
- 11
templates/snippets/show.tera Ver fichero

2
   <head>
2
   <head>
3
     <title>{{ title }}</title>
3
     <title>{{ title }}</title>
4
     <style>
4
     <style>
5
-      pre {
5
+      .container {
6
+        margin: auto;
7
+        max-width: 800px;
8
+      }
9
+
10
+      .header__raw-link {
6
         font-size: 16px;
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
     </style>
23
     </style>
19
     <meta name="viewport" content="width=device-width">
24
     <meta name="viewport" content="width=device-width">
20
   </head>
25
   </head>
21
   <body>
26
   <body>
22
     <div class="container">
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
     </div>
40
     </div>
28
   </body>
41
   </body>
29
 </html>
42
 </html>

Loading…
Cancelar
Guardar