class Handlebars::Helpers::StringFormatting::AppendIf
Append If will append suffix to value, if value is not empty
Public Instance Methods
handlebars_helper()
click to toggle source
# File lib/handlebars/helpers/string_formatting/append_if.rb, line 32 def handlebars_helper proc do |_context, value, suffix, formats| # Handle optional: formats formats = nil if formats.is_a?(V8::Object) wrapper(parse(value, suffix, formats)) end end
parse(value, suffix, formats)
click to toggle source
Parse will Append If will append suffix to value, if value is not empty
@example
puts AppendIf.new.parse('the quick brown', 'fox', 'dashify') the-quick-brown-fox
@param [String] value - value to add suffix too @param [String] suffix - suffix to add to value @param [String] formats - list of formats to apply to value, defaults to none @return [String] value + suffix when value exists, otherwise ''
# File lib/handlebars/helpers/string_formatting/append_if.rb, line 27 def parse(value, suffix, formats) format_as = Handlebars::Helpers::StringFormatting::FormatAs.new value.present? ? "#{format_as.parse(value, formats)}#{suffix}" : '' end