Skip to content

Commit

Permalink
include @wq/analyst in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Apr 2, 2024
1 parent d00992c commit ff0e953
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ jobs:
run: |
curl -L -s https://unpkg.com/wq > docs/js/wq.js
curl -L -s https://unpkg.com/@wq/markdown@latest > docs/js/markdown.js
curl -L -s https://unpkg.com/@wq/analyst@next > docs/js/analyst.js
curl -L -s https://unpkg.com/@wq/chart@next > docs/js/chart.js
sed -i "s/^import\(.*\)https:\/\/unpkg.com\/wq/import\1.\/wq.js/" docs/js/*.js
sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/markdown@next/import\1.\/markdown.js/" docs/js/*.js
sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/analyst/import\1.\/analyst.js/" docs/js/*.js
sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/chart/import\1.\/chart.js/" docs/js/*.js
- name: Export Django site
run: |
python -m pip install django djangorestframework pandas openpyxl
python -m unittest tests.generate_docs
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
build
dist
node_modules
docs/static
docs/timeseries.*
9 changes: 9 additions & 0 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
margin-right: auto;
max-width: 100%;
}
.MuiAppBar-colorPrimary img {
border-radius: 4px;
padding-left: 4px;
padding-right: 4px;
margin-left: -18px !important;
margin-top: 4px;
margin-bottom: 4px;
background-color: rgba(0, 0, 0, 0.6);
}
</style>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LTN8HFGJT2"></script>
<script>
Expand Down
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ wq_config:

[**Django REST Pandas on GitHub**](https://github.com/wq/django-rest-pandas)

### Demo

```js
// @wq/analyst
{
"url": "/timeseries.csv",
"formats": {
"csv": "CSV",
"xlsx": "Excel",
"json": "JSON"
}
}
```

[pandas]: https://pandas.pydata.org/
[Django REST Framework]: https://www.django-rest-framework.org/
[formats]: ./renderers/index.md
Expand Down
7 changes: 6 additions & 1 deletion docs/js/$index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ layout: null
---

import wq, { modules } from 'https://unpkg.com/wq';
import markdown, { renderers } from 'https://unpkg.com/@wq/markdown@next';
import markdown, { components } from 'https://unpkg.com/@wq/markdown@next';
import Demo from './demo.js';

const React = modules['react'];
const { Typography, Link } = modules['@wq/material'];

components.code = Demo;

wq.use(markdown);

const config = {
site_title: 'Django REST Pandas',
logo: '/images/icons/django-rest-pandas.svg',
store: {
service: '',
defaults: {
Expand Down Expand Up @@ -52,6 +56,7 @@ function pageConf(page) {
icon: page.wq_config.icon_data ? page.wq_config.name : null,
markdown: page.content,
list: true,
form: [],
cache: 'all',
can_change: false,
can_add: false,
Expand Down
31 changes: 31 additions & 0 deletions docs/js/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { modules } from "https://unpkg.com/wq";
import { components } from "https://unpkg.com/@wq/markdown";
import { Analyst } from "https://unpkg.com/@wq/analyst";

const React = modules.react;
const Code = components.code;

export default function CodeDetect(props) {
const { children: value } = props;
if (value.includes("// @wq/analyst")) {
const config = parseConfig(value);
if (config) {
return React.createElement(Analyst, { config });
} else {
return React.createElement(Code, {
children: "// Error parsing @wq/analyst config\n\n" + value,
});
}
} else {
return React.createElement(Code, props);
}
}

function parseConfig(value) {
value = value.replace("// @wq/analyst", "").trim();
try {
return JSON.parse(value);
} catch {
return null;
}
}
10 changes: 5 additions & 5 deletions tests/files/multitimeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<html lang="en-us" dir="ltr">
<head>
<title>Multi Time Series</title>
<link rel="stylesheet" href="admin/css/base.css">
<link rel="stylesheet" href="/static/admin/css/base.css">

<link rel="stylesheet" href="admin/css/dark_mode.css">
<script src="admin/js/theme.js" defer></script>
<link rel="stylesheet" href="/static/admin/css/dark_mode.css">
<script src="/static/admin/js/theme.js" defer></script>



<link rel="stylesheet" type="text/css" href="admin/css/forms.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css">




<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="admin/css/responsive.css">
<link rel="stylesheet" href="/static/admin/css/responsive.css">


<meta name="robots" content="NONE,NOARCHIVE">
Expand Down
10 changes: 5 additions & 5 deletions tests/files/timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<html lang="en-us" dir="ltr">
<head>
<title>Time Series Custom</title>
<link rel="stylesheet" href="admin/css/base.css">
<link rel="stylesheet" href="/static/admin/css/base.css">

<link rel="stylesheet" href="admin/css/dark_mode.css">
<script src="admin/js/theme.js" defer></script>
<link rel="stylesheet" href="/static/admin/css/dark_mode.css">
<script src="/static/admin/js/theme.js" defer></script>



<link rel="stylesheet" type="text/css" href="admin/css/forms.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css">




<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="admin/css/responsive.css">
<link rel="stylesheet" href="/static/admin/css/responsive.css">


<meta name="robots" content="NONE,NOARCHIVE">
Expand Down
33 changes: 33 additions & 0 deletions tests/generate_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from rest_framework.test import APITestCase
from tests.testapp.models import TimeSeries, CustomIndexSeries
from django.core.management import call_command
import pathlib


DOCS = pathlib.Path("docs")

class DocsTestCase(APITestCase):
def setUp(self):
data = (
("2014-01-01", 0.5),
("2014-01-02", 0.4),
("2014-01-03", 0.6),
("2014-01-04", 0.2),
("2014-01-05", 0.1),
)
for date, value in data:
TimeSeries.objects.create(date=date, value=value)

def test_docs(self):
call_command('collectstatic', interactive=False)
for url in (
"timeseries.html",
"timeseries.csv",
"timeseries.json",
"timeseries.xlsx",
):
response = self.client.get(f"/{url}")
path = DOCS / url
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(response.content)
3 changes: 3 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.staticfiles",
"tests.testapp",
"rest_pandas",
"rest_framework",
Expand All @@ -16,6 +17,8 @@
}
}
ROOT_URLCONF = "tests.urls"
STATIC_URL = "/static"
STATIC_ROOT = "docs/static"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
Expand Down

0 comments on commit ff0e953

Please sign in to comment.