Class: Handlebars::Helpers::StringFormatting::Padl
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::StringFormatting::Padl
- Defined in:
- lib/handlebars/helpers/string_formatting/padl.rb
Overview
Add padding to the left of the value.
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, count, char) ⇒ String
Parse will Add padding to the left of the value.
Methods inherited from BaseSafeStringHelper
Methods inherited from BaseHelper
#parse_json, #struct_to_hash, #tokenizer, #wrapper
Instance Method Details
#handlebars_helper ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/handlebars/helpers/string_formatting/padl.rb', line 46 def proc do |_context, value, count, char| # Handle optional: value, count and char value = nil if value.is_a?(V8::Object) count = nil if count.is_a?(V8::Object) char = nil if char.is_a?(V8::Object) wrapper(parse(value, count, char)) end end |
#parse(value, count, char) ⇒ String
Parse will Add padding to the left of the value.
38 39 40 41 42 43 44 |
# File 'lib/handlebars/helpers/string_formatting/padl.rb', line 38 def parse(value, count, char) value = '' if value.nil? count = ::Helpers.configuration.padl_count if count.nil? count = count.to_i if count.is_a?(String) char = ::Helpers.configuration.padl_char if char.nil? value.to_s.rjust(count, char) end |