class Handlebars::Helpers::StringFormatting::SurroundIf

Surround If will surround a value with prefix and suffix, if value is not empty

Public Instance Methods

handlebars_helper() click to toggle source
# File lib/handlebars/helpers/string_formatting/surround_if.rb, line 33
def handlebars_helper
  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) click to toggle source

Parse will surround a value with prefix and suffix, if value is not empty

@example

puts SurroundIf.new.parse('product category', '["', '"]', 'titleize')

["Product Category"]

@param [String] value - value to surround @param [String] prefix - prefix to insert in front of value @param [String] suffix - suffix to append to value @param [String] formats - list of formats to apply to value, defaults to none @return [String] value surrounded by prefix and suffix

# File lib/handlebars/helpers/string_formatting/surround_if.rb, line 28
def parse(value, prefix, suffix, formats)
  format_as = Handlebars::Helpers::StringFormatting::FormatAs.new
  value.present? ? "#{prefix}#{format_as.parse(value, formats)}#{suffix}" : ''
end