lib/bunch/combiner.rb in bunch-1.0.0pre1 vs lib/bunch/combiner.rb in bunch-1.0.0pre2
- old
+ new
@@ -16,14 +16,14 @@
def enter_tree(tree)
if tree.name
@path << tree.name
- combine_file = tree.get("_combine")
+ combine_file = tree.get("_combine") || tree.get("_.yml")
if combine_file || combining?
- ordering = combine_file ? combine_file.content : ""
+ ordering = combine_file ? extract_ordering(combine_file.content) : ""
push_context Context.new(@path, ordering)
end
end
end
@@ -44,11 +44,11 @@
end
end
end
def visit_file(file)
- return if file.path == "_combine"
+ return if file.path == "_combine" || file.path == "_.yml"
if combining?
context.add file.path, file.content, file.extension
else
write_file file.path, file.content
@@ -80,16 +80,26 @@
def combining?
@contexts.any?
end
+ def extract_ordering(file_content)
+ as_yaml = YAML.load(file_content)
+
+ if as_yaml.is_a?(Array)
+ as_yaml
+ else
+ file_content.split("\n").map(&:strip)
+ end
+ end
+
class Context
attr_accessor :ordering, :extension
- def initialize(path, ordering_file_contents)
+ def initialize(path, ordering)
@path = path.join("/")
@content = {}
- @ordering = ordering_file_contents.split("\n")
+ @ordering = ordering
@extension = nil
@empty = true
end
def add(path, content, extension)