|
| 1 | +module Docs |
| 2 | + class Hammerspoon |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + def get_name |
| 5 | + at_css("h1").content |
| 6 | + end |
| 7 | + |
| 8 | + def get_type |
| 9 | + slug.split("/").first |
| 10 | + end |
| 11 | + |
| 12 | + def additional_entries |
| 13 | + return [] if root_page? |
| 14 | + entries = [] |
| 15 | + |
| 16 | + # add a base entry |
| 17 | + entries << [name, nil, name] |
| 18 | + |
| 19 | + css("section").each do |section| |
| 20 | + title_node = section.at_css("h5") |
| 21 | + if title_node.nil? |
| 22 | + next |
| 23 | + end |
| 24 | + entry_name = title_node.content.strip |
| 25 | + entry_id = section["id"] |
| 26 | + |
| 27 | + fn_type = section.at_css("a.dashAnchor").get_attribute("name") |
| 28 | + # this dashAnchor is the most consistent way to get the type of the entry |
| 29 | + if fn_type.start_with?("//apple_ref/cpp/Function") |
| 30 | + fn_type = "Function" |
| 31 | + entry_name << "()" |
| 32 | + elsif fn_type.start_with?("//apple_ref/cpp/Constructor/") |
| 33 | + fn_type = "Constructor" |
| 34 | + entry_name << "()" |
| 35 | + elsif fn_type.start_with?("//apple_ref/cpp/Method") |
| 36 | + fn_type = "Method" |
| 37 | + entry_name << "()" |
| 38 | + elsif fn_type.start_with?("//apple_ref/cpp/Class") |
| 39 | + fn_type = "Class" |
| 40 | + elsif fn_type.start_with?("//apple_ref/cpp/Constant") |
| 41 | + fn_type = "Constant" |
| 42 | + elsif fn_type.start_with?("//apple_ref/cpp/Variable") |
| 43 | + fn_type = "Variable" |
| 44 | + elsif fn_type.start_with?("//apple_ref/cpp/Deprecated") |
| 45 | + fn_type = "Deprecated" |
| 46 | + elsif fn_type.start_with?("//apple_ref/cpp/Field") |
| 47 | + fn_type = "Field" |
| 48 | + else |
| 49 | + fn_type = "Unknown" |
| 50 | + end |
| 51 | + |
| 52 | + # Create a new entry for each method/function |
| 53 | + if fn_type != "Unknown" |
| 54 | + entries << ["#{name}.#{entry_name}", entry_id, name] |
| 55 | + end |
| 56 | + |
| 57 | + end |
| 58 | + |
| 59 | + entries |
| 60 | + end |
| 61 | + |
| 62 | + def include_default_entry? |
| 63 | + # Decide when to include the default entry |
| 64 | + # Here we include it unless the page is a module overview or similar |
| 65 | + !subpath.end_with?("index.lp") |
| 66 | + end |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments