class Handlebars::Helpers::StringFormatting::Surround

Surround will surround a value with prefix and suffix, an empty value is considered valid data

Public Instance Methods

handlebars_helper() click to toggle source
# File lib/handlebars/helpers/string_formatting/surround.rb, line 39
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, an empty value is considered valid data

@example

puts Surround.new.parse('product category', '"', '"', 'titleize')

"Product Category"

@example

puts Surround.new.parse(nil, '"', '"', 'titleize')

""

@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] prefix + value + suffix

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