Browse Source

Do syntax highlighting

master
Dylan Baker 5 years ago
parent
commit
b7928e7eec
5 changed files with 249 additions and 19 deletions
  1. 200
    0
      Cargo.lock
  2. 1
    0
      Cargo.toml
  3. 1
    0
      src/main.rs
  4. 33
    1
      src/routes.rs
  5. 14
    18
      templates/gists/show.tera

+ 200
- 0
Cargo.lock View File

@@ -1,5 +1,10 @@
1 1
 # This file is automatically @generated by Cargo.
2 2
 # It is not intended for manual editing.
3
+[[package]]
4
+name = "adler32"
5
+version = "1.0.3"
6
+source = "registry+https://github.com/rust-lang/crates.io-index"
7
+
3 8
 [[package]]
4 9
 name = "aho-corasick"
5 10
 version = "0.6.10"
@@ -65,6 +70,16 @@ dependencies = [
65 70
  "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
66 71
 ]
67 72
 
73
+[[package]]
74
+name = "bincode"
75
+version = "1.1.3"
76
+source = "registry+https://github.com/rust-lang/crates.io-index"
77
+dependencies = [
78
+ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
79
+ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
80
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
81
+]
82
+
68 83
 [[package]]
69 84
 name = "bitflags"
70 85
 version = "0.7.0"
@@ -94,6 +109,11 @@ dependencies = [
94 109
  "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
95 110
 ]
96 111
 
112
+[[package]]
113
+name = "build_const"
114
+version = "0.2.1"
115
+source = "registry+https://github.com/rust-lang/crates.io-index"
116
+
97 117
 [[package]]
98 118
 name = "byte-tools"
99 119
 version = "0.3.1"
@@ -144,6 +164,22 @@ dependencies = [
144 164
  "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
145 165
 ]
146 166
 
167
+[[package]]
168
+name = "crc"
169
+version = "1.8.1"
170
+source = "registry+https://github.com/rust-lang/crates.io-index"
171
+dependencies = [
172
+ "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
173
+]
174
+
175
+[[package]]
176
+name = "crc32fast"
177
+version = "1.2.0"
178
+source = "registry+https://github.com/rust-lang/crates.io-index"
179
+dependencies = [
180
+ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
181
+]
182
+
147 183
 [[package]]
148 184
 name = "deunicode"
149 185
 version = "0.4.3"
@@ -239,6 +275,22 @@ dependencies = [
239 275
  "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
240 276
 ]
241 277
 
278
+[[package]]
279
+name = "flate2"
280
+version = "1.0.7"
281
+source = "registry+https://github.com/rust-lang/crates.io-index"
282
+dependencies = [
283
+ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
284
+ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
285
+ "miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
286
+ "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
287
+]
288
+
289
+[[package]]
290
+name = "fnv"
291
+version = "1.0.6"
292
+source = "registry+https://github.com/rust-lang/crates.io-index"
293
+
242 294
 [[package]]
243 295
 name = "fsevent"
244 296
 version = "0.2.17"
@@ -298,6 +350,7 @@ dependencies = [
298 350
  "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
299 351
  "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
300 352
  "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
353
+ "syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
301 354
 ]
302 355
 
303 356
 [[package]]
@@ -315,6 +368,14 @@ name = "humansize"
315 368
 version = "1.1.0"
316 369
 source = "registry+https://github.com/rust-lang/crates.io-index"
317 370
 
371
+[[package]]
372
+name = "humantime"
373
+version = "1.2.0"
374
+source = "registry+https://github.com/rust-lang/crates.io-index"
375
+dependencies = [
376
+ "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
377
+]
378
+
318 379
 [[package]]
319 380
 name = "hyper"
320 381
 version = "0.10.16"
@@ -420,6 +481,19 @@ name = "libc"
420 481
 version = "0.2.53"
421 482
 source = "registry+https://github.com/rust-lang/crates.io-index"
422 483
 
484
+[[package]]
485
+name = "line-wrap"
486
+version = "0.1.1"
487
+source = "registry+https://github.com/rust-lang/crates.io-index"
488
+dependencies = [
489
+ "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
490
+]
491
+
492
+[[package]]
493
+name = "linked-hash-map"
494
+version = "0.5.2"
495
+source = "registry+https://github.com/rust-lang/crates.io-index"
496
+
423 497
 [[package]]
424 498
 name = "lock_api"
425 499
 version = "0.1.5"
@@ -468,6 +542,34 @@ dependencies = [
468 542
  "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
469 543
 ]
470 544
 
545
+[[package]]
546
+name = "miniz-sys"
547
+version = "0.1.11"
548
+source = "registry+https://github.com/rust-lang/crates.io-index"
549
+dependencies = [
550
+ "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
551
+ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
552
+]
553
+
554
+[[package]]
555
+name = "miniz_oxide"
556
+version = "0.2.1"
557
+source = "registry+https://github.com/rust-lang/crates.io-index"
558
+dependencies = [
559
+ "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
560
+]
561
+
562
+[[package]]
563
+name = "miniz_oxide_c_api"
564
+version = "0.2.1"
565
+source = "registry+https://github.com/rust-lang/crates.io-index"
566
+dependencies = [
567
+ "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
568
+ "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
569
+ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
570
+ "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
571
+]
572
+
471 573
 [[package]]
472 574
 name = "mio"
473 575
 version = "0.6.16"
@@ -557,6 +659,26 @@ dependencies = [
557 659
  "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
558 660
 ]
559 661
 
662
+[[package]]
663
+name = "onig"
664
+version = "4.3.2"
665
+source = "registry+https://github.com/rust-lang/crates.io-index"
666
+dependencies = [
667
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
668
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
669
+ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
670
+ "onig_sys 69.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
671
+]
672
+
673
+[[package]]
674
+name = "onig_sys"
675
+version = "69.1.0"
676
+source = "registry+https://github.com/rust-lang/crates.io-index"
677
+dependencies = [
678
+ "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
679
+ "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
680
+]
681
+
560 682
 [[package]]
561 683
 name = "opaque-debug"
562 684
 version = "0.2.2"
@@ -655,6 +777,24 @@ dependencies = [
655 777
  "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
656 778
 ]
657 779
 
780
+[[package]]
781
+name = "pkg-config"
782
+version = "0.3.14"
783
+source = "registry+https://github.com/rust-lang/crates.io-index"
784
+
785
+[[package]]
786
+name = "plist"
787
+version = "0.4.1"
788
+source = "registry+https://github.com/rust-lang/crates.io-index"
789
+dependencies = [
790
+ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
791
+ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
792
+ "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
793
+ "line-wrap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
794
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
795
+ "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
796
+]
797
+
658 798
 [[package]]
659 799
 name = "pq-sys"
660 800
 version = "0.4.6"
@@ -671,6 +811,11 @@ dependencies = [
671 811
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
672 812
 ]
673 813
 
814
+[[package]]
815
+name = "quick-error"
816
+version = "1.2.2"
817
+source = "registry+https://github.com/rust-lang/crates.io-index"
818
+
674 819
 [[package]]
675 820
 name = "quote"
676 821
 version = "0.6.12"
@@ -1052,6 +1197,27 @@ dependencies = [
1052 1197
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1053 1198
 ]
1054 1199
 
1200
+[[package]]
1201
+name = "syntect"
1202
+version = "3.2.0"
1203
+source = "registry+https://github.com/rust-lang/crates.io-index"
1204
+dependencies = [
1205
+ "bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
1206
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
1207
+ "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
1208
+ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1209
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1210
+ "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
1211
+ "onig 4.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
1212
+ "plist 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
1213
+ "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
1214
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
1215
+ "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
1216
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
1217
+ "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
1218
+ "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
1219
+]
1220
+
1055 1221
 [[package]]
1056 1222
 name = "tera"
1057 1223
 version = "0.11.20"
@@ -1282,6 +1448,19 @@ dependencies = [
1282 1448
  "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1283 1449
 ]
1284 1450
 
1451
+[[package]]
1452
+name = "xml-rs"
1453
+version = "0.8.0"
1454
+source = "registry+https://github.com/rust-lang/crates.io-index"
1455
+
1456
+[[package]]
1457
+name = "yaml-rust"
1458
+version = "0.4.3"
1459
+source = "registry+https://github.com/rust-lang/crates.io-index"
1460
+dependencies = [
1461
+ "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
1462
+]
1463
+
1285 1464
 [[package]]
1286 1465
 name = "yansi"
1287 1466
 version = "0.4.0"
@@ -1293,6 +1472,7 @@ version = "0.5.0"
1293 1472
 source = "registry+https://github.com/rust-lang/crates.io-index"
1294 1473
 
1295 1474
 [metadata]
1475
+"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c"
1296 1476
 "checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
1297 1477
 "checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c"
1298 1478
 "checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5"
@@ -1301,10 +1481,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1301 1481
 "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
1302 1482
 "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
1303 1483
 "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
1484
+"checksum bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "959c8e54c1ad412ffeeb95f05a9cade02d2d40a7b3c2f852d3353148f4beff35"
1304 1485
 "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
1305 1486
 "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
1306 1487
 "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
1307 1488
 "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09"
1489
+"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
1308 1490
 "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
1309 1491
 "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
1310 1492
 "checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d"
@@ -1312,6 +1494,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1312 1494
 "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
1313 1495
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1314 1496
 "checksum cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1465f8134efa296b4c19db34d909637cb2bf0f7aaf21299e23e18fa29ac557cf"
1497
+"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
1498
+"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
1315 1499
 "checksum deunicode 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
1316 1500
 "checksum devise 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74e04ba2d03c5fa0d954c061fc8c9c288badadffc272ebb87679a89846de3ed3"
1317 1501
 "checksum devise_codegen 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7"
@@ -1323,6 +1507,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1323 1507
 "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
1324 1508
 "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
1325 1509
 "checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d"
1510
+"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa"
1511
+"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
1326 1512
 "checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05"
1327 1513
 "checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874"
1328 1514
 "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
@@ -1332,6 +1518,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1332 1518
 "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
1333 1519
 "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
1334 1520
 "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
1521
+"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
1335 1522
 "checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273"
1336 1523
 "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
1337 1524
 "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
@@ -1345,6 +1532,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1345 1532
 "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
1346 1533
 "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
1347 1534
 "checksum libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "ec350a9417dfd244dc9a6c4a71e13895a4db6b92f0b106f07ebbc3f3bc580cee"
1535
+"checksum line-wrap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9"
1536
+"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
1348 1537
 "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
1349 1538
 "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
1350 1539
 "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
@@ -1352,6 +1541,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1352 1541
 "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
1353 1542
 "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
1354 1543
 "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
1544
+"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
1545
+"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e"
1546
+"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab"
1355 1547
 "checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
1356 1548
 "checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40"
1357 1549
 "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
@@ -1360,6 +1552,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1360 1552
 "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
1361 1553
 "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
1362 1554
 "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
1555
+"checksum onig 4.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a646989adad8a19f49be2090374712931c3a59835cb5277b4530f48b417f26e7"
1556
+"checksum onig_sys 69.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388410bf5fa341f10e58e6db3975f4bea1ac30247dd79d37a9e5ced3cb4cc3b0"
1363 1557
 "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409"
1364 1558
 "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
1365 1559
 "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337"
@@ -1371,8 +1565,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1371 1565
 "checksum pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
1372 1566
 "checksum pest_generator 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63120576c4efd69615b5537d3d052257328a4ca82876771d6944424ccfd9f646"
1373 1567
 "checksum pest_meta 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f249ea6de7c7b7aba92b4ff4376a994c6dbd98fd2166c89d5c4947397ecb574d"
1568
+"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
1569
+"checksum plist 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f4739851c08dd9a62a78beff2edf1a438517268b2c563c42fc6d9d3139e42d2a"
1374 1570
 "checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
1375 1571
 "checksum proc-macro2 0.4.29 (registry+https://github.com/rust-lang/crates.io-index)" = "64c827cea7a7ab30ce4593e5e04d7a11617ad6ece2fa230605a78b00ff965316"
1572
+"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
1376 1573
 "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
1377 1574
 "checksum r2d2 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9dd8a293251281a4d02848925fcdbbc9f466ddb4965981bb06680359b3d12091"
1378 1575
 "checksum r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9c29bad92da76d02bc2c020452ebc3a3fe6fa74cfab91e711c43116e4fb1a3"
@@ -1416,6 +1613,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1416 1613
 "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
1417 1614
 "checksum state 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7345c971d1ef21ffdbd103a75990a15eb03604fc8b8852ca8cb418ee1a099028"
1418 1615
 "checksum syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)" = "ec52cd796e5f01d0067225a5392e70084acc4c0013fa71d55166d38a8b307836"
1616
+"checksum syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e80b8831c5a543192ffc3727f01cf0e57579c6ac15558e3048bfb5708892167b"
1419 1617
 "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3"
1420 1618
 "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
1421 1619
 "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
@@ -1448,5 +1646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1448 1646
 "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
1449 1647
 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1450 1648
 "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
1649
+"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5"
1650
+"checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d"
1451 1651
 "checksum yansi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d60c3b48c9cdec42fb06b3b84b5b087405e1fa1c644a1af3930e4dfafe93de48"
1452 1652
 "checksum yansi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71"

+ 1
- 0
Cargo.toml View File

@@ -14,6 +14,7 @@ rocket = "0.4.0"
14 14
 serde = "1.0.82"
15 15
 serde_derive = "1.0.82"
16 16
 serde_json = "1.0.33"
17
+syntect = "3.2.0"
17 18
 
18 19
 [dependencies.rocket_contrib]
19 20
 version = "0.4.0"

+ 1
- 0
src/main.rs View File

@@ -11,6 +11,7 @@ extern crate rocket;
11 11
 extern crate rocket_contrib;
12 12
 #[macro_use]
13 13
 extern crate serde_derive;
14
+extern crate syntect;
14 15
 
15 16
 use dotenv::dotenv;
16 17
 use rocket_contrib::templates::Template;

+ 33
- 1
src/routes.rs View File

@@ -4,6 +4,9 @@ use rocket::response::status;
4 4
 use rocket_contrib::json::Json;
5 5
 use rocket_contrib::templates::Template;
6 6
 use std::collections::HashMap;
7
+use syntect::highlighting::ThemeSet;
8
+use syntect::html::highlighted_html_for_string;
9
+use syntect::parsing::SyntaxSet;
7 10
 
8 11
 use crate::connection::DbConn;
9 12
 use crate::gists;
@@ -30,7 +33,36 @@ pub fn show_gist(id: i32, connection: DbConn) -> Template {
30 33
         Err(_) => None,
31 34
     };
32 35
     let mut context = HashMap::new();
33
-    context.insert("gist", gist);
36
+
37
+    match gist {
38
+        Some(g) => {
39
+            let body = match g.filetype {
40
+                Some(filetype) => {
41
+                    let ps = SyntaxSet::load_defaults_newlines();
42
+                    let ts = ThemeSet::load_defaults();
43
+                    let syntax = ps.find_syntax_by_extension(&filetype);
44
+
45
+                    match syntax {
46
+                        Some(s) => highlighted_html_for_string(
47
+                            &g.body,
48
+                            &ps,
49
+                            s,
50
+                            &ts.themes["Solarized (light)"],
51
+                        ),
52
+                        None => format!("<pre class='plaintext'>{}</pre>", g.body),
53
+                    }
54
+                }
55
+                None => format!("<pre class='plaintext'>{}</pre>", g.body),
56
+            };
57
+            context.insert("title", g.title.clone());
58
+            context.insert("body", body);
59
+        }
60
+        None => {
61
+            context.insert("title", "404".to_string());
62
+            context.insert("body", "<h3>Gist not found</h3>".to_string());
63
+        }
64
+    }
65
+
34 66
     Template::render("gists/show", &context)
35 67
 }
36 68
 

+ 14
- 18
templates/gists/show.tera View File

@@ -1,32 +1,28 @@
1 1
 <html>
2 2
   <head>
3
-    <title>{% if gist %}{{ gist.title }}{% else %}404 - Not Found{% endif %}</title>
3
+    <title>{{ title }}</title>
4 4
     <style>
5 5
       pre {
6
-        counter-reset: line;
6
+        font-size: 16px;
7
+        padding: 15px;
7 8
       }
8
-      code {
9
-        counter-increment: line;
9
+
10
+      pre.plaintext {
11
+        padding: 0;
10 12
       }
11
-      code:before {
12
-        content: counter(line);
13
-        margin-right: 10px;
13
+
14
+      .container {
15
+        margin: auto;
16
+        max-width: 800px;
14 17
       }
15 18
     </style>
16 19
   </head>
17 20
   <body>
18
-    {% if gist %}
19
-      <h3>{{ gist.title }}</h3>
21
+    <div class="container">
22
+      <h1>{{ title }}</h3>
20 23
       <div>
21
-          {% set lines = gist.body | split(pat = '
22
-') %}
23
-        <pre>
24
-          {%- for line in lines %}<code id="{{ loop.index }}">{{ line }}</code>
25
-{% endfor %}
26
-        </pre>
24
+        {{ body | safe }}
27 25
       </div>
28
-    {% else %}
29
-      <h3>Gist not found</h3>
30
-    {% endif %}
26
+    </div>
31 27
   </body>
32 28
 </html>

Loading…
Cancel
Save