Method: Docman::DocrootConfig#structure_build

Defined in:
lib/docman/docroot_config.rb

#structure_build(path, prefix = '', parent = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/docman/docroot_config.rb', line 107

def structure_build(path, prefix = '', parent = nil)
  return unless File.file? File.join(path, 'info.yaml')

  children = []
  info = YAML::load_file(File.join(path, 'info.yaml'))
  @raw_infos[File.basename path] = YAML::load_file(File.join(path, 'info.yaml'))
  unless info['status'].nil?
    return if info['status'] == 'disabled'
  end
  name = File.basename path
  prefix = prefix.size > 0 ? File.join(prefix, name) : name
  info['full_path'] = path
  info['docroot_config'] = self
  info['build_path'] = prefix
  info['full_build_path'] = File.join(@docroot_dir, prefix)
  info['temp_path'] = File.join(@docroot_dir, '.docman/tmp', info['build_path'])
  info['states_path'] = File.join(@docroot_dir, '.docman/states', info['build_path'])
  info['name'] = name
  info['parent'] = parent
  info['order'] = info.has_key?('order') ? info['order'] : 10
  info['children'] = children

  if @override['projects'] && @override['projects'].key?(info['name'])
    info.merge! @override['projects'][info['name']]
  end

  i = Docman::Info.new(info)
  @root = i if parent.nil?
  i['root'] = @root

  @names[name.to_s] = i

  Dir.foreach(path) do |entry|
    next if (entry == '..' || entry == '.')
    full_path = File.join(path, entry)
    if File.directory?(full_path)
      dir_hash = structure_build(full_path, prefix, i)
      unless dir_hash == nil
        children << dir_hash
      end
    end
  end
  i
end