Class: Uniword::Template::Helpers::FilterHelper
- Inherits:
-
Object
- Object
- Uniword::Template::Helpers::FilterHelper
- Defined in:
- lib/uniword/template/helpers/filter_helper.rb
Overview
Helper for applying filters to template values.
Supports value transformations:
- format: Date/time formatting
- upcase: Uppercase text
- downcase: Lowercase text
- titleize: Title case text
- capitalize: Capitalize first letter
- currency: Format as currency
Syntax: | filter} or | filter: arg}
Responsibility: Filter application only Single Responsibility Principle: Does NOT parse or render
Instance Method Summary collapse
-
#apply(value, filter_name, *args) ⇒ Object
Apply filter to value.
Instance Method Details
#apply(value, filter_name, *args) ⇒ Object
Apply filter to value
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/uniword/template/helpers/filter_helper.rb', line 32 def apply(value, filter_name, *args) case filter_name.to_s when "format" apply_format(value, args.first || "%Y-%m-%d") when "upcase" value.to_s.upcase when "downcase" value.to_s.downcase when "titleize" titleize(value.to_s) when "capitalize" value.to_s.capitalize when "currency" apply_currency(value, args.first || "USD") when "number" apply_number_format(value, args.first) when "truncate" truncate(value.to_s, args.first&.to_i || 30) when "strip" value.to_s.strip when "reverse" value.to_s.reverse else # Unknown filter - return value unchanged value end end |