- if self[:order] == :numeric
- sorted = content_fragments.sort do |a, b|
- def decompound(d)
- d.split('___', 2).map { |v| v =~ /^\d+$/ ? v.to_i : v }
+ sorted = if self[:order] == :numeric
+ content_fragments.sort do |a, b|
+ decompound(a[0]) <=> decompound(b[0])
+ end
+ else
+ content_fragments.sort_by do |a|
+ a_order, a_name = a[0].split('__', 2)
+ [a_order, a_name]
+ end
+ end
+
+ case self[:format]
+ when :plain
+ @generated_content = sorted.map { |cf| cf[1] }.join
+ when :yaml
+ content_array = sorted.map do |cf|
+ YAML.safe_load(cf[1])
+ end
+ content_hash = content_array.reduce({}) do |memo, current|
+ nested_merge(memo, current)
+ end
+ @generated_content = content_hash.to_yaml
+ when :json, :'json-array', :'json-pretty', :'json-array-pretty'
+ content_array = sorted.map do |cf|
+ JSON.parse(cf[1])
+ end
+
+ if [:json, :'json-pretty'].include?(self[:format])
+ content_hash = content_array.reduce({}) do |memo, current|
+ nested_merge(memo, current)