From 446f943968ca026fcdfa0a8b8b593a6ec99e146a Mon Sep 17 00:00:00 2001 From: Holger Just Date: Mon, 26 Dec 2011 13:15:03 +0100 Subject: [PATCH] [#790] Add filter to output an array into an unordered list --- lib/chili_project/liquid/filters.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/chili_project/liquid/filters.rb b/lib/chili_project/liquid/filters.rb index 13df2d1c..c598a890 100644 --- a/lib/chili_project/liquid/filters.rb +++ b/lib/chili_project/liquid/filters.rb @@ -54,6 +54,23 @@ module ChiliProject def strip(input) input.to_s.strip end + + 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 end Template.register_filter(OverriddenFilters)