Added configuration for diff2html
This commit is contained in:
+37
-1
@@ -6,10 +6,13 @@
|
||||
xml
|
||||
racket/string
|
||||
"config.rkt"
|
||||
"utils.rkt"
|
||||
)
|
||||
|
||||
(provide diff->html
|
||||
show->html)
|
||||
show->html
|
||||
config-diff2html
|
||||
)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Helper functions
|
||||
@@ -57,6 +60,39 @@
|
||||
;; Exported functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (config-diff2html)
|
||||
|
||||
(define (checker f)
|
||||
(λ (inp)
|
||||
(let ((url (string-trim inp)))
|
||||
(if (string=? url "")
|
||||
(f)
|
||||
(if (valid-http-or-file-url? url)
|
||||
url
|
||||
(begin
|
||||
(displayln "! Not a valid url, please input a valid url")
|
||||
#f)))))
|
||||
)
|
||||
|
||||
(define (inp name f)
|
||||
(input-prompt (string-join
|
||||
(list
|
||||
(format "Give the url for the ~a" name)
|
||||
"Enter keeps the current value:"
|
||||
(string-append " - " (f))
|
||||
">")
|
||||
"\n")
|
||||
#:loop-until (checker f)))
|
||||
|
||||
(let ((h-css (inp "Highlighting CSS" highlight-css))
|
||||
(d-css (inp "Diff2Html CSS" diff2html-min-css))
|
||||
(d-js (inp "Diff2Html UI Javascript" diff2html-ui-min-js))
|
||||
)
|
||||
(cfg-set! 'diff 'highlight-css h-css)
|
||||
(cfg-set! 'diff 'diff2html-min-css d-css)
|
||||
(cfg-set! 'diff 'diff2html-ui-min-js d-js))
|
||||
)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; goal : Render a Git diff in a temporary HTML file.
|
||||
; pre : diff is a unified Git diff string.
|
||||
|
||||
+29
-1
@@ -1,4 +1,32 @@
|
||||
#lang racket/base
|
||||
|
||||
(provide config)
|
||||
(require net/url)
|
||||
|
||||
(provide input-prompt
|
||||
valid-http-or-file-url?
|
||||
)
|
||||
|
||||
(define (input-prompt p #:loop-until [until (λ (x) x)])
|
||||
(let loop ()
|
||||
(display p)
|
||||
(flush-output)
|
||||
(let ((inp (read-line)))
|
||||
(let ((i (until inp)))
|
||||
(if i
|
||||
i
|
||||
(loop)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
(define (valid-http-or-file-url? value)
|
||||
(if (not (string? value))
|
||||
#f
|
||||
(with-handlers ([exn:fail? (λ (exn) #f)])
|
||||
(let ((url (string->url value)))
|
||||
(and
|
||||
(member (url-scheme url) '("http" "https" "file"))
|
||||
(string? (url-host url))
|
||||
(not (string=? (url-host url) "")))))))
|
||||
Reference in New Issue
Block a user