Method: Noumenon::ContentRepository::FileSystem#children
- Defined in:
- lib/noumenon/content_repository/file_system.rb
#children(root = "/", depth = 1, include_root = true) ⇒ Object
Return any content items below the path specified.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/noumenon/content_repository/file_system.rb', line 63 def children(root = "/", depth = 1, include_root = true) root.gsub! /\/$/, '' pattern = File.join(repository_path(root), "*") items = Dir.glob(pattern).collect { |i| i.gsub(repository_path("/"), "/"). gsub(".yml", "") }.reject { |i| i.gsub(root, "").split("/").size > depth + 1 } items.delete(File.join(root, "index")) unless include_root items.collect { |item| path = item == "" ? "/" : item.gsub("index", "") # Loading every item probably isn't scalable, but it'll do for now. We can add caching # at a later date if needed. page = get(path).merge({ path: path }) page[:children] = children(page[:path], depth - 1, false) if depth - 1 > 0 page }.sort { |a, b| a[:path] <=> b[:path] } end |