Class: Handlebars::Helpers::StringFormatting::AppendIf
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::StringFormatting::AppendIf
- Defined in:
- lib/handlebars/helpers/string_formatting/append_if.rb
Overview
Append If will append suffix to value, if value is not empty
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, suffix, formats) ⇒ String
Parse will Append If will append suffix to value, 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
32 33 34 35 36 37 38 |
# File 'lib/handlebars/helpers/string_formatting/append_if.rb', line 32 def 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) ⇒ String
Parse will Append If will append suffix to value, if value is not empty
27 28 29 30 |
# File 'lib/handlebars/helpers/string_formatting/append_if.rb', line 27 def parse(value, suffix, formats) format_as = ::Helpers::StringFormatting::FormatAs.new value.present? ? "#{format_as.parse(value, formats)}#{suffix}" : '' end |