Skip to content

Commit

Permalink
Top level object style.
Browse files Browse the repository at this point in the history
  • Loading branch information
daizutabi committed Jun 19, 2020
1 parent 977a912 commit 24bf1cf
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Changed
- Top level object style.
- Hide `function` prefix by `display: none;` in CSS.


## [1.0.6] - 2020-06-19
### Changed
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/google_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ MkApi generates the documentation for the `add()` function.

In this simple example, you can see some features of MkApi.

* Type inspection of `add()` (*function* prefix is added before `google_style.add`).
* Use of type annotation for both Parameters and Returns sections.
* Add *optional* if parameters have default values.
* Add "optional" if parameters have default values.
* Default value replacement by the `{default}` keyword in the Parameters section.
* External hyperlink.
* Use of MkDocs extensions: MathJax rendering and admonition.
Expand All @@ -79,9 +78,9 @@ creates the documentation for the `gen()` generator.

In this simple example, note that:

* A *generator* prefix instead of a *function* prefix.
* Type inspection of `gen()` (*generator* prefix is added before `google_style.gen`).
* The parameter `n` has no type annotation but you can specify it in the Parameters section directly.
* Yields type is not *iterator of str* but *str*, because the `gen()` is a generator.
* Yields type is not "iterator of str" but "str", because the `gen()` is a generator.

## Class

Expand Down Expand Up @@ -141,7 +140,7 @@ creates the documentation for the `ExampleDataClass` class.

In this example, note that:

* A DATACLASS prefix instead of a CLASS prefix.
* A *dataclass* prefix instead of a *class* prefix.
* Attributes type inspection as well as parameters if they are data class fields.


Expand Down
7 changes: 3 additions & 4 deletions docs/examples/numpy_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ MkApi generates the API documentation for the `add()` function.

In this simple example, you can see some features of MkApi.

* Type inspection of `add()` (*function* prefix is added before `numpy_style.add`).
* Use of type annotation for both Parameters and Returns sections.
* Add *optional* if parameters have default values.
* Default value replacement by the `{default}` keyword in the Parameters section.
Expand All @@ -80,9 +79,9 @@ creates the documentation for the `gen()` generator.

In this simple example, note that:

* A *generator* prefix instead of a *function* prefix.
* Type inspection of `gen()` (*generator* prefix is added before `google_style.gen`).
* The parameter `n` has no type annotation but you can specify it in the Parameters section directly.
* Yields type is not *iterator of str* but *str*, because the `gen()` is a generator.
* Yields type is not "iterator of str" but "str", because the `gen()` is a generator.

## Class

Expand Down Expand Up @@ -142,7 +141,7 @@ creates the documentation for the `ExampleDataClass` class.

In this example, note that:

* A DATACLASS prefix instead of a CLASS prefix.
* A *dataclass* prefix instead of a *class* prefix.
* Attributes type inspection as well as parameters if they are data class fields.

!!! note
Expand Down
7 changes: 4 additions & 3 deletions mkapi/templates/object.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

{% set upper = 'upper' in filters -%}
{% set body_tag = 'span' if 'plain' in filters else 'code' -%}
{% set top = ' top' if '.' not in object.qualname else '' -%}
<div class='mkapi-object-container'>
<div class="mkapi-object {{ object.kind }} {% if body_tag == 'span' %}plain{% else %}code{% endif %}">
<div class="mkapi-object-kind {{ object.kind }}">{% if upper and object.kind in ['package', 'module'] %}{{ object.kind|upper }}{% else %}{{ object.kind }}{% endif %}</div>
<{{tag}}{% if heading_id %} id="{{ heading_id }}"{% endif %} class="mkapi-object-body {{ object.kind }}">{{ object_body(object, prefix_url, name_url, body_tag, upper) }}</{{tag}}>
<div class="mkapi-object {{ object.kind }} {% if body_tag == 'span' %}plain{% else %}code{% endif %}{{ top }}">
<div class="mkapi-object-kind {{ object.kind }}{{ top }}">{% if upper and object.kind in ['package', 'module'] %}{{ object.kind|upper }}{% else %}{{ object.kind }}{% endif %}</div>
<{{tag}}{% if heading_id %} id="{{ heading_id }}"{% endif %} class="mkapi-object-body {{ object.kind }}{{ top }}">{{ object_body(object, prefix_url, name_url, body_tag, upper) }}</{{tag}}>
</div>
{% if 'sourcelink' in filters or 'link' in filters or 'apilink' in filters -%}
<div class="mkapi-src-link">
Expand Down
14 changes: 5 additions & 9 deletions mkapi/theme/css/mkapi-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ div.mkapi-object.code {
color: #111;
}

div.mkapi-object.class.code, div.mkapi-object.dataclass.code {
div.mkapi-object.top.code {
border: none;
line-height: normal;
background: #e7f2fa;
color: #2980B9;
border-top: solid 3px #6ab0de;
padding: 6px 12px 6px 6px;
}
Expand All @@ -80,11 +79,10 @@ div.mkapi-object.class.code, div.mkapi-object.dataclass.code {
font-style: normal;
}


.mkapi-object-kind.method {
.mkapi-object-kind.function, .mkapi-object-kind.method {
display: none;
}
.mkapi-object-kind.class, .mkapi-object-kind.dataclass {
.mkapi-object-kind.top {
color: #2980B9;
font-size: 90%;
}
Expand Down Expand Up @@ -142,10 +140,8 @@ code.mkapi-object-name {
font-style: italic;
}

.mkapi-node .mkapi-object-body.class code.mkapi-object-parenthesis,
.mkapi-node .mkapi-object-body.class code.mkapi-object-signature,
.mkapi-node .mkapi-object-body.dataclass code.mkapi-object-parenthesis,
.mkapi-node .mkapi-object-body.dataclass code.mkapi-object-signature {
.mkapi-node .mkapi-object-body.top code.mkapi-object-parenthesis,
.mkapi-node .mkapi-object-body.top code.mkapi-object-signature {
font-weight: 700;
color: #2980B9;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/core/test_core_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ def test_set_html_and_render():
html = node.get_html()

assert html.startswith('<div class="mkapi-node" id="mkapi.core.base.Base">')
assert 'mkapi-object-kind dataclass">dataclass</div>' in html
assert 'mkapi-object-kind dataclass top">dataclass</div>' in html
assert '<div class="mkapi-object-body dataclass top">' in html
assert '<code class="mkapi-object-prefix">mkapi.core.base.</code>' in html
assert '<code class="mkapi-object-name">Base</code>' in html
assert '<code class="mkapi-object-parenthesis">(</code>' in html
assert '<code class="mkapi-object-signature">name=&#39;&#39;</code>, ' in html
assert '<code class="mkapi-object-signature">markdown=&#39;&#39;</code>' in html
assert '<div class="mkapi-section-body">1</div>' in html
assert '<span class="mkapi-item-description">2</span></li>' in html
assert '<code class="mkapi-object-name">set_html</code>' in html
Expand Down Expand Up @@ -148,6 +154,8 @@ def test_decorated_member():


def test_colon_in_docstring():
"""Issue#17"""

class A:
def func(self):
"""this: is not type."""
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_core_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_page():
assert '<a href="../api/mkapi.core.base.md#mkapi.core.base">BASE</a>' in h
assert '<a href="#mkapi.core.base.Base">Base</a>' in h
assert '<div class="mkapi-node" id="mkapi.core.base.Base">' in h
assert '<div class="mkapi-object dataclass code">' in h
assert '<div class="mkapi-object dataclass code top">' in h
assert '<a href="../api/mkapi.core.base.md#mkapi.core.base">mkapi.core.base' in h
assert '<a href="../api/mkapi.core.base.md#mkapi.core.base.Base">Base</a>' in h
assert '<span class="mkapi-section-name-body attributes">Attributes</span>' in h
Expand Down

0 comments on commit 24bf1cf

Please sign in to comment.