Method: TTL2HTML::App#build_breadcrumbs

Defined in:
lib/ttl2html.rb

#build_breadcrumbs(uri, template, depth = 0) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/ttl2html.rb', line 254

def build_breadcrumbs(uri, template, depth = 0)
  results = []
  data = @data[uri]
  if @config[:breadcrumbs]
    if depth == 0
      first_label = template.get_title(data)
      first_label = data[@config[:breadcrumbs].first["label"]].first if @config[:breadcrumbs].first["label"] and data[@config[:breadcrumbs].first["label"]]
      results << { label: first_label }
    end
    @config[:breadcrumbs].each do |e|
      data_target = data
      data_target = @data_inverse[uri] if e["inverse"]
      if data_target
        if e["property"].kind_of? Array
          parent = nil
          data_target_sub = data_target
          e["property"].each do |prop|
            if data_target_sub[prop["property"]]
              data_target_sub[prop["property"]].each do |o|
                parent = o
                data_target_sub = @data[parent]
              end
            end
          end
          if parent
            results << build_breadcrumbs_sub(parent, template)
            results += build_breadcrumbs(parent, template, depth + 1)
            return results
          end
        elsif data_target[e["property"]]
          data_target[e["property"]].each do |parent|
            results << build_breadcrumbs_sub(parent, template, e["label"])
            results += build_breadcrumbs(parent, template, depth + 1)
            return results
          end
        end
      end
    end
  end
  results
end