Skip to content

Commit dd51452

Browse files
authored
format rendered tile html (#62)
* version bump * see how grid looks with multiple tiles * strip whitespace * add example error * add info about docker container setup * more info on running tests locally
1 parent c52ba44 commit dd51452

File tree

13 files changed

+111
-73
lines changed

13 files changed

+111
-73
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ See 'Theme Updates' in [Developer Setup](DEVELOPER_README.md#theme-updates)
7474

7575
### Adding Tests
7676

77-
See 'Add Tests' in [Developer Setup](DEVELOPER_README.md#add-tests)
77+
See 'Add Tests' in [Developer Setup](DEVELOPER_README.md#add-functional-tests)
7878

7979
## CI Information
8080

DEVELOPER_README.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ Use this readme to add a feature to this theme or to update the theme documentat
2121
- [Bump Theme Version](#bump-theme-version)
2222
- [Start Documentation Server with Local Theme](#start-documentation-server-with-local-theme)
2323
- [Make Updates](#make-updates)
24-
- [Test Theme Build Locally](#test-theme-build-locally)
25-
- [Add Tests](#add-tests)
24+
- [Test Theme Build/Packaging Locally](#test-theme-buildpackaging-locally)
25+
- [Add Functional Tests](#add-functional-tests)
2626
- [Push Changes and Create PR](#push-changes-and-create-pr-1)
2727
- [Review PR Build](#review-pr-build)
2828

2929

3030
## Developer Setup
31+
Development for this project is done within [Docker containers]. Using Docker containers makes setup easy because all developer workspaces will have the same installed software / OS. If there's a tool that is not available that you think would be helpful to add to the default container image, please feel free to [open an Issue](https://github.com/ntno/mkdocs-terminal/issues/new/choose) and start a discussion.
32+
33+
*Note*: All software besides the two prerequisites will be installed in the Docker container and not your machine.
34+
35+
[Docker containers]: https://www.docker.com/resources/what-container/
3136

3237
### Prerequisites
3338
- install [docker](https://docs.docker.com/get-docker/)
@@ -48,6 +53,14 @@ make serve-docs
4853
You should be able to visit [http://0.0.0.0:8080/mkdocs-terminal/](http://0.0.0.0:8080/mkdocs-terminal/) in your browser and view the mkdocs-terminal documentation site.
4954

5055
If you get a `docker.sock: connect: permission denied` error, you probably need to start the Docker engine on your machine.
56+
57+
**Example Error**:
58+
```
59+
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.project%3Dmkdocs-terminal%22%3Atrue%7D%7D&limit=0": dial unix /var/run/docker.sock: connect: permission denied
60+
make: *** [ubuntu] Error 1
61+
```
62+
63+
**Solution**:
5164
Open the Docker Desktop application and wait until the application indicates that the Docker engine is in a "running" state. Then retry starting your docker container.
5265

5366
<img src="documentation/docs/img/developer-setup/engine-starting.png" width="600" title="Docker Engine Starting" alt="orange starting indicator at bottom left of Docker Desktop">
@@ -118,16 +131,32 @@ Update files in [terminal/](terminal/). You should see changes loaded in [http:
118131
- confirm links are not broken
119132
- confirm existing components/features still work
120133

121-
### Test Theme Build Locally
134+
### Test Theme Build/Packaging Locally
122135
Launch the project's ubuntu container and run tox build tests:
123136

124-
```
137+
```bash
125138
make ubuntu
126139
make tox
127140
```
128141

129-
### Add Tests
130-
Test suite setup is in progress. See [GitHub issue](https://github.com/ntno/mkdocs-terminal/issues/13) for details. If you have experience creating automated tests for Jinja2 please consider making a contribution!
142+
### Add Functional Tests
143+
If you are adding/changing theme functionality, please add a test to the relevant test class in [tests/](tests/). You can run the test suite locally by using the commands described in this section.
144+
145+
After you have installed the required testing software you can rerun `make quick-tests` whenever you want to re-execute.
146+
147+
```bash
148+
make ubuntu
149+
make install-test-prereqs
150+
make install-test-requirements
151+
make quick-tests
152+
```
153+
154+
Remember to work in the project's [Docker container](#developer-setup) to avoid Python dependency conflicts. Once you have run `make ubuntu`, your terminal prompt should include `root@CONTAINER_ID`:
155+
156+
![Docker Container](documentation/docs/img/developer-setup/developer-container.png)
157+
158+
159+
Test suites can always be improved! See [GitHub issue](https://github.com/ntno/mkdocs-terminal/issues/13) for current progress/discussion. If you have experience creating automated tests for Jinja2 please consider making a contribution.
131160

132161
### Push Changes and Create PR
133162
See [Work On Pull Request](https://github.com/susam/gitpr#work-on-pull-request) for help on adding/pushing changes to your feature branch.

NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ Terminal for MkDocs' Tile Grid relies on the *meta*[^mkdocs-page-meta] attribute
3535
- img: https://picsum.photos/id/{id}/200/200
3636
- to read: [Make for devops](https://alexharv074.github.io/2019/12/26/gnu-make-for-devops-engineers.html)
3737
- to read: [testing bash scripts](https://alexharv074.github.io/2017/07/07/unit-testing-a-bash-script-with-shunit2.html)
38-
- [pytidylib](https://pythonhosted.org/pytidylib/)
38+
- [pytidylib](https://pythonhosted.org/pytidylib/)
39+
- [jinja2 web render](https://j2live.ttl255.com/)
99.7 KB
Loading

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mkdocs-terminal",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Terminal.css theme for MkDocs",
55
"keywords": [
66
"mkdocs",

requirements.test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
flake8
12
mkdocs
23
pytest > 7
34
pytidylib >= 0.3.2

terminal/macros/tile-image.j2

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% macro make_image( tile ) -%}
2-
<img src="{{ tile.img_src }}"
3-
{% if tile.img_title is defined and tile.img_title|string|length %}title="{{ tile.img_title }}"{% endif %}
4-
alt="{{ tile.img_alt|default('', true ) }}"
5-
{% if tile.img_width is defined and tile.img_width|string|length %}width="{{ tile.img_width }}"{% endif %}
6-
{% if tile.img_height is defined and tile.img_height|string|length %}height="{{ tile.img_height }}"{% endif %}
7-
>
2+
<img src="{{ tile.img_src }}" alt="{{ tile.img_alt|default('', true ) }}"
3+
{%- if tile.img_title is defined and tile.img_title|string|length %} title="{{ tile.img_title }}"{% endif %}
4+
{%- if tile.img_width is defined and tile.img_width|string|length %} width="{{ tile.img_width }}"{% endif %}
5+
{%- if tile.img_height is defined and tile.img_height|string|length %} height="{{ tile.img_height }}"{% endif %} >
86
{%- endmacro -%}

terminal/macros/tile-link.j2

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{% macro make_link_start( tile ) -%}
22
<a href="{{ tile.link_href }}"
3-
{% if tile.link_title is defined and tile.link_title|string|length %}title="{{ tile.link_title }}"{% endif %}
4-
{% if tile.link_target is defined and tile.link_target|string|length %}target="{{ tile.link_target }}"{% endif %}
5-
>
3+
{%- if tile.link_title is defined and tile.link_title|string|length %} title="{{ tile.link_title }}"{% endif %}
4+
{%- if tile.link_target is defined and tile.link_target|string|length %} target="{{ tile.link_target }}"{% endif %} >
65
{%- endmacro -%}
7-

terminal/macros/tile.j2

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,35 @@
1+
12
{% import 'macros/tile-image.j2' as image_helper %}
23
{% import 'macros/tile-link.j2' as link_helper %}
3-
4-
{% macro make_tile( tile ) -%}
5-
6-
{% set ns = namespace(is_valid=false, has_link=false, has_image=false, has_caption=false) %}
7-
{% if tile.img_src is defined and tile.img_src|string|length %}
4+
{% macro make_tile( tile ) %}
5+
{%- set ns = namespace(is_valid=false, has_link=false, has_image=false, has_caption=false) -%}
6+
{%- if tile.img_src is defined and tile.img_src|string|length -%}
87
{%- set ns.has_image = true -%}
9-
{% endif %}
10-
{% if tile.link_href is defined and tile.link_href|string|length %}
8+
{%- endif -%}
9+
{%- if tile.link_href is defined and tile.link_href|string|length -%}
1110
{%- set ns.has_link = true -%}
12-
{% endif %}
13-
{% if tile.caption is defined and tile.caption|string|length %}
11+
{%- endif -%}
12+
{%- if tile.caption is defined and tile.caption|string|length -%}
1413
{%- set ns.has_caption = true -%}
15-
{% endif %}
16-
{% if ns.has_link or ns.has_image %}
14+
{%- endif -%}
15+
{%- if ns.has_link or ns.has_image -%}
1716
{%- set ns.is_valid = true -%}
18-
{% endif %}
19-
20-
21-
{% if ns.is_valid %}
22-
<div
23-
{% if tile.id is defined and tile.id|string|length %}
24-
id="{{ tile.id }}"
25-
{% endif %}
26-
class="terminal-mkdocs-tile {{ tile.class }}">
27-
<figure>
28-
{% if ns.has_link %}
29-
{{ link_helper.make_link_start(tile) }}
30-
{% endif %}
31-
32-
{% if ns.has_image %}
33-
{{ image_helper.make_image(tile) }}
34-
{% endif %}
35-
36-
{% if ns.has_link %}
37-
{% if ns.has_image %}
38-
</a>
39-
{% else %}
40-
{{ tile.link_text|default(tile.link_href, true) }}</a>
41-
{% endif %}
42-
{% endif %}
43-
44-
{% if ns.has_caption %}
45-
<figcaption>{{ tile.caption|string|trim }}</figcaption>
46-
{% endif %}
47-
</figure>
48-
</div>
49-
{% endif %}
17+
{%- endif -%}
18+
{%- if ns.is_valid -%}
19+
<div {% if tile.id is defined and tile.id|string|length %} id="{{ tile.id }}"{%- endif -%} class="terminal-mkdocs-tile {{ tile.class }}">
20+
<figure>
21+
{% if ns.has_link -%}{{ link_helper.make_link_start(tile) }}{% endif %}
22+
{%- if ns.has_image %}
23+
{{ image_helper.make_image(tile) }}
24+
{%- endif -%}
25+
{%- if ns.has_link -%}
26+
{% if ns.has_image %}
27+
</a>{% else %}{{ tile.link_text|default(tile.link_href, true) }}</a>{%- endif -%}
28+
{%- endif -%}
29+
{%- if ns.has_caption %}
30+
<figcaption>{{ tile.caption|string|trim }}</figcaption>
31+
{%- endif %}
32+
</figure>
33+
</div>
34+
{%- endif -%}
5035
{%- endmacro -%}
51-

0 commit comments

Comments
 (0)