Sha256: 59c405fd6113a9bec18900e3431e6d30bf0d80a41c17ac8a85d5edd32f77ee7b
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
module Locomotive module Steam module Liquid module Filters module Misc # was called modulo at first def str_modulo(word, index, modulo) (index.to_i + 1) % modulo == 0 ? word : '' end # Get the nth element of the passed in array def index(array, position) array.at(position) if array.respond_to?(:at) end def default(input, value) input.blank? ? value : input end def random(input) rand(input.to_i) end # map/collect on a given property (support to_f, to_i) def map(input, property) flatten_if_necessary(input).map do |e| e = e.call if e.is_a?(Proc) if property == "to_liquid" e elsif property == "to_f" e.to_f elsif property == "to_i" e.to_i elsif e.respond_to?(:[]) e[property] end end end end ::Liquid::Template.register_filter(Misc) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems