Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-10-27 06:36:03 +0300
committerConnor Shea <connor.james.shea@gmail.com>2016-10-27 06:36:03 +0300
commitbf1c63a1b46e1cacb0c27e4946da40917bf82926 (patch)
treedda139c784d69f9c24febb72ee485eae74456431 /lib
parente93ad43ae403058496d2fbaaffa6134e03df3bbb (diff)
Crazy recursive function.
Diffstat (limited to 'lib')
-rw-r--r--lib/helpers/child_parent_better.rb34
1 files changed, 15 insertions, 19 deletions
diff --git a/lib/helpers/child_parent_better.rb b/lib/helpers/child_parent_better.rb
index 8d9b57d9..8f8945cd 100644
--- a/lib/helpers/child_parent_better.rb
+++ b/lib/helpers/child_parent_better.rb
@@ -1,29 +1,25 @@
module Nanoc::Helpers
module ChildParentBetter
def parent_path(item)
- if item.identifier.to_s.end_with?('README.md')
- path_without_last_component = item.identifier.to_s.sub(/[^\/]+$/, '').chop
- path_without_last_component = path_without_last_component.to_s.sub(/[^\/]+$/, '').chop
- parent = @items[path_without_last_component + '/README.*']
- else
- path_without_last_component = item.identifier.to_s.sub(/[^\/]+$/, '').chop
- parent = @items[path_without_last_component + '/README.*']
- end
-
- if parent.nil?
- path_without_last_component = path_without_last_component.sub(/[^\/]+$/, '').chop
- parent = @items[path_without_last_component + '/README.*']
- end
- # puts "#{item.identifier.to_s}, #{parent.identifier.to_s if parent}"
+ parent = get_nearest_parent(item.identifier.to_s)
parent
end
- def children_of(item)
- if item.identifier.legacy?
- item.children
+ # Recursion!
+ def get_nearest_parent(item_identifier)
+ if (item_identifier.nil? || (item_identifier.to_s.end_with?('README.md') && item_identifier.to_s.split('/').length == 3))
+ return
+ elsif item_identifier.to_s.end_with?('README.md')
+ parent_dir = item_identifier.sub(/[^\/]+$/, '').chop
+ get_nearest_parent(parent_dir)
else
- pattern = item.identifier.without_ext + '/*'
- @items.find_all(pattern)
+ parent_dir = item_identifier.sub(/[^\/]+$/, '').chop
+ parent = @items[parent_dir + '/README.*']
+ if parent.nil?
+ get_nearest_parent(parent_dir)
+ else
+ return parent
+ end
end
end
end