Sha256: 8989d17d1a0f2b853610f34263e2f6076866839993751373a24b19737c81a062
Contents?: true
Size: 1.16 KB
Versions: 6
Compression:
Stored size: 1.16 KB
Contents
module CamaleonCms module Admin module CategoryHelper # build an array multiple with category items prefixed with - for each level # categories: collection of categories # level: internal iterator control # attrs: (Hash) extra params # max_level: (Integer) permit to stop iteration in certain level # until_cats: (Array of cat ids) permit to stop iteration if current iteration is in this array # exclude_cats: (Array of cat ids) exclude this categories from the list def cama_category_get_options_html(categories, level = 0, attrs = {}) attrs = { max_level: 1000, until_cats: [], exclude_cats: [] }.merge(attrs) options = [] categories.all.decorate.each do |category| next if attrs[:exclude_cats].include?(category.id) options << [('—' * level) + category.the_title, category.id] children = attrs[:max_level] < level ? [] : category.children children = [] if attrs[:until_cats].include?(category.id) options += cama_category_get_options_html(children, level + 1, attrs) if children.size.positive? end options end end end end
Version data entries
6 entries across 6 versions & 1 rubygems