新增:打包编译功能

This commit is contained in:
李强
2024-06-18 12:46:57 +08:00
parent 1f81ac5854
commit 38bb65f9d5
137 changed files with 2481 additions and 6332 deletions

View File

@@ -0,0 +1,38 @@
{% load rest_framework %}
<!-- Modal -->
<div class="modal fade auth-modal auth-basic" id="auth_basic_modal" tabindex="-1" role="dialog" aria-labelledby="basic authentication modal">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title"><i class="fa fa-key"></i> Basic Authentication</h3>
</div>
<form class="form-horizontal authentication-basic-form">
<div class="modal-body">
<div class="form-group">
<label for="authorization" class="col-sm-2 control-label">Username:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" required>
</div>
</div>
<div class="form-group">
<label for="authorization" class="col-sm-2 control-label">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Use Basic Authentication</button>
</div>
</form>
</div>
</div>
</div>

View File

@@ -0,0 +1,35 @@
{% load rest_framework %}
<!-- Modal -->
<div class="modal fade auth-modal auth-session" id="auth_session_modal" tabindex="-1" role="dialog" aria-labelledby="session authentication modal">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title"><i class="fa fa-key"></i> Session Authentication</h3>
</div>
<form class="form-horizontal authentication-session-form">
<div class="modal-body">
{% if user.is_authenticated %}
<h4 class="text-center">You are logged in as {{ user.get_username }}.</h4>
{% else %}
<div class="text-center">
<h4 class="text-center">You need to {% optional_docs_login request %} to enable Session Authentication.</h4>
</div>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{% if user.is_authenticated %}
<button type="submit" class="btn btn-primary">Use Session Authentication</button>
{% endif %}
</div>
</form>
</div>
</div>
</div>

View File

@@ -0,0 +1,36 @@
{% load rest_framework %}
<!-- Modal -->
<div class="modal fade auth-modal auth-token" id="auth_token_modal" tabindex="-1" role="dialog" aria-labelledby="token authentication modal">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title"><i class="fa fa-key"></i> Token Authentication</h3>
</div>
<form class="form-horizontal authentication-token-form">
<div class="modal-body">
<div class="form-group">
<label for="prefix" class="col-sm-2 control-label">Scheme:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="scheme" placeholder="Bearer" aria-describedby="schemeHelpBlock" required>
<span id="schemeHelpBlock" class="help-block">Either a registered authentication scheme such as <code>Bearer</code>, or a custom schema such as <code>Token</code> or <code>JWT</code>.</span>
</div>
</div>
<div class="form-group">
<label for="token" class="col-sm-2 control-label">Token:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="token" placeholder="XXXX-XXXX-XXXX-XXXX" aria-describedby="helpBlock" required>
<span id="tokenHelpBlock" class="help-block">A valid API token.</span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Use Token Authentication</button>
</div>
</form>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
{% load rest_framework %}
<div class="row intro">
<div class="col-md-6 intro-title">
<h1>{{ document.title }}</h1>
{% if document.description %}
<p>{% render_markdown document.description %}</p>
{% endif %}
</div>
<div class="col-md-6 intro-code">
{% for html in lang_intro_htmls %}
{% include html %}
{% endfor %}
</div>
</div>
{% if document|data %}
{% for section_key, section in document|data|items %}
{% if section_key %}
<h2 id="{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a href="#{{ section_key }}"><i class="fa fa-link" aria-hidden="true"></i>
</a></h2>
{% endif %}
{% for link_key, link in section|schema_links|items %}
{% include "rest_framework/docs/link.html" %}
{% endfor %}
{% endfor %}
{% for link_key, link in document.links|items %}
{% include "rest_framework/docs/link.html" %}
{% endfor %}
{% endif %}

View File

@@ -0,0 +1,71 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error Rendering Schema</title>
</head>
<body>
<h1>Error</h1>
<pre>
{{ data }}
</pre>
{% if debug is True %}
<hr />
<h2>Additional Information</h2>
<p>Note: You are seeing this message because <code>DEBUG==True</code>.</p>
<p>Seeing this page is <em>usually</em> a configuration error: are your
<code>DEFAULT_AUTHENTICATION_CLASSES</code> or <code>DEFAULT_PERMISSION_CLASSES</code>
being applied unexpectedly?</p>
<p>Your response status code is: <code>{{ response.status_code }}</code></p>
<h3>401 Unauthorised.</h3>
<ul>
<li>Do you have SessionAuthentication enabled?</li>
<li>Are you logged in?</li>
</ul>
<h3>403 Forbidden.</h3>
<ul>
<li>Do you have sufficient permissions to access this view?</li>
<li>Is you schema non-empty? (An empty schema will lead to a permission denied error being raised.)</li>
</ul>
<p>Most commonly the intended solution is to disable authentication and permissions
when including the docs urls:</p>
<pre>
path('docs/', include_docs_urls(title='Your API',
authentication_classes=[],
permission_classes=[])),
</pre>
<h2>Overriding this template</h2>
<p>If you wish access to your docs to be authenticated you may override this template
at <code>rest_framework/docs/error.html</code>.</p>
<p>The available context is: <code>data</code> the error dict above, <code>request</code>,
<code>response</code> and the <code>debug</code> flag.</p>
{% endif %}
<script src="{% static 'rest_framework/js/jquery-3.5.1.min.js' %}"></script>
</body>
</html>

View File

@@ -0,0 +1,57 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ document.title }}</title>
<link href="{% static 'rest_framework/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'rest_framework/css/bootstrap-theme.min.css' %}" rel="stylesheet">
<link href="{% static 'rest_framework/css/font-awesome-4.0.3.css' %}" rel="stylesheet">
<link href="{% static 'rest_framework/docs/css/base.css' %}" rel="stylesheet">
<link href="{% static 'rest_framework/docs/css/jquery.json-view.min.css' %}" rel="stylesheet">
<link href="{% static 'rest_framework/docs/img/favicon.ico' %}" rel="shortcut icon">
{% if code_style %}<style>{{ code_style }}</style>{% endif %}
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
<script src="{% url 'api-docs:schema-js' %}"></script>
</head>
<body data-spy="scroll" data-target="#sidebar-nav" data-offset="50">
{% include "rest_framework/docs/sidebar.html" %}
<div class="container" id="main">
<div class="row">
<div class="col-md-12 main-container">
{% include "rest_framework/docs/document.html" %}
</div>
</div>
</div>
{% include "rest_framework/docs/auth/token.html" %}
{% include "rest_framework/docs/auth/basic.html" %}
{% include "rest_framework/docs/auth/session.html" %}
<script src="{% static 'rest_framework/js/jquery-3.5.1.min.js' %}"></script>
<script src="{% static 'rest_framework/js/bootstrap.min.js' %}"></script>
<script src="{% static 'rest_framework/docs/js/jquery.json-view.min.js' %}"></script>
<script src="{% static 'rest_framework/docs/js/api.js' %}"></script>
<script>
{% if user.is_authenticated %}
window.auth = {
'type': 'session',
};
$('#selected-authentication').text('session');
$('#auth-control').children().removeClass('active');
$('#auth-control').find("[data-auth='session']").closest('li').addClass('active');
{% endif %}
$('pre.highlight').filter('[data-language="{{ langs | first }}"]').removeClass('hide');
</script>
</body>
</html>

View File

@@ -0,0 +1,51 @@
{% load rest_framework %}
<!-- Modal -->
<div class="modal fade api-modal" id="{{ section_key }}_{{ link_key|slugify }}_modal" tabindex="-1" role="dialog" aria-labelledby="api explorer modal">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="toggle-view hide">
<div class="btn-group" role="group">
<button type="button" data-display-toggle="data" class="btn btn-sm btn-info">Data</button>
<button type="button" data-display-toggle="raw" class="btn btn-sm">Raw</button>
</div>
</div>
<h3 class="modal-title"><i class="fa fa-exchange"></i> {{ link.title|default:link_key }}</h3>
</div>
<form data-key='["{{ section_key }}", "{{ link_key }}"]' class="api-interaction">
<div class="modal-body">
<div class="row">
<div class="col-lg-6 request">
{% form_for_link link %}
</div>
<hr class="hidden-lg hidden-xl" />
<div class="col-lg-6 response" id="response">
<div class="request-awaiting">Awaiting request</div>
<div class="meta hide">
<span class="label label-primary request-method"></span>
<code class="request-url"></code>
<label class="label label-lg response-status-code pull-right"></label>
</div>
<pre class="well response-data hide"></pre>
<pre class="well response-raw hide"><div class="response-raw-request"></div><div class="response-raw-response"></div></pre>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Send Request</button>
</div>
</form>
</div>
</div>
</div>

View File

@@ -0,0 +1,5 @@
{% load rest_framework %}
{% load static %}
<pre class="highlight javascript hide" data-language="javascript"><code>{% code html %}<!-- Load the JavaScript client library -->
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
<script src="{% url 'api-docs:schema-js' %}"></script>{% endcode %}</code></pre>

View File

@@ -0,0 +1,15 @@
{% load rest_framework %}
<pre class="highlight javascript hide" data-language="javascript"><code>{% code javascript %}var coreapi = window.coreapi // Loaded by `coreapi.js`
var schema = window.schema // Loaded by `schema.js`
// Initialize a client
var client = new coreapi.Client()
// Interact with the API endpoint
var action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
{% if link.fields %}var params = {
{% for field in link.fields %} {{ field.name }}: ...{% if not loop.last %},{% endif %}
{% endfor %}}
{% endif %}client.action(schema, action{% if link.fields %}, params{% endif %}).then(function(result) {
// Return value is in 'result'
}){% endcode %}</code></pre>

View File

@@ -0,0 +1,3 @@
{% load rest_framework %}
<pre class="highlight python hide" data-language="python"><code>{% code bash %}# Install the Python client library
$ pip install coreapi{% endcode %}</code></pre>

View File

@@ -0,0 +1,13 @@
{% load rest_framework %}
<pre class="highlight python hide" data-language="python"><code>{% code python %}import coreapi
# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("{{ document.url }}"{% if schema_format %}, format="{{ schema_format }}"{% endif %})
# Interact with the API endpoint
action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
{% if link.fields %}params = {
{% for field in link.fields %} "{{ field.name }}": ...{% if not loop.last %},{% endif %}
{% endfor %}}
{% endif %}result = client.action(schema, action{% if link.fields %}, params=params{% endif %}){% endcode %}</code></pre>

View File

@@ -0,0 +1,3 @@
{% load rest_framework %}
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Install the command line client
$ pip install coreapi-cli{% endcode %}</code></pre>

View File

@@ -0,0 +1,6 @@
{% load rest_framework %}
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Load the schema document
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
# Interact with the API endpoint
$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key|cut:"> " }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>

View File

@@ -0,0 +1,102 @@
{% load rest_framework %}
<div class="row coredocs-link">
<div class="col-md-6 docs-content">
<button
class="btn btn-sm btn-success"
style="float: right; margin-top: 20px"
data-toggle="modal"
data-target="#{{ section_key }}_{{ link_key|slugify }}_modal">
<i class="fa fa-exchange"></i> Interact
</button>
<h3 id="{{ section_key }}-{{ link_key|slugify }}" class="coredocs-link-title">{{ link.title|default:link_key }} <a href="#{{ section_key }}-{{ link_key|slugify }}"><i class="fa fa-link" aria-hidden="true"></i>
</a></h3>
<div class="meta">
<span class="label label-primary">{{ link.action|upper }}</span>
<code>{{ link.url }}</code>
</div>
<p>{% render_markdown link.description %}</p>
{% if link.fields|with_location:'path' %}
<h4>Path Parameters</h4>
<p>The following parameters should be included in the URL path.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'path' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description|safe }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if link.fields|with_location:'query' %}
<h4>Query Parameters</h4>
<p>The following parameters should be included as part of a URL query string.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'query' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description|safe }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if link.fields|with_location:'header' %}
<h4>Header Parameters</h4>
<p>The following parameters should be included as HTTP headers.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'header' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description|safe }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if link.fields|with_location:'body' %}
<h4>Request Body</h4>
<p>The request body should be <code>"{{ link.encoding }}"</code> encoded, and should contain a single item.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'body' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description|safe }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% elif link.fields|with_location:'form' %}
<h4>Request Body</h4>
<p>The request body should be a <code>"{{ link.encoding }}"</code> encoded object, containing the following&nbsp;items.</p>
<table class="parameters table table-bordered table-striped">
<thead>
<tr><th>Parameter</th><th>Description</th></tr>
</thead>
<tbody>
{% for field in link.fields|with_location:'form' %}
<tr><td class="parameter-name"><code>{{ field.name }}</code>{% if field.required %} <span class="label label-warning">required</span>{% endif %}</td><td>{% if field.schema.description %}{{ field.schema.description|safe }}{% endif %}</td></tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
<div class="col-md-6 code-samples">
{% for html in lang_htmls %}
{% include html %}
{% endfor %}
</div>
</div>
{% include "rest_framework/docs/interact.html" with link=link %}

View File

@@ -0,0 +1,44 @@
{% load rest_framework %}
<div class="sidebar">
<h3 class="brand"><a href="#">{{ document.title }}</a></h3>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
{% if document|data %}
{% for section_key, section in document|data|items %}
<li data-toggle="collapse" data-target="#{{ section_key }}-dropdown" class="collapsed">
<a><i class="fa fa-dot-circle-o fa-lg"></i> {% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} <span class="arrow"></span></a>
<ul class="sub-menu {% if section_key %}collapse{% endif %}" id="{{ section_key }}-dropdown">
{% for link_key, link in section|schema_links|items %}
<li><a href="#{{ section_key }}-{{ link_key|slugify }}">{{ link.title|default:link_key }}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
{% endif %}
</ul>
<ul class="menu-list menu-list-bottom">
<li data-toggle="collapse" data-target="#auth-control" class="collapsed">
<a><i class="fa fa-user fa-lg"></i> Authentication</a> <span id="selected-authentication">{% if user.is_authenticated %}session{% else %}none{% endif %}</span>
</li>
<ul class="sub-menu collapse out" id="auth-control">
<li {% if not user.is_authenticated %}class="active"{% endif %}><a data-auth="none" href="#">none</a></li>
<li><a data-auth="token" data-toggle="modal" data-target="#auth_token_modal" href="#">token</a></li>
<li><a data-auth="basic" data-toggle="modal" data-target="#auth_basic_modal" href="#">basic</a></li>
<li {% if user.is_authenticated %}class="active"{% endif %}><a data-auth="session" data-toggle="modal" data-target="#auth_session_modal" href="#">session</a></li>
</ul>
<li data-toggle="collapse" data-target="#language-control" class="collapsed">
<a><i class="fa fa-code fa-lg"></i> Source Code</a> <span id="selected-language">{{ langs | first }}</span>
</li>
<ul class="sub-menu collapse out" id="language-control">
{% for lang in langs %}
<li{% if loop.first %} class="active"{% endif %}><a href="#" data-language="{{ lang }}">{{ lang }}</a></li>
{% endfor %}
</ul>
</ul>
</div>
</div>