Sha256: 04ab08acd4d41db3f971f6450c63fa9288c0c729941444d856a77ec0001db9c8

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

#!/usr/bin/env bash
set -o errexit

: ${language=en}
: ${charset=utf-8}
: ${viewport='width=device-width'}

--language() { language=$1; }
--attributes() { attributes+=" $1"; }
--charset() { charset=$1; }
--viewport() { viewport=$1; }

preamble=(language attributes charset viewport)
is-preamble-keyword()
{ printf '%s\n' ${preamble[*]} | grep "^$1\$" >/dev/null; }
maybe-insert-preamble()
if ! `is-preamble-keyword $1`; then
  head+=("$(printf "$charset_tag" "$charset")")
  head+=("$(printf "$viewport_tag" "$viewport")")
  maybe-insert-preamble() { :; }
  for x in ${preamble[*]}; do
    eval 'function --'$x' { echo >&2 $0: '$x' must come first; }'
  done; fi

: ${html_tag:='<html lang="%s"%s>'}
: ${charset_tag:='<meta charset="%s">'}
: ${viewport_tag:='<meta name="viewport" content="%s">'}
: ${title_tag:='<title>%s</title>'}
: ${javascript_tag:='<script src="%s"></script>'}
: ${stylesheet_tag:='<link rel="stylesheet" href="%s">'}

--head() { head+=("$1"); }
--body() { body+=("$1"); }
--foot() { foot+=("$1"); }
--title() { --head "$(printf "$title_tag" "$1")"; }
--stylesheet() { --head "$(printf "$stylesheet_tag" "$1")"; }
--javascript() { --foot "$(printf "$javascript_tag" "$1")"; }
--asset() case "$1" in
  *.css) --stylesheet "$1";;
  *.js) --javascript "$1";;
  *) echo >&2 "$0: $1: ignoring unknown asset";; esac

while read keyword words; do
  if [[ $keyword ]]; then
    keyword=$(echo $keyword | tr A-Z a-z | sed 's/:$//')
    [[ $words ]] || words=$keyword keyword=asset
    if type >&/dev/null -- "--$keyword"; then
      maybe-insert-preamble $keyword
      --$keyword "${words[@]}"
    elif [[ $keyword != '#' ]]; then
      echo >&2 "$0: unknown keyword \`$keyword'"; fi
  else
    while read line; do --body "$line"; done; fi; done

maybe-insert-preamble
body=("${body[@]}" "${foot[@]}")
sed 's/^ *$//' <<EOF
<!doctype html>
`printf "$html_tag" "$language" "$attributes"`
  <head>`[[ $head ]] && printf '\n    %s' "${head[@]}"`
  </head>
  <body>`[[ $body ]] && printf '\n    %s' "${body[@]}"`
  </body>
</html>
EOF

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grounds-0.0.1 bin/grounds