Class: Handlebars::Helpers::StringFormatting::SurroundIf
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::StringFormatting::SurroundIf
- Defined in:
- lib/handlebars/helpers/string_formatting/surround_if.rb
Overview
Surround If will surround a value with prefix and suffix, if value is not empty
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, prefix, suffix, formats) ⇒ String
Parse will surround a value with prefix and suffix, if value is not empty.
Methods inherited from BaseSafeStringHelper
Methods inherited from BaseHelper
#parse_json, #struct_to_hash, #tokenizer, #wrapper
Instance Method Details
#handlebars_helper ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/handlebars/helpers/string_formatting/surround_if.rb', line 33 def proc do |_context, value, prefix, suffix, formats| # Handle optional: formats formats = nil if formats.is_a?(V8::Object) wrapper(parse(value, prefix, suffix, formats)) end end |
#parse(value, prefix, suffix, formats) ⇒ String
Parse will surround a value with prefix and suffix, if value is not empty
28 29 30 31 |
# File 'lib/handlebars/helpers/string_formatting/surround_if.rb', line 28 def parse(value, prefix, suffix, formats) format_as = ::Helpers::StringFormatting::FormatAs.new value.present? ? "#{prefix}#{format_as.parse(value, formats)}#{suffix}" : '' end |