defs.rkt 3.59 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
(require scribble/decode)
4
(require scribble/manual)
5 6
(require racket/class)
(require racket/draw)
7 8
(require racket/system)
(require racket/port)
9
(require racket/vector)
10
(require racket/file)
Robert Ricci's avatar
Robert Ricci committed
11 12 13

(provide (all-defined-out))

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

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

23 24 25 26 27 28 29 30
; 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))

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

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

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

44
(define (clab-only . stuff)
45
  (apt-vs-clab #:clab stuff))
46

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

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

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

62
(define tb (lambda () (if (clab?) "CloudLab" "Apt")))
63

64 65 66 67
; 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"))))
68

69 70
; Arbitrary width that works reasonably well with the manual class's main
; column width
71 72 73 74 75 76
(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
77

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

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

89
(define (screenshot path)
90 91 92 93 94 95 96
  (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))))]
97 98
         [b (make-object bitmap% fullpath)]
         [width (send b get-width)]
Robert Ricci's avatar
Robert Ricci committed
99
         [scale-factor (* 1.0 (/ screenshot-width width))])
100 101 102
    (list (image #:scale scale-factor fullpath fullpath) (linebreak))))

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

(define (under-construction)
  (bold "This section is under construction"))
112 113 114 115 116

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

(define (ssh)
  (tt "ssh"))
120 121

(define (code-sample filename)
122
  (code-inset (verbatim (file->string (string-append "code-samples/" filename)))))