From c37c3e4357c36e05b8dcb141aefa25ead84e24a1 Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Thu, 5 Apr 2018 14:34:38 -0400 Subject: [PATCH] add header/footer to template Fixes #64 --- CHANGELOG.md | 2 ++ lib/ood_core/batch_connect/template.rb | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c827c6b35..541112f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. argument. [#24](https://github.com/OSC/ood_core/issues/24) - Added `OodCore::Job::Script#shell_path` as an option to all adapters. [#82](https://github.com/OSC/ood_core/issues/82) +- Added `header` and `footer` options to a Batch Connect template. + [#64](https://github.com/OSC/ood_core/issues/64) ### Fixed - Replaced `Fixnum` code comments with `Integer`. diff --git a/lib/ood_core/batch_connect/template.rb b/lib/ood_core/batch_connect/template.rb index 1ca515156..f515fe871 100644 --- a/lib/ood_core/batch_connect/template.rb +++ b/lib/ood_core/batch_connect/template.rb @@ -26,6 +26,10 @@ class Template # looking for available port # @option context [#to_i] :passwd_size (32) Length of randomly generated # password + # @option context [#to_s] :header ("") Shell code prepended at the top of + # the script body + # @option context [#to_s] :footer ("") Shell code appended at the bottom + # of the script body # @option context [#to_s] :script_wrapper ("%s") Bash code that wraps # around the body of the template script (use `%s` to interpolate the # body) @@ -58,11 +62,9 @@ def initialize(context = {}) # @return [String] rendered template def to_s <<-EOT.gsub(/^ {10}/, '') - # - # Generated with ood_core v#{VERSION} - # - + #{header} #{script_wrapper} + #{footer} EOT end @@ -150,6 +152,16 @@ def bash_helpers end.to_s end + # Shell code that is prepended at the top of the script body + def header + context.fetch(:header, "").to_s + end + + # Shell code that is appended at the bottom of the script body + def footer + context.fetch(:footer, "").to_s + end + # Bash code that wraps around the body of the template script (use `%s` # to interpolate the body) def script_wrapper