Top Level Namespace

Defined Under Namespace

Modules: Jekyll

Instance Method Summary collapse

Instance Method Details

#directory_hash(path, name = nil, level = 0) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/jekyll-theme-isotc211-helpers/resource_listing.rb', line 114

def directory_hash(path, name=nil, level=0)
  data = {
    "data" => (name || path),
    "full_path" => path,
    "level" => level,
  }
  data["children"] = children = []

  level += 1

  Dir.foreach(path) do |entry|
    next if (entry == '..' || entry == '.')

    full_path = File.join(path, entry)

    if File.directory?(full_path)
      children << directory_hash(full_path, entry, level=level)
    else
      children << { "data" => entry, "full_path" => full_path, "level" => level }
    end
  end

  return data
end