class Handlebars::Helpers::StringFormatting::PrependIf

Append If will prepend the prefix to value, if value is not empty

Public Instance Methods

handlebars_helper() click to toggle source
# File lib/handlebars/helpers/string_formatting/prepend_if.rb, line 32
def handlebars_helper
  proc do |_context, value, prefix, formats|
    # Handle optional: formats
    formats = nil if formats.is_a?(V8::Object)
    wrapper(parse(value, prefix, formats))
  end
end
parse(value, prefix, formats) click to toggle source

Parse will Append If will prepend the prefix to value, if value is not empty

@example

puts PrependIf.new.parse('turn to symbol', ':', 'snake')

:turn_to_symbol

@param [String] value - value to add prepend too @param [String] prefix - prefix to insert in front of value @param [String] formats - list of formats to apply to value, defaults to none @return [String] prefix + value when value exists, otherwise ''

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