Module: ChiliProject::Liquid::Filters

Defined in:
lib/chili_project/liquid/filters.rb

Instance Method Summary collapse

Instance Method Details

#default(input, default) ⇒ Object


85
86
87
# File 'lib/chili_project/liquid/filters.rb', line 85

def default(input, default)
  input.to_s.strip.present? ? input : default
end

#strip(input) ⇒ Object


89
90
91
# File 'lib/chili_project/liquid/filters.rb', line 89

def strip(input)
  input.to_s.strip
end

#to_list(array, header_or_depth = nil) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/chili_project/liquid/filters.rb', line 93

def to_list(array, header_or_depth = nil)
  result = []
  if header_or_depth.is_a?(String)
    result << "\np. #{header_or_depth}\n"
    depth = 1
  else
    if header_or_depth.respond_to?(:to_i)
      depth = [1, header_or_depth.to_i].max
    else
      depth = 1
    end
  end

  result += (array || []).collect{|elm| "#{"*" * depth.to_i } #{elm.to_s}"}
  result.join("\n")
end