lib/nested_array/nested.rb in nested_array-2.0.4 vs lib/nested_array/nested.rb in nested_array-2.2.0
- old
+ new
@@ -36,10 +36,13 @@
option_value: 'id', # Что брать в качестве значений при формировании опций селекта.
option_text: 'name',
}
end
+ #
+ # Перебирает вложенную стуктуру.
+ #
def each_nested options={}
options = NESTED_OPTIONS.merge options
level = 0
cache = []
cache[level] = self.clone
@@ -247,18 +250,19 @@
while level >= 0
node = cache[level][i[level]]
i[level]+= 1
if node != nil
+ node_html, node_options = yield(node.clone, parents.clone, level)
html+= options[:tab] * (level * 2 + 1) if options[:tabulated]
- html+= options[:li]
- html+= yield(node.clone, parents.clone, level)
+ html+= node_options&.[](:li) || options[:li]
+ html+= node_html.to_s
if !node[options[:children]].nil? && node[options[:children]].length > 0
level+= 1
html+= "\n" if !options[:inline]
html+= options[:tab] * (level * 2) if options[:tabulated]
- html+= options[:ul]
+ html+= node_options&.[](:ul) || options[:ul]
html+= "\n" if !options[:inline]
parents[level] = node.clone
cache[level] = node[options[:children]]
i[level] = 0
else