Skip to content

Instantly share code, notes, and snippets.

@feupeu
Created October 29, 2015 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feupeu/d694139353eef1e222ad to your computer and use it in GitHub Desktop.
Save feupeu/d694139353eef1e222ad to your computer and use it in GitHub Desktop.
(define (tag id content styles)
(string-append
"<" id
; Check if we should add anything inside the style property
(if (null? styles)
""
(string-append
" style='"
(apply string-append styles)
"'"
)
)
; Check if any content between tags i.e. <p>x</p>
(if (null? content)
; No content to include in the tag, let it auto-close
" /"
; Display the provided content
(string-append ">" content "</" id)
)
">"
)
)
; Generates the style property for a html tag
(define (style id value)
(string-append id ": " value ";")
)
; Will generate a table based on a header and some rows
(define (table header rows)
(tag "table"
(string-append
header
(apply string-append rows)
)
(list
(style "border" "1px solid black")
)
)
)
; Generates a table header based on some columns
(define (table-header columns)
(tag
"tr"
(apply string-append (map table-header-cell columns))
(list (style "font-weight" "bold")) ; Make text bold
)
)
; Generates a table row based on some columns
(define (table-row columns)
(tag
"tr"
(apply string-append (map table-std-cell columns))
'()
)
)
(define (table-std-cell content)
(tag
"td"
content
(list
(style "border" "1px solid black")
(style "padding" "0.5em 1em")
(style "text-align" "center")
)
)
)
(define (table-header-cell content)
(tag
"th"
content
(list
(style "border" "1px solid black")
(style "background" "lightgray")
(style "padding" "0.5em 1em")
)
)
)
(define (document headcontent bodycontent)
(string-append
(tag "html"
(string-append
(tag "head"
headcontent
'() ; no style
)
(tag "body"
bodycontent
'() ; no style
)
)
'() ; no style
)
)
)
#|
(define debug
(document "" (tag "p" "hej" (list (style "color" "black"))))
)
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment