From 8446c0a6b4fa5bbdbbe74899ff858f645d8dc6e2 Mon Sep 17 00:00:00 2001 From: William Melody Date: Mon, 6 Nov 2023 22:37:25 -0800 Subject: [PATCH] Enable assigning custom CSS & JS as content or URL. --- nb | 26 ++++++++++++++++++---- test/browse.bats | 57 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/nb b/nb index 08cd30eba..ca50c6333 100755 --- a/nb +++ b/nb @@ -10599,8 +10599,10 @@ _render() { _render_print_head() { local _custom_css="${NB_CUSTOM_CSS:-}" local _custom_css_element= + local _custom_css_url="${NB_CUSTOM_CSS_URL:-}" local _custom_javascript="${NB_CUSTOM_JAVASCRIPT:-${NB_CUSTOM_JS:-}}" local _custom_javascript_element= + local _custom_javascript_url="${NB_CUSTOM_JAVASCRIPT_URL:-${NB_CUSTOM_JS_URL:-}}" local _html_title="${_ME}" if [[ "${1:-}" == "--title" ]] && [[ -n "${2:-}" ]] @@ -10663,14 +10665,28 @@ _render() { esac fi - if [[ -n "${_custom_javascript:-}" ]] + if [[ -n "${_custom_javascript:-}" ]] then - _custom_javascript_element="" + _custom_javascript_element="\ +" fi - if [[ -n "${_custom_css:-}" ]] + if [[ -n "${_custom_javascript_url:-}" ]] then - _custom_css_element="" + _custom_javascript_url_element="\ +" + fi + + if [[ -n "${_custom_css:-}" ]] + then + _custom_css_element="\ +" + fi + + if [[ -n "${_custom_css_url:-}" ]] + then + _custom_css_url_element="\ +" fi cat < +${_custom_css_url_element:-} +${_custom_javascript_url_element:-} ${_custom_css_element:-} ${_custom_javascript_element:-} diff --git a/test/browse.bats b/test/browse.bats index 36aa04501..87a54c7e6 100644 --- a/test/browse.bats +++ b/test/browse.bats @@ -29,11 +29,10 @@ load test_helper sleep 1 declare _custom_css=".example { color: blue; }" - declare _custom_js= - _custom_js="$(cat < ]] +\${_NEWLINE}.example\ {\ color:\ blue\;\ }${_NEWLINE}\ ]] [[ "${output}" =~ \ -\\ ]] +\${_NEWLINE}function\ example\(\)\ {\ console.log\(\"Example.\"\)\;\ }${_NEWLINE}\ ]] NB_CUSTOM_CSS="${_custom_css:-}" \ NB_CUSTOM_JAVASCRIPT="${_custom_js:-}" \ @@ -59,10 +60,48 @@ HEREDOC [[ "${status}" -eq 0 ]] + [[ ! "${output}" =~ \${_NEWLINE}.example\ {\ color:\ blue\;\ }${_NEWLINE}\ ]] + [[ "${output}" =~ \ +\${_NEWLINE}function\ example\(\)\ {\ console.log\(\"Example.\"\)\;\ }${_NEWLINE}\ ]] + + NB_CUSTOM_CSS_URL="${_custom_css_url:-}" \ + NB_CUSTOM_JS_URL="${_custom_js_url:-}" \ + run "${_NB}" browse --print + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + [[ "${status}" -eq 0 ]] + + [[ "${output}" =~ \ +\ ]] + [[ "${output}" =~ \ +\\ ]] + [[ ! "${output}" =~ \ +\${_NEWLINE}.example\ {\ color:\ blue\;\ }${_NEWLINE}\ ]] + [[ ! "${output}" =~ \ +\${_NEWLINE}function\ example\(\)\ {\ console.log\(\"Example.\"\)\;\ }${_NEWLINE}\ ]] + + NB_CUSTOM_CSS_URL="${_custom_css_url:-}" \ + NB_CUSTOM_JAVASCRIPT_URL="${_custom_js_url:-}" \ + run "${_NB}" browse --print + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + [[ "${status}" -eq 0 ]] + [[ "${output}" =~ \ -\ ]] +\ ]] [[ "${output}" =~ \ -\\ ]] +\\ ]] + [[ ! "${output}" =~ \ +\${_NEWLINE}.example\ {\ color:\ blue\;\ }${_NEWLINE}\ ]] + [[ ! "${output}" =~ \ +\${_NEWLINE}function\ example\(\)\ {\ console.log\(\"Example.\"\)\;\ }${_NEWLINE}\ ]] } # configuration ###############################################################