Class: Handlebars::Helpers::StringFormatting::PrependIf
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::StringFormatting::PrependIf
- Defined in:
- lib/handlebars/helpers/string_formatting/prepend_if.rb
Overview
Append If will prepend the prefix to value, if value is not empty
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, prefix, formats) ⇒ String
Parse will Append If will prepend the prefix 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/prepend_if.rb', line 32 def 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) ⇒ String
Parse will Append If will prepend the prefix to value, if value is not empty
27 28 29 30 |
# 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 |