Skip to content

Commit

Permalink
add header/footer to template
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
nickjer authored Apr 5, 2018
1 parent d95ff10 commit c37c3e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
20 changes: 16 additions & 4 deletions lib/ood_core/batch_connect/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c37c3e4

Please sign in to comment.