Skip to content

Commit

Permalink
feat: allow to search for functions on the search box (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Dec 11, 2021
1 parent de6defd commit 61abad3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Indexer
private const TYPE_CLASS = 1;
private const TYPE_METHOD = 2;
private const TYPE_NAMESPACE = 3;
private const TYPE_FUNCTION = 4;

public function getIndex(Project $project)
{
Expand All @@ -43,6 +44,11 @@ public function getIndex(Project $project)
}
}

foreach ($project->getProjectFunctions() as $function) {
$index['searchIndex'][] = $this->getSearchString((string) $function);
$index['info'][] = [self::TYPE_FUNCTION, $function];
}

return $index;
}

Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected function renderGlobalTemplates(Project $project, $callback = null)
'namespaces' => $project->getNamespaces(),
'interfaces' => $project->getProjectInterfaces(),
'classes' => $project->getProjectClasses(),
'functions' => $project->getProjectFunctions(),
'items' => $this->getIndex($project),
'index' => $this->indexer->getIndex($project),
'tree' => $this->getTree($project),
Expand Down
5 changes: 3 additions & 2 deletions src/Renderer/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public function setCurrentDepth(int $depth): void
$this->currentDepth = $depth;
}

public function pathForFunction(array $context, string $function): string
public function pathForFunction(array $context, FunctionReflection $function): string
{
return $this->relativeUri($this->currentDepth) . '#function_' . str_replace('\\', '', $function);
$namespace = $this->pathForNamespace($context, $function->getNamespace());
return $this->relativeUri($this->currentDepth) . $namespace . '#function_' . str_replace('\\', '', $function->getName());
}

public function pathForClass(array $context, string $class): string
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/themes/default/doctum.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
-}},
{{ add_class_methods_index(class, prettyJsonOptions) }}
{% endfor %}
{% for function in functions -%}
{{-
{
type: 'Function'|trans,
link: function_path(function),
name: function.__toString(),
doc: function.shortdesc|desc(function)|md_to_html,
}|json_encode(prettyJsonOptions)|raw
-}},
{% endfor %}
{# Override this block, search_index_extra, to add custom search entries! #}
{% block search_index_extra '' %}
// Fix trailing commas in the index
Expand Down

0 comments on commit 61abad3

Please sign in to comment.