Skip to content

Commit

Permalink
ENH Display protected methods/properties
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 10, 2023
1 parent 5fb8635 commit e168eff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
47 changes: 43 additions & 4 deletions conf/themes/silverstripe/class.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "default/class.twig" %}
{% from "macros.twig" import render_classes, property_link, hint_link, deprecated, deprecations, internals, todos %}
{% from "macros.twig" import render_classes, property_link, method_link, hint_link, deprecated, deprecations, internals, todos %}

{# This has to be included so that we can add config after constants #}
{% block page_content %}
Expand Down Expand Up @@ -72,7 +72,7 @@

{% endblock %}

{# This has to be included so that we can exclude config from the properties section #}
{# This has to be included so that we can exclude config from the properties section, and to rearrange some display items #}
{% block properties %}
<table class="table table-condensed">
{% for property in properties %}
Expand All @@ -81,10 +81,12 @@
{# END CUSTOMISATION #}
<tr>
<td id="property_{{ property.name|raw }}">
{% if property.isStatic() %}static{% endif %}
{# BEGIN CUSTOMISATION - add public, and reorder so that static is after visibility #}
{% if property.isPublic() %}public{% endif %}
{% if property.isProtected() %}protected{% endif %}
{% if property.isPrivate() %}private{% endif %}
{{ hint_link(property.hint) }}
{% if property.isStatic() %}static{% endif %}
{# END CUSTOMISATION #}
{% if property.isInternal() %}<span class="label label-warning">{% trans 'internal' %}</span>{% endif %}
{% if property.isDeprecated() %}<span class="label label-danger">{% trans 'deprecated' %}</span>{% endif %}
{% if property.isReadOnly() %}<span class="label label-primary">{% trans 'read-only' %}</span>{% endif %}
Expand All @@ -95,6 +97,9 @@
<br>
{% endif %}
</td>
{# BEGIN CUSTOMISATION - move type hint into its own column to match config #}
<td class="type"> {{ hint_link(property.hint) }} </td>
{# END CUSTOMISATION #}
<td>${{ property.name|raw }}</td>
<td class="last">{{ property.shortdesc|desc(class)|md_to_html }}</td>
<td>
Expand All @@ -110,6 +115,40 @@
</table>
{% endblock %}

{# This has to be included to include visibility and rearrange things slightly #}
{% block methods %}
<div class="container-fluid underlined">
{% for method in methods %}
<div class="row">
{# BEGIN CUSTOMISATION - add visibility and move type hint into its own column #}
<div class="col-md-1">
{% if method.isPublic() %}public{% endif %}
{% if method.isProtected() %}protected{% endif %}
{% if method.isPrivate() %}private{% endif %}
{% if method.static %}static&nbsp;{% endif %}
</div>
<div class="col-md-1 type">
{{ hint_link(method.hint) }}
</div>
{# END CUSTOMISATION #}
<div class="col-md-8">
<a href="#method_{{ method.name|raw }}">{{ method.name|raw }}</a>{{ block('method_parameters_signature') }}
{% if not method.shortdesc %}
<p class="no-description">{% trans 'No description' %}</p>
{% else %}
<p>{{ method.shortdesc|desc(class)|md_to_html }}</p>
{%- endif %}
</div>
<div class="col-md-2">
{%- if method.class is not same as(class) -%}
<small>{{ 'from&nbsp;%s'|trans|format(method_link(method, false, true))|raw }}</small>
{%- endif -%}
</div>
</div>
{% endfor %}
</div>
{% endblock %}

{# BEGIN CUSTOMISATION - completely new block #}
{% block configs %}
<table class="table table-condensed">
Expand Down
9 changes: 4 additions & 5 deletions src/Parser/Filter/SilverStripeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace SilverStripe\ApiDocs\Parser\Filter;

use Doctum\Parser\Filter\PublicFilter;
use Doctum\Parser\Filter\DefaultFilter;
use Doctum\Reflection\ClassReflection;
use Doctum\Reflection\MethodReflection;
use Doctum\Reflection\PropertyReflection;

class SilverStripeFilter extends PublicFilter
class SilverStripeFilter extends DefaultFilter
{
public function acceptClass(ClassReflection $class)
{
Expand All @@ -21,8 +21,7 @@ public function acceptMethod(MethodReflection $method)

public function acceptProperty(PropertyReflection $property)
{
// if there's a config tag, then we want to document it
return !$property->getTags('internal') &&
($property->getTags('config') || parent::acceptProperty($property));
// Explicitly allow private static properties
return !$property->getTags('internal') && ($property->isStatic() || parent::acceptProperty($property));
}
}

0 comments on commit e168eff

Please sign in to comment.