defs.rkt 3.43 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1
#lang racket/base
Robert Ricci's avatar
Robert Ricci committed
2
(require scribble/base)
3 4 5
(require scribble/decode)
(require racket/class)
(require racket/draw)
6 7
(require racket/system)
(require racket/port)
8
(require racket/vector)
Robert Ricci's avatar
Robert Ricci committed
9 10 11

(provide (all-defined-out))

12 13
; Check to see if we are building Apt or CloudLab documentation
(define tb-mode 
14 15
  (if (vector-member "clab" (current-command-line-arguments))
    'clab
16 17
    'apt))

18
(define (apt?) (if (equal? tb-mode 'apt) #t #f))
19
(define (clab?)  (if (equal? tb-mode 'clab) #t #f))
20

21 22 23 24 25 26 27 28
; Check to see if we are building for web or PDF; there is probably some
; nicer way to do this by inspecting the scribble/run state directly, but
; I haven't figured it out
(define doc-mode
    (if (vector-member "pdf" (current-command-line-arguments))
      'pdf
      'html))

29
(define (apt-vs-clab #:apt [apt-version (list)] #:clab [clab-version (list)])
30 31
  (if (apt?)
    apt-version
32
    clab-version))
33

34
(define (apt-vs-clab* #:apt [apt-version ""] #:clab [clab-version ""])
35
  (decode-flow (list (if (apt?)
36 37 38
                          apt-version
                          clab-version))))

39
(define (apt-only . stuff)
40
  (apt-vs-clab #:apt stuff))
41

42
(define (clab-only . stuff)
43
  (apt-vs-clab #:clab stuff))
44

45
(define apt-base-url
46
  (if (clab?)
47
    "https://www.cloudlab.us/"
48 49
    "https://www.aptlab.net/"))

50 51 52
(define apt-doc-url
  (if (clab?)
    "http://docs.cloudlab.us/"
53
    "http://docs.aptlab.net/"))
54

55 56 57 58 59
(define forum-url 
  (if (apt?)
    "https://groups.google.com/forum/#!forum/apt-users"
    "https://groups.google.com/forum/#!forum/cloudlab-users"))

60
(define tb (lambda () (if (clab?) "CloudLab" "Apt")))
61

62 63 64 65
; We want the 'version' to be the date of the most recent commit
(define apt-version
  (with-output-to-string
    (lambda () (system "git show -s --date=short --format='%cd (%h)' HEAD"))))
66

67 68
; Arbitrary width that works reasonably well with the manual class's main
; column width
69 70 71 72 73 74
(define screenshot-width 650)

(define apturl
  (case-lambda
    [() apt-base-url]
    [(page) (string-append apt-base-url page)]))
Robert Ricci's avatar
Robert Ricci committed
75

76
(define (TODO . what)
77
  (bold "TODO: " (decode-content what)))
78 79 80 81 82 83 84 85

(define nodetype
  (lambda (typename howmany . properties)
          (tabular #:style 'boxed #:sep (hspace 3)
                   (cons
                     (list (bold typename)
                           (string-append (number->string howmany) " nodes"))
                     properties))))
86

87
(define (screenshot path)
88 89 90 91 92 93 94
  (let* ([aptpath (string-append "screenshots/apt/" path)]
         [clabpath (string-append "screenshots/clab/" path)]
         [fullpath (if (apt?)
                     aptpath
                     (if (file-exists? clabpath)
                       clabpath
                       (cdr (cons (displayln (string-append "WARNING: CloudLab missing screenshot " path)) aptpath))))]
95 96
         [b (make-object bitmap% fullpath)]
         [width (send b get-width)]
Robert Ricci's avatar
Robert Ricci committed
97
         [scale-factor (* 1.0 (/ screenshot-width width))])
98 99 100
    (list (image #:scale scale-factor fullpath fullpath) (linebreak))))

(define (instructionstep step #:screenshot [screenshot-path #f] . body)
101 102
  (item (bold (decode-content (list step)))
        (linebreak)
103 104
        (if screenshot-path
          (screenshot  screenshot-path)
105 106
          (void))
        (decode-content body)))
107 108 109

(define (under-construction)
  (bold "This section is under construction"))
110 111 112 113 114

(define (future-work tag)
  (margin-note "There are planned features relating to this section: see \""
               (secref tag)
               "\" for more details."))
115 116 117

(define (ssh)
  (tt "ssh"))