Module: Liquid::Rails::MiscFilter

Defined in:
lib/liquid4-rails/filters/misc_filter.rb

Instance Method Summary collapse

Instance Method Details

#index(array, position) ⇒ Object

Get the nth element of the passed in array



7
8
9
# File 'lib/liquid4-rails/filters/misc_filter.rb', line 7

def index(array, position)
  array.at(position) if array.respond_to?(:at)
end

#jsonify(object) ⇒ Object



15
16
17
# File 'lib/liquid4-rails/filters/misc_filter.rb', line 15

def jsonify(object)
  JSON.dump(object)
end

#random(input) ⇒ Object



11
12
13
# File 'lib/liquid4-rails/filters/misc_filter.rb', line 11

def random(input)
  rand(input.to_i)
end

#toggle_class_name(class_name, condition) ⇒ Object

If condition is true, the class_name is returned. Otherwise, it returns nil. class_name: css class name condition: boolean



22
23
24
# File 'lib/liquid4-rails/filters/misc_filter.rb', line 22

def toggle_class_name(class_name, condition)
  condition ? class_name : nil
end